Class: Spec::Matchers::Matcher
Instance Attribute Summary collapse
Instance Method Summary
collapse
#be, #be_a, #be_a_kind_of, #be_an_instance_of, #be_close, #change, clear_generated_description, #eql, #equal, #exception_from, #exist, #fail, #fail_with, generated_description, #have, #have_at_least, #have_at_most, #include, #map_specs, #method_missing, #raise_error, #respond_to, #run_with, #satisfy, #simple_matcher, #throw_symbol, #with_ruby, #wrap_expectation
Methods included from DSL
#create, #define
Methods included from Pretty
#_pretty_print, #split_words, #to_sentence
#instance_exec
Constructor Details
#initialize(name, *expected, &declarations) ⇒ Matcher
Returns a new instance of Matcher.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 10
def initialize(name, *expected, &declarations)
@name = name
@expected = expected
@actual = nil
@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}"}
}
making_declared_methods_public do
instance_exec(*@expected, &declarations)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Spec::Matchers
Instance Attribute Details
Returns the value of attribute actual.
8
9
10
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 8
def actual
@actual
end
|
Returns the value of attribute expected.
8
9
10
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 8
def expected
@expected
end
|
Instance Method Details
#description(&block) ⇒ Object
29
30
31
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 29
def description(&block)
cache_or_call_cached(:description, &block)
end
|
49
50
51
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 49
def diffable
@diffable = true
end
|
#diffable? ⇒ Boolean
45
46
47
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 45
def diffable?
@diffable
end
|
#failure_message_for_should(&block) ⇒ Object
33
34
35
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 33
def failure_message_for_should(&block)
cache_or_call_cached(:failure_message_for_should, actual, &block)
end
|
#failure_message_for_should_not(&block) ⇒ Object
37
38
39
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 37
def failure_message_for_should_not(&block)
cache_or_call_cached(:failure_message_for_should_not, actual, &block)
end
|
#match(&block) ⇒ Object
41
42
43
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 41
def match(&block)
@match_block = block
end
|
#matches?(actual) ⇒ Boolean
25
26
27
|
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/matcher.rb', line 25
def matches?(actual)
instance_exec(@actual = actual, &@match_block)
end
|