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

#failure_message_when_negated

Constructor Details

#initialize(*methods) ⇒ RespondToMatcher

Returns a new instance of RespondToMatcher.



156
157
158
159
# File 'lib/crspec/matchers.rb', line 156

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

Instance Method Details

#failure_messageObject



166
167
168
# File 'lib/crspec/matchers.rb', line 166

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


161
162
163
164
# File 'lib/crspec/matchers.rb', line 161

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