Class: Spec::Matchers::SimpleMatcher
- Defined in:
- lib/spec/matchers/simple_matcher.rb
Instance Attribute Summary collapse
- #description ⇒ Object
-
#failure_message ⇒ Object
writeonly
Sets the attribute failure_message.
-
#negative_failure_message ⇒ Object
writeonly
Sets the attribute negative_failure_message.
Instance Method Summary collapse
- #explanation ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(description, &match_block) ⇒ SimpleMatcher
constructor
A new instance of SimpleMatcher.
- #matches?(given) ⇒ Boolean
Constructor Details
#initialize(description, &match_block) ⇒ SimpleMatcher
Returns a new instance of SimpleMatcher.
6 7 8 9 10 |
# File 'lib/spec/matchers/simple_matcher.rb', line 6 def initialize(description, &match_block) @description = description @match_block = match_block @failure_message = @negative_failure_message = nil end |
Instance Attribute Details
#description ⇒ Object
22 23 24 |
# File 'lib/spec/matchers/simple_matcher.rb', line 22 def description @description || explanation end |
#failure_message=(value) ⇒ Object (writeonly)
Sets the attribute failure_message
4 5 6 |
# File 'lib/spec/matchers/simple_matcher.rb', line 4 def (value) @failure_message = value end |
#negative_failure_message=(value) ⇒ Object (writeonly)
Sets the attribute negative_failure_message
4 5 6 |
# File 'lib/spec/matchers/simple_matcher.rb', line 4 def (value) @negative_failure_message = value end |
Instance Method Details
#explanation ⇒ Object
34 35 36 |
# File 'lib/spec/matchers/simple_matcher.rb', line 34 def explanation "No description provided. See RDoc for simple_matcher()" end |
#failure_message_for_should ⇒ Object
26 27 28 |
# File 'lib/spec/matchers/simple_matcher.rb', line 26 def @failure_message || (@description.nil? ? explanation : %[expected #{@description.inspect} but got #{@given.inspect}]) end |
#failure_message_for_should_not ⇒ Object
30 31 32 |
# File 'lib/spec/matchers/simple_matcher.rb', line 30 def @negative_failure_message || (@description.nil? ? explanation : %[expected not to get #{@description.inspect}, but got #{@given.inspect}]) end |
#matches?(given) ⇒ Boolean
12 13 14 15 16 17 18 19 20 |
# File 'lib/spec/matchers/simple_matcher.rb', line 12 def matches?(given) @given = given case @match_block.arity when 2 @match_block.call(@given, self) else @match_block.call(@given) end end |