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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rspec/json_expectations/matcher_factory.rb', line 8

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

    # RSpec 2 vs 3
    if respond_to?(:failure_message)
      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
    else
      match_for_should do |actual|
        traverse(expected, actual, false)
      end

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

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

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