Class: Pact::RSpec::Matchers::MatchTerm

Inherits:
Object
  • Object
show all
Includes:
Matchers::Messages, RSpec2Delegator
Defined in:
lib/pact/provider/rspec/matchers.rb

Instance Method Summary collapse

Methods included from RSpec2Delegator

#method_missing

Methods included from Matchers::Messages

#expected_desc_for_it, #match_header_failure_message, #match_term_failure_message

Constructor Details

#initialize(expected, differ, diff_formatter, example) ⇒ MatchTerm

Returns a new instance of MatchTerm.



25
26
27
28
29
30
# File 'lib/pact/provider/rspec/matchers.rb', line 25

def initialize expected, differ, diff_formatter, example
  @expected = expected
  @differ = differ
  @diff_formatter = diff_formatter
  @example = example
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Pact::RSpec::Matchers::RSpec2Delegator

Instance Method Details

#failure_messageObject



46
47
48
# File 'lib/pact/provider/rspec/matchers.rb', line 46

def failure_message
  match_term_failure_message @difference, @actual, @diff_formatter, Pact::RSpec.color_enabled?
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pact/provider/rspec/matchers.rb', line 32

def matches? actual
  @actual = actual
  @difference = @differ.call(@expected, @actual)
  unless @difference.empty?
    Pact::RSpec.with_rspec_3 do
      @example.[:pact_diff] = @difference
    end
    Pact::RSpec.with_rspec_2 do
      @example.example.[:pact_diff] = @difference
    end
  end
  @difference.empty?
end