Class: Spec::Matchers::Matcher
Instance Method Summary collapse
- #description(&block) ⇒ Object
- #failure_message_for_should(&block) ⇒ Object
- #failure_message_for_should_not(&block) ⇒ Object
-
#initialize(name, expected = nil, &block_passed_to_init) ⇒ Matcher
constructor
A new instance of Matcher.
- #match(&block) ⇒ Object
- #matches?(actual) ⇒ Boolean
Constructor Details
#initialize(name, expected = nil, &block_passed_to_init) ⇒ Matcher
Returns a new instance of Matcher.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/spec/matchers/matcher.rb', line 4 def initialize(name, expected=nil, &block_passed_to_init) @name = name @expected = expected @block = block_passed_to_init @messages = { :description => lambda {"#{name_to_sentence} #{expected}"}, :failure_message_for_should => lambda {|actual| "expected #{actual} to #{name_to_sentence} #{expected}"}, :failure_message_for_should_not => lambda {|actual| "expected #{actual} not to #{name_to_sentence} #{expected}"} } end |
Instance Method Details
#description(&block) ⇒ Object
21 22 23 |
# File 'lib/spec/matchers/matcher.rb', line 21 def description(&block) cache_or_call_cached(:description, &block) end |
#failure_message_for_should(&block) ⇒ Object
25 26 27 |
# File 'lib/spec/matchers/matcher.rb', line 25 def (&block) cache_or_call_cached(:failure_message_for_should, @actual, &block) end |
#failure_message_for_should_not(&block) ⇒ Object
29 30 31 |
# File 'lib/spec/matchers/matcher.rb', line 29 def (&block) cache_or_call_cached(:failure_message_for_should_not, @actual, &block) end |
#match(&block) ⇒ Object
33 34 35 |
# File 'lib/spec/matchers/matcher.rb', line 33 def match(&block) @match_block = block end |
#matches?(actual) ⇒ Boolean
15 16 17 18 19 |
# File 'lib/spec/matchers/matcher.rb', line 15 def matches?(actual) @actual = actual instance_exec @expected, &@block instance_exec @actual, &@match_block end |