Class: CustomMatcher
- Inherits:
-
Object
- Object
- CustomMatcher
- Defined in:
- lib/rspec-custom-matchers.rb
Defined Under Namespace
Modules: Helper
Class Method Summary collapse
Instance Method Summary collapse
- #description(*args) ⇒ Object
- #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.
11 12 13 |
# File 'lib/rspec-custom-matchers.rb', line 11 def initialize(expected = nil) @expected = expected end |
Class Method Details
.create(class_name, &block) ⇒ Object
5 6 7 8 9 |
# File 'lib/rspec-custom-matchers.rb', line 5 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
#description(*args) ⇒ Object
36 37 38 |
# File 'lib/rspec-custom-matchers.rb', line 36 def description *args class_display_name end |
#failure_message ⇒ Object
15 16 17 |
# File 'lib/rspec-custom-matchers.rb', line 15 def end |
#matcher(target, expected) ⇒ Object
23 24 25 |
# File 'lib/rspec-custom-matchers.rb', line 23 def matcher(target, expected) target == expected end |
#matches?(target) ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/rspec-custom-matchers.rb', line 27 def matches?(target) @target = target if self.method(:matcher).arity == 2 matcher(@target, @expected) else matcher(@target) end end |
#negative_failure_message ⇒ Object
19 20 21 |
# File 'lib/rspec-custom-matchers.rb', line 19 def (false) end |