# File lib/spec/matchers/matcher.rb, line 10
10: def initialize(name, *expected, &declarations)
11: @name = name
12: @expected = expected
13: @actual = nil
14: @diffable = false
15: @expected_exception = nil
16: @messages = {
17: :description => lambda {"#{name_to_sentence}#{expected_to_sentence}"},
18: :failure_message_for_should => lambda {|actual| "expected #{actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"},
19: :failure_message_for_should_not => lambda {|actual| "expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"}
20: }
21: making_declared_methods_public do
22: instance_exec(*@expected, &declarations)
23: end
24: end
See Spec::Matchers
# File lib/spec/matchers/matcher.rb, line 82
82: def chain(method, &block)
83: self.class.class_eval do
84: define_method method do |*args|
85: block.call(*args)
86: self
87: end
88: end
89: end
See Spec::Matchers
# File lib/spec/matchers/matcher.rb, line 67
67: def description(&block)
68: cache_or_call_cached(:description, &block)
69: end
See Spec::Matchers
# File lib/spec/matchers/matcher.rb, line 77
77: def diffable
78: @diffable = true
79: end
Used internally by objects returns by should and should_not.
# File lib/spec/matchers/matcher.rb, line 72
72: def diffable?
73: @diffable
74: end
See Spec::Matchers
# File lib/spec/matchers/matcher.rb, line 57
57: def failure_message_for_should(&block)
58: cache_or_call_cached(:failure_message_for_should, &block)
59: end
See Spec::Matchers
# File lib/spec/matchers/matcher.rb, line 62
62: def failure_message_for_should_not(&block)
63: cache_or_call_cached(:failure_message_for_should_not, &block)
64: end
See Spec::Matchers
# File lib/spec/matchers/matcher.rb, line 46
46: def match(&block)
47: @match_block = block
48: end
See Spec::Matchers
# File lib/spec/matchers/matcher.rb, line 51
51: def match_unless_raises(exception=Exception, &block)
52: @expected_exception = exception
53: match(&block)
54: end
Used internally by objects returns by should and should_not.
# File lib/spec/matchers/matcher.rb, line 27
27: def matches?(actual)
28: @actual = actual
29: if @expected_exception
30: begin
31: instance_exec(actual, &@match_block)
32: true
33: rescue @expected_exception
34: false
35: end
36: else
37: begin
38: instance_exec(actual, &@match_block)
39: rescue Spec::Expectations::ExpectationNotMetError
40: false
41: end
42: end
43: end
# File lib/spec/matchers/matcher.rb, line 114
114: def cache(key, &block)
115: @messages[key] = block
116: end
# File lib/spec/matchers/matcher.rb, line 110
110: def cache_or_call_cached(key, &block)
111: block ? cache(key, &block) : call_cached(key)
112: end
# File lib/spec/matchers/matcher.rb, line 118
118: def call_cached(key)
119: @messages[key].arity == 1 ? @messages[key].call(@actual) : @messages[key].call
120: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.