Class: MotionSpec::Matcher::RespondTo

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-spec/matcher/respond_to.rb

Instance Method Summary collapse

Constructor Details

#initialize(method_name) ⇒ RespondTo

Returns a new instance of RespondTo.



5
6
7
# File 'lib/motion-spec/matcher/respond_to.rb', line 5

def initialize(method_name)
  @method_name = method_name
end

Instance Method Details

#argumentsObject Also known as: argument



14
15
16
# File 'lib/motion-spec/matcher/respond_to.rb', line 14

def arguments
  self
end

#fail!(subject, negated) ⇒ Object

Raises:



31
32
33
34
35
36
37
# File 'lib/motion-spec/matcher/respond_to.rb', line 31

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)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/motion-spec/matcher/respond_to.rb', line 19

def matches?(subject)
  valid = true

  valid &&= subject.respond_to?(@method_name)

  if valid && @number_of_args
    valid &&= subject.method(@method_name).arity == @number_of_args
  end

  valid
end

#with(number_of_args) ⇒ Object



9
10
11
12
# File 'lib/motion-spec/matcher/respond_to.rb', line 9

def with(number_of_args)
  @number_of_args = number_of_args
  self
end