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.



8
9
10
11
12
13
14
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 8

def initialize(expected)
  if JsonExpressions::Matcher === expected
    @expected = expected
  else
    @expected = JsonExpressions::Matcher.new(expected)
  end
end

Instance Method Details

#descriptionObject



32
33
34
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 32

def description
  "should equal JSON expression #{@expected.inspect}"
end

#failure_message_for_shouldObject Also known as: failure_message



22
23
24
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 22

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

#failure_message_for_should_notObject Also known as: failure_message_when_negated



27
28
29
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 27

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

#matches?(target) ⇒ Boolean Also known as: ===

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/json_expressions/rspec/matchers/match_json_expression.rb', line 16

def matches?(target)
  @target = (String === target) ? JSON.parse(target) : target
  @expected =~ @target
end