Class: RSpec::JsonExpectations::MatcherFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/json_expectations/matcher_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(matcher_name) ⇒ MatcherFactory

Returns a new instance of MatcherFactory.



4
5
6
# File 'lib/rspec/json_expectations/matcher_factory.rb', line 4

def initialize(matcher_name)
  @matcher_name = matcher_name
end

Instance Method Details

#define_matcher(&block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rspec/json_expectations/matcher_factory.rb', line 8

def define_matcher(&block)
  RSpec::Matchers.define(@matcher_name) do |expected|
    yield

    match do |actual|
      traverse(expected, actual, false)
    end

    match_when_negated do |actual|
      traverse(expected, actual, true)
    end

    failure_message do |actual|
      RSpec::JsonExpectations::FailurePresenter.render(@include_json_errors)
    end

    failure_message_when_negated do |actual|
      RSpec::JsonExpectations::FailurePresenter.render(@include_json_errors)
    end
  end
end