Exception: Assay::ResponseFailure

Inherits:
Assertion
  • Object
show all
Defined in:
lib/assay/assertions/response_failure.rb

Overview

Does an object #respond_to? a method call.

Constant Summary

Constants inherited from Assertion

Assertion::SIZE_LIMIT

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Assertion

assert, #assert, assertable_method, #assertion?, #fail?, fail?, #initialize, #negative?, #pass?, refute, #refute, #set_arguments, #set_negative, to_matcher

Constructor Details

This class inherits a constructor from Assay::Assertion

Class Method Details

.assertion_nameObject



8
9
10
# File 'lib/assay/assertions/response_failure.rb', line 8

def self.assertion_name
  :respond_to
end

.assertion_name!Object



12
13
14
# File 'lib/assay/assertions/response_failure.rb', line 12

def self.assertion_name!
  :not_respond_to
end

.operator_nameObject



16
17
18
# File 'lib/assay/assertions/response_failure.rb', line 16

def self.operator_name
  :respond_to?
end

.pass?(reciever, method) ⇒ Boolean

Check assertion.

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/assay/assertions/response_failure.rb', line 21

def self.pass?(reciever, method)
  #flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs
  #obj, meth = meth, obj if flip
  reciever.respond_to?(method)
end

Instance Method Details

#to_sObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/assay/assertions/response_failure.rb', line 28

def to_s
  return super unless @arguments.size == 2

  reciever = @arguments[0].inspect
  method   = @arguments[1].inspect

  if @_negated
    "Expected #{reciever} (#{reciever.class}) to NOT respond to ##{method}"
  else
    "Expected #{reciever} (#{reciever.class}) to respond to ##{method}"
  end
end