Class: RSpec::JsonExpectations::Matchers::UnorderedArrayMatcher
- Inherits:
-
Object
- Object
- RSpec::JsonExpectations::Matchers::UnorderedArrayMatcher
- Extended by:
- Forwardable
- Defined in:
- lib/rspec/json_expectations/matchers.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
readonly
Returns the value of attribute array.
Instance Method Summary collapse
- #all?(&blk) ⇒ Boolean
- #check_for_missing(missing, item, index, ok) ⇒ Object
-
#initialize(array) ⇒ UnorderedArrayMatcher
constructor
A new instance of UnorderedArrayMatcher.
- #match(errors, actual, prefix) ⇒ Object
- #match_one(missing, item, index, actual) ⇒ Object
- #unwrap_array ⇒ Object
Constructor Details
#initialize(array) ⇒ UnorderedArrayMatcher
Returns a new instance of UnorderedArrayMatcher.
80 81 82 |
# File 'lib/rspec/json_expectations/matchers.rb', line 80 def initialize(array) @array = array end |
Instance Attribute Details
#array ⇒ Object (readonly)
Returns the value of attribute array.
76 77 78 |
# File 'lib/rspec/json_expectations/matchers.rb', line 76 def array @array end |
Instance Method Details
#all?(&blk) ⇒ Boolean
106 107 108 |
# File 'lib/rspec/json_expectations/matchers.rb', line 106 def all?(&blk) array.each_with_index.all?(&blk) end |
#check_for_missing(missing, item, index, ok) ⇒ Object
101 102 103 104 |
# File 'lib/rspec/json_expectations/matchers.rb', line 101 def check_for_missing(missing, item, index, ok) missing << { item: item, index: index } unless ok ok end |
#match(errors, actual, prefix) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/rspec/json_expectations/matchers.rb', line 84 def match(errors, actual, prefix) missing_items = [] errors[prefix.join("/")] = { missing: missing_items } all? do |expected_item, index| match_one(missing_items, expected_item, index, actual) end end |
#match_one(missing, item, index, actual) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/rspec/json_expectations/matchers.rb', line 93 def match_one(missing, item, index, actual) check_for_missing(missing, item, index, actual.any? do |actual_item| JsonTraverser.traverse({}, item, actual_item, false) end ) end |
#unwrap_array ⇒ Object
110 111 112 |
# File 'lib/rspec/json_expectations/matchers.rb', line 110 def unwrap_array array end |