Class: Micronaut::Matchers::RespondTo

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(*names) ⇒ RespondTo

Returns a new instance of RespondTo.



6
7
8
9
# File 'lib/micronaut/matchers/respond_to.rb', line 6

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

Instance Method Details

#descriptionObject



29
30
31
32
# File 'lib/micronaut/matchers/respond_to.rb', line 29

def description
  # Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
  "respond to #{@names.inspect}"
end

#failure_messageObject



21
22
23
# File 'lib/micronaut/matchers/respond_to.rb', line 21

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

#matches?(given) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
# File 'lib/micronaut/matchers/respond_to.rb', line 11

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

#negative_failure_messageObject



25
26
27
# File 'lib/micronaut/matchers/respond_to.rb', line 25

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