Module: RSpec::Matchers::Custom::MatchersHelper

Defined in:
lib/rspec-matchers-matchers/custom_matchers_helper.rb

Class Method Summary collapse

Class Method Details

.get_message(matcher, key) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rspec-matchers-matchers/custom_matchers_helper.rb', line 6

def self.get_message(matcher, key)
  actual_messages = matcher.instance_variable_get('@actual_messages')
  if actual_messages.nil?
    actual_messages = Hash.new
    matcher.instance_variable_set('@actual_messages',actual_messages)
  end
  unless actual_messages.has_key? key
    case key
      when :failure_message_for_should
        message = get_positive_failure_message matcher
      when :failure_message_for_should_not
        message = get_negative_failure_message matcher
      when :description
        message = matcher.description
      else
        raise RuntimeError, "Unsupported key #{key}"
    end
    actual_messages[key] = message
  end
  actual_messages[key]
end

.get_negative_failure_message(matcher) ⇒ Object



34
35
36
37
38
# File 'lib/rspec-matchers-matchers/custom_matchers_helper.rb', line 34

def self.get_negative_failure_message(matcher)
  matcher.respond_to?(:failure_message_for_should_not) ?
    matcher.failure_message_for_should_not :
    matcher.negative_failure_message
end

.get_positive_failure_message(matcher) ⇒ Object



28
29
30
31
32
# File 'lib/rspec-matchers-matchers/custom_matchers_helper.rb', line 28

def self.get_positive_failure_message(matcher)
    matcher.respond_to?(:failure_message_for_should) ?
      matcher.failure_message_for_should :
      matcher.failure_message
end

.match_message(actual_message, expected_message) ⇒ Object



40
41
42
43
# File 'lib/rspec-matchers-matchers/custom_matchers_helper.rb', line 40

def self.match_message(actual_message, expected_message)
  # the method is simple, but we use it so we can stub it out if need be
  actual_message.eql? expected_message
end