Parent

Class Index [+]

Quicksearch

Spec::Matchers::Matcher

Attributes

expected[R]
actual[R]

Public Class Methods

new(name, *expected, &declarations) click to toggle source
    # 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

Public Instance Methods

chain(method, &block) click to toggle source

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
description(&block) click to toggle source

See Spec::Matchers

    # File lib/spec/matchers/matcher.rb, line 67
67:       def description(&block)
68:         cache_or_call_cached(:description, &block)
69:       end
diffable() click to toggle source

See Spec::Matchers

    # File lib/spec/matchers/matcher.rb, line 77
77:       def diffable
78:         @diffable = true
79:       end
diffable?() click to toggle source

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
failure_message_for_should(&block) click to toggle source

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
failure_message_for_should_not(&block) click to toggle source

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
match(&block) click to toggle source

See Spec::Matchers

    # File lib/spec/matchers/matcher.rb, line 46
46:       def match(&block)
47:         @match_block = block
48:       end
match_unless_raises(exception=Exception, &block) click to toggle source

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
matches?(actual) click to toggle source

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

Private Instance Methods

cache(key, &block) click to toggle source
     # File lib/spec/matchers/matcher.rb, line 114
114:       def cache(key, &block)
115:         @messages[key] = block
116:       end
cache_or_call_cached(key, &block) click to toggle source
     # 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
call_cached(key) click to toggle source
     # 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
expected_to_sentence() click to toggle source
     # File lib/spec/matchers/matcher.rb, line 126
126:       def expected_to_sentence
127:         to_sentence(@expected)
128:       end
name_to_sentence() click to toggle source
     # File lib/spec/matchers/matcher.rb, line 122
122:       def name_to_sentence
123:         split_words(@name)
124:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.