Class: BaconExpect::Matcher::RespondTo
- Inherits:
-
Object
- Object
- BaconExpect::Matcher::RespondTo
- Defined in:
- lib/bacon-expect/matchers/respond_to.rb
Instance Method Summary collapse
- #arguments ⇒ Object (also: #argument)
- #fail!(subject, negated) ⇒ Object
-
#initialize(method_name) ⇒ RespondTo
constructor
A new instance of RespondTo.
- #matches?(subject) ⇒ Boolean
- #with(number_of_args) ⇒ Object
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
#arguments ⇒ Object 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
24 25 26 |
# File 'lib/bacon-expect/matchers/respond_to.rb', line 24 def fail!(subject, negated) raise FailedExpectation.new(FailMessageRenderer.(negated, subject, @method_name, @number_of_args)) end |
#matches?(subject) ⇒ 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 |