Object
# File lib/rspec/matchers/matcher.rb, line 9 def initialize(name, *expected, &declarations) @name = name @expected = expected @actual = nil @diffable = false @expected_exception, @rescued_exception = nil, nil @match_for_should_not_block = nil @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}"} } making_declared_methods_public do instance_exec(*@expected, &declarations) end end
See RSpec::Matchers
# File lib/rspec/matchers/matcher.rb, line 105 def chain(method, &block) define_method method do |*args| block.call(*args) self end end
See RSpec::Matchers
# File lib/rspec/matchers/matcher.rb, line 90 def description(&block) cache_or_call_cached(:description, &block) end
See RSpec::Matchers
# File lib/rspec/matchers/matcher.rb, line 100 def diffable @diffable = true end
Used internally by objects returns by should and should_not.
# File lib/rspec/matchers/matcher.rb, line 95 def diffable? @diffable end
Used internally by should_not
# File lib/rspec/matchers/matcher.rb, line 47 def does_not_match?(actual) @actual = actual @match_for_should_not_block ? instance_exec(actual, &@match_for_should_not_block) : !matches?(actual) end
See RSpec::Matchers
# File lib/rspec/matchers/matcher.rb, line 80 def failure_message_for_should(&block) cache_or_call_cached(:failure_message_for_should, &block) end
See RSpec::Matchers
# File lib/rspec/matchers/matcher.rb, line 85 def failure_message_for_should_not(&block) cache_or_call_cached(:failure_message_for_should_not, &block) end
# File lib/rspec/matchers/matcher.rb, line 54 def include(*args) singleton_class.__send__(:include, *args) end
See RSpec::Matchers
# File lib/rspec/matchers/matcher.rb, line 63 def match(&block) @match_block = block end
See RSpec::Matchers
# File lib/rspec/matchers/matcher.rb, line 69 def match_for_should_not(&block) @match_for_should_not_block = block end
See RSpec::Matchers
# File lib/rspec/matchers/matcher.rb, line 74 def match_unless_raises(exception=Exception, &block) @expected_exception = exception match(&block) end
Used internally by should and should_not.
# File lib/rspec/matchers/matcher.rb, line 28 def matches?(actual) @actual = actual if @expected_exception begin instance_exec(actual, &@match_block) true rescue @expected_exception => @rescued_exception false end else begin instance_exec(actual, &@match_block) rescue RSpec::Expectations::ExpectationNotMetError false end end end
Generated with the Darkfish Rdoc Generator 2.