Class: Spec::Matchers::SimpleMatcher
- Defined in:
- lib/spec/matchers/simple_matcher.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #explanation ⇒ 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 |
# File 'lib/spec/matchers/simple_matcher.rb', line 6 def initialize(description, &match_block) @description = description @match_block = match_block end |
Instance Attribute Details
#description ⇒ Object
21 22 23 |
# File 'lib/spec/matchers/simple_matcher.rb', line 21 def description @description || explanation end |
#failure_message ⇒ Object
25 26 27 |
# File 'lib/spec/matchers/simple_matcher.rb', line 25 def @failure_message || (@description.nil? ? explanation : %[expected #{@description.inspect} but got #{@given.inspect}]) end |
#negative_failure_message ⇒ Object
29 30 31 |
# File 'lib/spec/matchers/simple_matcher.rb', line 29 def @negative_failure_message || (@description.nil? ? explanation : %[expected not to get #{@description.inspect}, but got #{@given.inspect}]) end |
Instance Method Details
#explanation ⇒ Object
33 34 35 |
# File 'lib/spec/matchers/simple_matcher.rb', line 33 def explanation "No description provided. See RDoc for simple_matcher()" end |
#matches?(given) ⇒ Boolean
11 12 13 14 15 16 17 18 19 |
# File 'lib/spec/matchers/simple_matcher.rb', line 11 def matches?(given) @given = given case @match_block.arity when 2 @match_block.call(@given, self) else @match_block.call(@given) end end |