Class: Crspec::Matchers::PredicateMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Crspec::Matchers::PredicateMatcher
- Defined in:
- lib/crspec/matchers.rb
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(predicate, description, *args, **kwargs, &block) ⇒ PredicateMatcher
constructor
A new instance of PredicateMatcher.
- #matches?(actual) ⇒ Boolean
Methods inherited from BaseMatcher
Constructor Details
#initialize(predicate, description, *args, **kwargs, &block) ⇒ PredicateMatcher
Returns a new instance of PredicateMatcher.
303 304 305 306 307 308 309 310 |
# File 'lib/crspec/matchers.rb', line 303 def initialize(predicate, description, *args, **kwargs, &block) super(nil) @predicate = predicate @description = description @args = args @kwargs = kwargs @block = block end |
Instance Method Details
#failure_message ⇒ Object
321 322 323 |
# File 'lib/crspec/matchers.rb', line 321 def "Expected #{@actual.inspect} to #{@description}#{args_description}" end |
#failure_message_when_negated ⇒ Object
325 326 327 |
# File 'lib/crspec/matchers.rb', line 325 def "Expected #{@actual.inspect} not to #{@description}#{args_description}" end |
#matches?(actual) ⇒ Boolean
312 313 314 315 316 317 318 319 |
# File 'lib/crspec/matchers.rb', line 312 def matches?(actual) @actual = actual unless @actual.respond_to?(@predicate) raise NoMethodError, "undefined method '#{@predicate}' for #{@actual.inspect}" end !!@actual.public_send(@predicate, *@args, **@kwargs, &@block) end |