Class Spec::Matchers::Matcher

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

Included modules

  1. Spec::Matchers::Pretty

Attributes

actual [R]
expected [R]

Public class methods

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

Public instance methods

description (&block)
[show source]
# File lib/spec/matchers/matcher.rb, line 26
      def description(&block)
        cache_or_call_cached(:description, &block)
      end
diffable ()
[show source]
# File lib/spec/matchers/matcher.rb, line 46
      def diffable
        @diffable = true
      end
diffable? ()
[show source]
# File lib/spec/matchers/matcher.rb, line 42
      def diffable?
        @diffable
      end
failure_message_for_should (&block)
[show source]
# File lib/spec/matchers/matcher.rb, line 30
      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 34
      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 38
      def match(&block)
        @match_block = block
      end
matches? (actual)
[show source]
# File lib/spec/matchers/matcher.rb, line 20
      def matches?(actual)
        @actual = actual
        instance_exec(*@expected, &@declarations)
        instance_exec(@actual,    &@match_block)
      end