Class: JsonExpressions::RSpec::Matchers::MatchJsonExpression
- Inherits:
-
Object
- Object
- JsonExpressions::RSpec::Matchers::MatchJsonExpression
- Defined in:
- lib/json_expressions/rspec/matchers/match_json_expression.rb
Instance Method Summary collapse
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(expected) ⇒ MatchJsonExpression
constructor
A new instance of MatchJsonExpression.
- #matches?(target) ⇒ Boolean
Constructor Details
#initialize(expected) ⇒ MatchJsonExpression
Returns a new instance of MatchJsonExpression.
7 8 9 10 11 12 13 |
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 7 def initialize(expected) if JsonExpressions::Matcher === expected @expected = expected else @expected = JsonExpressions::Matcher.new(expected) end end |
Instance Method Details
#failure_message_for_should ⇒ Object
20 21 22 |
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 20 def "expected #{@target.inspect} to match JSON expression #{@expected.inspect}\n" + @expected.last_error end |
#failure_message_for_should_not ⇒ Object
24 25 26 |
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 24 def "expected #{@target.inspect} not to match JSON expression #{@expected.inspect}" end |
#matches?(target) ⇒ Boolean
15 16 17 18 |
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 15 def matches?(target) @target = (String === target) ? JSON.parse(target) : target @expected =~ @target end |