Class: JsonResponseMatchers::Values
- Defined in:
- lib/json_response_matchers/values.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #failure_message ⇒ Object
- #for(*attributes) ⇒ Object
- #in_strict_order ⇒ Object
-
#initialize(expected) ⇒ Values
constructor
A new instance of Values.
- #matches?(actual) ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(expected) ⇒ Values
Returns a new instance of Values.
6 7 8 9 |
# File 'lib/json_response_matchers/values.rb', line 6 def initialize expected super @check_order = false end |
Instance Method Details
#failure_message ⇒ Object
11 12 13 |
# File 'lib/json_response_matchers/values.rb', line 11 def "expected\n #{@actual}\nto #{@check_order ? 'equal' : 'match'}\n #{@expected}" end |
#for(*attributes) ⇒ Object
25 26 27 28 |
# File 'lib/json_response_matchers/values.rb', line 25 def for *attributes @for = attributes.map &:to_s self end |
#in_strict_order ⇒ Object
30 31 32 33 |
# File 'lib/json_response_matchers/values.rb', line 30 def in_strict_order @check_order = true self end |
#matches?(actual) ⇒ Boolean
16 17 18 19 20 21 22 23 |
# File 'lib/json_response_matchers/values.rb', line 16 def matches? actual raise ArgumentError, "You must set one or more attributes for mapping with #for:\n have_json_values(#{@expected}).for(attribute_name(s))" unless @for @actual = fetch_from extract_parsed_json_from actual @actual = @actual.map do |item| @for.one? ? item[@for.first] : @for.map { |attribute| item[attribute] } end @check_order ? @actual == @expected : arrays_match? end |