Class: RSpec::SleepingKingStudios::Matchers::BuiltIn::RespondToMatcher
- Inherits:
-
Matchers::BuiltIn::RespondTo
- Object
- Matchers::BuiltIn::RespondTo
- RSpec::SleepingKingStudios::Matchers::BuiltIn::RespondToMatcher
- Includes:
- Shared::MatchParameters
- Defined in:
- lib/rspec/sleeping_king_studios/matchers/built_in/respond_to_matcher.rb
Overview
Extensions to the built-in RSpec #respond_to matcher.
Instance Method Summary collapse
- #description ⇒ Object
-
#failure_message ⇒ Object
Message for when the object does not match, but was expected to.
-
#failure_message_when_negated ⇒ Object
Message for when the object matches, but was expected not to.
-
#initialize(*expected) ⇒ RespondToMatcher
constructor
A new instance of RespondToMatcher.
Methods included from Shared::MatchParameters
#argument, #with, #with_a_block, #with_arbitrary_keywords, #with_keywords, #with_unlimited_arguments
Constructor Details
#initialize(*expected) ⇒ RespondToMatcher
Returns a new instance of RespondToMatcher.
12 13 14 15 16 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/respond_to_matcher.rb', line 12 def initialize *expected @include_all = [true, false].include?(expected.last) ? expected.pop : false super(*expected) end |
Instance Method Details
#description ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/respond_to_matcher.rb', line 19 def description = "respond to #{pp_names}" if method_signature_expectation? << ' ' << method_signature_expectation.description end # if end |
#failure_message ⇒ Object
Message for when the object does not match, but was expected to. Make sure to always call #matches? first to set up the matcher state.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/respond_to_matcher.rb', line 30 def method_names = @failing_method_names || [] = [] method_names.map do |method_name| = "expected #{@actual.inspect} to respond to #{method_name.inspect}" reasons = @failing_method_reasons[method_name] || {} if reasons.key?(:does_not_respond_to_method) << ", but #{@actual.inspect} does not respond to #{method_name.inspect}" elsif reasons.key?(:is_not_a_method) << ", but #{@actual.inspect} does not define a method at #{method_name.inspect}" else errors = @failing_method_reasons[method_name] # TODO: Replace this with ", but received arguments did not match "\ # " method signature:" << " with arguments:\n" << format_errors(errors) end # if-elsif-else << end # method .join "\n" end |
#failure_message_when_negated ⇒ Object
Message for when the object matches, but was expected not to. Make sure to always call #matches? first to set up the matcher state.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/respond_to_matcher.rb', line 57 def @failing_method_names ||= [] methods, = @failing_method_names, [] methods.map do |method| = "expected #{@actual.inspect} not to respond to #{method.inspect}" if method_signature_expectation? << ' ' << method_signature_expectation.description end # if << end # method .join "\n" end |