module RSpec::Matchers::Custom::MatchersHelper

Public Class Methods

get_message(matcher, key) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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