Class: RSpec::SleepingKingStudios::Matchers::Core::HaveAliasedMethodMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::SleepingKingStudios::Matchers::Core::HaveAliasedMethodMatcher
- Defined in:
- lib/rspec/sleeping_king_studios/matchers/core/have_aliased_method_matcher.rb
Overview
Prior to 2.7.0, this was named AliasMethodMatcher.
Matcher for testing whether an object aliases a specified method using the specified other method name.
Direct Known Subclasses
Constant Summary
Constants included from Description
Description::DEFAULT_EXPECTED_ITEMS
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
-
#as(aliased_name) ⇒ AliasMethodMatcher
Specifies the name of the new method.
- #description ⇒ Object
-
#failure_message ⇒ Object
Message for when the object does not match, but was expected to.
-
#initialize(original_name) ⇒ HaveAliasedMethodMatcher
constructor
A new instance of HaveAliasedMethodMatcher.
-
#matches?(actual) ⇒ Boolean
Tests the actual object to see if it matches the defined condition(s).
Methods inherited from BaseMatcher
#does_not_match?, #failure_message_when_negated
Constructor Details
#initialize(original_name) ⇒ HaveAliasedMethodMatcher
Returns a new instance of HaveAliasedMethodMatcher.
16 17 18 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_aliased_method_matcher.rb', line 16 def initialize(original_name) @original_name = original_name.intern end |
Instance Method Details
#as(aliased_name) ⇒ AliasMethodMatcher
Specifies the name of the new method.
25 26 27 28 29 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_aliased_method_matcher.rb', line 25 def as(aliased_name) @aliased_name = aliased_name self end |
#description ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_aliased_method_matcher.rb', line 32 def description str = "alias :#{original_name}" str += " as #{aliased_name.inspect}" if aliased_name str 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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_aliased_method_matcher.rb', line 41 def = "expected #{@actual.inspect} to alias :#{original_name}" += " as #{aliased_name.inspect}" if aliased_name if @errors[:does_not_respond_to_old_method] += ", but did not respond to :#{original_name}" return end if @errors[:does_not_respond_to_new_method] += ", but did not respond to :#{aliased_name}" return end if @errors[:does_not_alias_method] += ", but :#{original_name} and :#{aliased_name} are different "\ "methods" return end end |
#matches?(actual) ⇒ Boolean
Tests the actual object to see if it matches the defined condition(s). Invoked by RSpec expectations.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_aliased_method_matcher.rb', line 70 def matches?(actual) super @errors = {} if aliased_name.nil? raise ArgumentError.new('must specify a new method name') end responds_to_methods? && aliases_method? end |