Class: EqualJsonArrayWithKey
- Inherits:
-
Object
- Object
- EqualJsonArrayWithKey
- Defined in:
- lib/eq_json_array_with_key.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
Returns the value of attribute actual.
-
#expected ⇒ Object
Returns the value of attribute expected.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(expected, key) ⇒ EqualJsonArrayWithKey
constructor
A new instance of EqualJsonArrayWithKey.
- #matches?(actual) ⇒ Boolean
Constructor Details
#initialize(expected, key) ⇒ EqualJsonArrayWithKey
Returns a new instance of EqualJsonArrayWithKey.
11 12 13 14 15 16 17 18 |
# File 'lib/eq_json_array_with_key.rb', line 11 def initialize(expected, key) unless key.is_a? Symbol raise "Key should be a symbol" end @expected = expected @key = key @messageGenerator = ArrayWithKeyMessageGen.new(self) end |
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
9 10 11 |
# File 'lib/eq_json_array_with_key.rb', line 9 def actual @actual end |
#expected ⇒ Object
Returns the value of attribute expected.
9 10 11 |
# File 'lib/eq_json_array_with_key.rb', line 9 def expected @expected end |
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/eq_json_array_with_key.rb', line 9 def key @key end |
Instance Method Details
#failure_message ⇒ Object
49 50 51 |
# File 'lib/eq_json_array_with_key.rb', line 49 def return @failureMessage end |
#matches?(actual) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/eq_json_array_with_key.rb', line 20 def matches?(actual) @actual = actual unless actual.length == expected.length @failureMessage = @messageGenerator.generateDifferentSizeArrays() return false end @expected.each() do |expectedItem| if expectedItem[@key].nil? @failureMessage = @messageGenerator.generateExpectedItemMissingKey(expectedItem) return false end actualItem = actual.find {|item| item[@key] == expectedItem[@key]} if actualItem.nil? @failureMessage = @messageGenerator.generateExpectedNotInActual(expectedItem) return false; end @eqJsonMatcher=EqualJson.new(expectedItem) if !@eqJsonMatcher.matches?(actualItem) @failureMessage = @messageGenerator.generateFailureMessage(expectedItem, @eqJsonMatcher.) return false; end end return true; end |