Class: RSpec::JsonMatcher::AbstractMatcher
- Inherits:
-
Object
- Object
- RSpec::JsonMatcher::AbstractMatcher
show all
- Defined in:
- lib/rspec/json_matcher/abstract_matcher.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AbstractMatcher.
6
7
8
9
|
# File 'lib/rspec/json_matcher/abstract_matcher.rb', line 6
def initialize(expected = nil)
@expected = expected
@reasons = []
end
|
Instance Attribute Details
#expected ⇒ Object
Returns the value of attribute expected.
4
5
6
|
# File 'lib/rspec/json_matcher/abstract_matcher.rb', line 4
def expected
@expected
end
|
#parsed ⇒ Object
Returns the value of attribute parsed.
4
5
6
|
# File 'lib/rspec/json_matcher/abstract_matcher.rb', line 4
def parsed
@parsed
end
|
#reasons ⇒ Object
Returns the value of attribute reasons.
4
5
6
|
# File 'lib/rspec/json_matcher/abstract_matcher.rb', line 4
def reasons
@reasons
end
|
Instance Method Details
#compare(&reason) ⇒ Object
27
28
29
|
# File 'lib/rspec/json_matcher/abstract_matcher.rb', line 27
def compare(&reason)
raise NotImplementedError, "You must implement #{self.class}#compare"
end
|
#description ⇒ Object
31
32
33
|
# File 'lib/rspec/json_matcher/abstract_matcher.rb', line 31
def description
"be JSON"
end
|
#failure_message ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/rspec/json_matcher/abstract_matcher.rb', line 35
def failure_message
if has_parser_error?
"expected value to be parsed as JSON, but failed"
else
inspection
end
end
|
#matches?(json) ⇒ Boolean
Also known as:
===
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/rspec/json_matcher/abstract_matcher.rb', line 11
def matches?(json)
@parsed = JSON.parse(json)
if has_expectation?
compare do |reason|
@reasons << reason
end
else
true
end
rescue JSON::ParserError
@parser_error = true
false
end
|
#negative_failure_message ⇒ Object
Also known as:
failure_message_when_negated
43
44
45
46
47
48
49
|
# File 'lib/rspec/json_matcher/abstract_matcher.rb', line 43
def negative_failure_message
if has_parser_error?
"expected value not to be parsed as JSON, but succeeded"
else
inspection("not ")
end
end
|