Class Spec::Matchers::Matcher

  1. lib/spec/matchers/matcher.rb
Parent: Object

Included modules

  1. Spec::Matchers::Pretty

Public class methods

new (name, *expected, &declarations)
[show source]
# File lib/spec/matchers/matcher.rb, line 6
      def initialize(name, *expected, &declarations)
        @name = name
        @expected = expected
        @declarations = declarations
        @messages = {
          :description => lambda {"#{name_to_sentence}#{expected_to_sentence}"},
          :failure_message_for_should => lambda {|actual| "expected #{actual} to #{name_to_sentence}#{expected_to_sentence}"},
          :failure_message_for_should_not => lambda {|actual| "expected #{actual} not to #{name_to_sentence}#{expected_to_sentence}"}
        }
      end

Public instance methods

description (&block)
[show source]
# File lib/spec/matchers/matcher.rb, line 23
      def description(&block)
        cache_or_call_cached(:description, &block)
      end
failure_message_for_should (&block)
[show source]
# File lib/spec/matchers/matcher.rb, line 27
      def failure_message_for_should(&block)
        cache_or_call_cached(:failure_message_for_should, @actual, &block)
      end
failure_message_for_should_not (&block)
[show source]
# File lib/spec/matchers/matcher.rb, line 31
      def failure_message_for_should_not(&block)
        cache_or_call_cached(:failure_message_for_should_not, @actual, &block)
      end
match (&block)
[show source]
# File lib/spec/matchers/matcher.rb, line 35
      def match(&block)
        @match_block = block
      end
matches? (actual)
[show source]
# File lib/spec/matchers/matcher.rb, line 17
      def matches?(actual)
        @actual = actual
        instance_exec(*@expected, &@declarations)
        instance_exec(@actual,    &@match_block)
      end