Class: JsonExpressions::RSpec::Matchers::MatchJsonExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/json_expressions/rspec/matchers/match_json_expression.rb

Instance Method Summary collapse

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_shouldObject



20
21
22
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 20

def failure_message_for_should
  "expected #{@target.inspect} to match JSON expression #{@expected.inspect}\n" + @expected.last_error
end

#failure_message_for_should_notObject



24
25
26
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 24

def failure_message_for_should_not
  "expected #{@target.inspect} not to match JSON expression #{@expected.inspect}"
end

#matches?(target) ⇒ Boolean

Returns:

  • (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