Class: Spec::Matchers::RespondTo

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/matchers/respond_to.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(*names) ⇒ RespondTo

Returns a new instance of RespondTo.



5
6
7
8
# File 'lib/spec/matchers/respond_to.rb', line 5

def initialize(*names)
  @names = names
  @names_not_responded_to = []
end

Instance Method Details

#descriptionObject



27
28
29
# File 'lib/spec/matchers/respond_to.rb', line 27

def description
  "respond to ##{@names.to_s}"
end

#failure_messageObject



19
20
21
# File 'lib/spec/matchers/respond_to.rb', line 19

def failure_message
  "expected target to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
# File 'lib/spec/matchers/respond_to.rb', line 10

def matches?(target)
  @names.each do |name|
    unless target.respond_to?(name)
      @names_not_responded_to << name
    end
  end
  return @names_not_responded_to.empty?
end

#negative_failure_messageObject



23
24
25
# File 'lib/spec/matchers/respond_to.rb', line 23

def negative_failure_message
  "expected target not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
end