Class: JsonSpec::Matchers::BeJsonEql
Instance Attribute Summary collapse
Instance Method Summary
collapse
#message_with_path
Methods included from Exclusion
#exclude_key?, #exclude_keys, #excluded_keys
Methods included from Helpers
#generate_normalized_json, #load_json, #normalize_json, #parse_json
Constructor Details
#initialize(expected_json = nil) ⇒ BeJsonEql
Returns a new instance of BeJsonEql.
14
15
16
17
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 14
def initialize(expected_json = nil)
@expected_json = expected_json
@path = nil
end
|
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
8
9
10
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 8
def actual
@actual
end
|
#expected ⇒ Object
Returns the value of attribute expected.
8
9
10
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 8
def expected
@expected
end
|
Instance Method Details
#at_path(path) ⇒ Object
26
27
28
29
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 26
def at_path(path)
@path = path
self
end
|
#description ⇒ Object
56
57
58
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 56
def description
message_with_path("equal JSON")
end
|
#diffable? ⇒ Boolean
10
11
12
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 10
def diffable?
true
end
|
#excluding(*keys) ⇒ Object
36
37
38
39
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 36
def excluding(*keys)
excluded_keys.merge(keys.map(&:to_s))
self
end
|
#failure_message ⇒ Object
Also known as:
failure_message_for_should
46
47
48
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 46
def failure_message
message_with_path("Expected equivalent JSON")
end
|
#failure_message_when_negated ⇒ Object
Also known as:
failure_message_for_should_not
51
52
53
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 51
def failure_message_when_negated
message_with_path("Expected inequivalent JSON")
end
|
#including(*keys) ⇒ Object
41
42
43
44
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 41
def including(*keys)
excluded_keys.subtract(keys.map(&:to_s))
self
end
|
#matches?(actual_json) ⇒ Boolean
19
20
21
22
23
24
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 19
def matches?(actual_json)
raise "Expected equivalent JSON not provided" if @expected_json.nil?
@actual, @expected = scrub(actual_json, @path), scrub(@expected_json)
@actual == @expected
end
|
#to_file(path) ⇒ Object
31
32
33
34
|
# File 'lib/json_spec/matchers/be_json_eql.rb', line 31
def to_file(path)
@expected_json = load_json(path)
self
end
|