Class: BaconExpect::Matcher::RespondTo

Inherits:
Object
  • Object
show all
Defined in:
lib/bacon-expect/matchers/respond_to.rb

Instance Method Summary collapse

Constructor Details

#initialize(method_name) ⇒ RespondTo

Returns a new instance of RespondTo.



3
4
5
# File 'lib/bacon-expect/matchers/respond_to.rb', line 3

def initialize(method_name)
  @method_name = method_name
end

Instance Method Details

#argumentsObject Also known as: argument



12
13
14
# File 'lib/bacon-expect/matchers/respond_to.rb', line 12

def arguments
  self
end

#fail!(subject, negated) ⇒ Object

Raises:



24
25
26
# File 'lib/bacon-expect/matchers/respond_to.rb', line 24

def fail!(subject, negated)
  raise FailedExpectation.new(FailMessageRenderer.message_for_respond_to(negated, subject, @method_name, @number_of_args))
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/bacon-expect/matchers/respond_to.rb', line 17

def matches?(subject)
  valid = true
  valid &&= subject.respond_to?(@method_name)
  valid &&= subject.method(@method_name).arity == @number_of_args if valid && @number_of_args
  valid
end

#with(number_of_args) ⇒ Object



7
8
9
10
# File 'lib/bacon-expect/matchers/respond_to.rb', line 7

def with(number_of_args)
  @number_of_args = number_of_args
  self
end