Class: RSpec::SleepingKingStudios::Matchers::Core::AliasMethodMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::SleepingKingStudios::Matchers::Core::AliasMethodMatcher
- Defined in:
- lib/rspec/sleeping_king_studios/matchers/core/alias_method_matcher.rb
Overview
Matcher for testing whether an object aliases a specified method using the specified other method name.
Constant Summary
Constants included from Description
Description::DEFAULT_EXPECTED_ITEMS
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
-
#as(new_method_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(expected) ⇒ AliasMethodMatcher
constructor
A new instance of AliasMethodMatcher.
-
#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(expected) ⇒ AliasMethodMatcher
Returns a new instance of AliasMethodMatcher.
14 15 16 17 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/alias_method_matcher.rb', line 14 def initialize expected @old_method_name = @expected = expected.intern @errors = {} end |
Instance Method Details
#as(new_method_name) ⇒ AliasMethodMatcher
Specifies the name of the new method.
24 25 26 27 28 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/alias_method_matcher.rb', line 24 def as new_method_name @new_method_name = new_method_name self end |
#description ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/alias_method_matcher.rb', line 31 def description str = "alias :#{old_method_name}" str << " as #{new_method_name.inspect}" if new_method_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.
40 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 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/alias_method_matcher.rb', line 40 def = "expected #{@actual.inspect} to alias :#{old_method_name}" << " as #{new_method_name.inspect}" if new_method_name if @errors[:does_not_respond_to_old_method] << ", but did not respond to :#{old_method_name}" return end # if if @errors[:does_not_respond_to_new_method] << ", but did not respond to :#{new_method_name}" return end # if if @errors[:does_not_alias_method] << ", but :#{old_method_name} and :#{new_method_name} are different "\ "methods" return end # if end |
#matches?(actual) ⇒ Boolean
Tests the actual object to see if it matches the defined condition(s). Invoked by RSpec expectations.
69 70 71 72 73 74 75 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/alias_method_matcher.rb', line 69 def matches? actual super raise ArgumentError.new('must specify a new method name') if new_method_name.nil? responds_to_methods? && aliases_method? end |