You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.6KB

  1. describe CryptCheck::Statused do
  2. def match_status(actual, **expected)
  3. expected = ::CryptCheck::Status.empty.merge expected
  4. expect(actual.status).to eq expected
  5. end
  6. describe '::status' do
  7. it 'must return empty if no check nor child' do
  8. statused = Class.new do
  9. include ::CryptCheck::Statused
  10. end.new
  11. match_status statused
  12. end
  13. it 'must return personal status if no child' do
  14. statused = Class.new do
  15. include ::CryptCheck::Statused
  16. def checks
  17. [
  18. [:foo, -> (_) { true }, :critical],
  19. [:bar, -> (_) { :error }],
  20. [:baz, -> (_) { false }]
  21. ]
  22. end
  23. end.new
  24. match_status statused, critical: %i(foo), error: %i(bar)
  25. end
  26. it 'must return personal and children statuses' do
  27. child = Class.new do
  28. include ::CryptCheck::Statused
  29. def checks
  30. [[:bar, -> (_) { :error }]]
  31. end
  32. end.new
  33. parent = Class.new do
  34. include ::CryptCheck::Statused
  35. def initialize(child)
  36. @child = child
  37. end
  38. def checks
  39. [[:foo, -> (_) { :critical }]]
  40. end
  41. def children
  42. [@child]
  43. end
  44. end.new(child)
  45. match_status parent, critical: %i(foo), error: %i(bar)
  46. end
  47. it 'must return remove duplicated status' do
  48. child = Class.new do
  49. include ::CryptCheck::Statused
  50. def checks
  51. [[:foo, -> (_) { :critical }]]
  52. end
  53. end.new
  54. parent = Class.new do
  55. include ::CryptCheck::Statused
  56. def initialize(child)
  57. @child = child
  58. end
  59. def checks
  60. [[:foo, -> (_) { :critical }]]
  61. end
  62. def children
  63. [@child]
  64. end
  65. end.new(child)
  66. match_status parent, critical: %i(foo)
  67. end
  68. end
  69. end