Class: CustomMatcher
- Inherits:
-
Object
- Object
- CustomMatcher
- Defined in:
- lib/rspec/custom_matcher.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(expected = nil) ⇒ CustomMatcher
constructor
A new instance of CustomMatcher.
- #matcher(target, expected) ⇒ Object
- #matches?(target) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(expected = nil) ⇒ CustomMatcher
Returns a new instance of CustomMatcher.
10 11 12 |
# File 'lib/rspec/custom_matcher.rb', line 10 def initialize(expected = nil) @expected = expected end |
Class Method Details
.create(class_name, &block) ⇒ Object
4 5 6 7 8 |
# File 'lib/rspec/custom_matcher.rb', line 4 def self.create(class_name, &block) klass = Class.new(CustomMatcher) klass.send(:define_method, :matcher, &block) if block_given? Object.const_set(build_class_name(class_name), klass) end |
Instance Method Details
#failure_message ⇒ Object
14 15 16 |
# File 'lib/rspec/custom_matcher.rb', line 14 def end |
#matcher(target, expected) ⇒ Object
22 23 24 |
# File 'lib/rspec/custom_matcher.rb', line 22 def matcher(target, expected) target == expected end |
#matches?(target) ⇒ Boolean
26 27 28 29 30 31 32 33 |
# File 'lib/rspec/custom_matcher.rb', line 26 def matches?(target) @target = target if self.method(:matcher).arity == 2 matcher(@target, @expected) else matcher(@target) end end |
#negative_failure_message ⇒ Object
18 19 20 |
# File 'lib/rspec/custom_matcher.rb', line 18 def (false) end |