Class: Crspec::Matchers::PredicateMatcher

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/crspec/matchers.rb

Instance Attribute Summary

Attributes inherited from BaseMatcher

#actual, #expected

Instance Method Summary collapse

Methods inherited from BaseMatcher

#and, #or

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_messageObject



321
322
323
# File 'lib/crspec/matchers.rb', line 321

def failure_message
  "Expected #{@actual.inspect} to #{@description}#{args_description}"
end

#failure_message_when_negatedObject



325
326
327
# File 'lib/crspec/matchers.rb', line 325

def failure_message_when_negated
  "Expected #{@actual.inspect} not to #{@description}#{args_description}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (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