Class: Crspec::Matchers::RespondToMatcher

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, #failure_message_when_negated, #or

Constructor Details

#initialize(*methods) ⇒ RespondToMatcher

Returns a new instance of RespondToMatcher.



236
237
238
239
# File 'lib/crspec/matchers.rb', line 236

def initialize(*methods)
  super(methods)
  @methods = methods
end

Instance Method Details

#failure_messageObject



246
247
248
# File 'lib/crspec/matchers.rb', line 246

def failure_message
  "Expected #{@actual.inspect} to respond to #{@methods.map(&:inspect).join(", ")}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


241
242
243
244
# File 'lib/crspec/matchers.rb', line 241

def matches?(actual)
  @actual = actual
  @methods.all? { |m| @actual.respond_to?(m) }
end