Class: JsonSpec::Matchers::BeJsonEql
- Inherits:
-
Object
- Object
- JsonSpec::Matchers::BeJsonEql
show all
- Includes:
- Exclusion, Helpers
- Defined in:
- lib/json_spec/matchers.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Exclusion
#exclude_key?, #exclude_keys, #excluded_keys
Methods included from Helpers
#generate_normalized_json, #normalize_json, #parse_json
Constructor Details
#initialize(expected_json) ⇒ BeJsonEql
Returns a new instance of BeJsonEql.
16
17
18
|
# File 'lib/json_spec/matchers.rb', line 16
def initialize(expected_json)
@expected_json = expected_json
end
|
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
10
11
12
|
# File 'lib/json_spec/matchers.rb', line 10
def actual
@actual
end
|
#expected ⇒ Object
Returns the value of attribute expected.
10
11
12
|
# File 'lib/json_spec/matchers.rb', line 10
def expected
@expected
end
|
Instance Method Details
#at_path(path) ⇒ Object
25
26
27
28
|
# File 'lib/json_spec/matchers.rb', line 25
def at_path(path)
@path = path
self
end
|
#description ⇒ Object
52
53
54
55
56
|
# File 'lib/json_spec/matchers.rb', line 52
def description
message = "equal JSON"
message << %( at path "#{@path}") if @path
message
end
|
#diffable? ⇒ Boolean
12
13
14
|
# File 'lib/json_spec/matchers.rb', line 12
def diffable?
true
end
|
#excluding(*keys) ⇒ Object
30
31
32
33
|
# File 'lib/json_spec/matchers.rb', line 30
def excluding(*keys)
excluded_keys.merge(keys.map{|k| k.to_s })
self
end
|
#failure_message_for_should ⇒ Object
40
41
42
43
44
|
# File 'lib/json_spec/matchers.rb', line 40
def failure_message_for_should
message = "Expected equivalent JSON"
message << %( at path "#{@path}") if @path
message
end
|
#failure_message_for_should_not ⇒ Object
46
47
48
49
50
|
# File 'lib/json_spec/matchers.rb', line 46
def failure_message_for_should_not
message = "Expected inequivalent JSON"
message << %( at path "#{@path}") if @path
message
end
|
#including(*keys) ⇒ Object
35
36
37
38
|
# File 'lib/json_spec/matchers.rb', line 35
def including(*keys)
excluded_keys.subtract(keys.map{|k| k.to_s })
self
end
|
#matches?(actual_json) ⇒ Boolean
20
21
22
23
|
# File 'lib/json_spec/matchers.rb', line 20
def matches?(actual_json)
@actual, @expected = scrub(actual_json, @path), scrub(@expected_json)
@actual == @expected
end
|