Class: FoundationApi::ShouldaMatcher::AttributeAliasMatcher
- Inherits:
-
Object
- Object
- FoundationApi::ShouldaMatcher::AttributeAliasMatcher
- Defined in:
- lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #for(source_attribute) ⇒ Object
-
#initialize(alias_name) ⇒ AttributeAliasMatcher
constructor
A new instance of AttributeAliasMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(alias_name) ⇒ AttributeAliasMatcher
Returns a new instance of AttributeAliasMatcher.
4 5 6 |
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 4 def initialize(alias_name) @expected_alias_name = alias_name.to_s end |
Instance Method Details
#description ⇒ Object
22 23 24 |
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 22 def description "have attribute alias #{@expected_alias_name}" end |
#failure_message ⇒ Object
14 15 16 |
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 14 def "Expected attribute alias #{@expected_alias_name} for #{@source_attribute || 'unspecified source attribute'}" end |
#for(source_attribute) ⇒ Object
26 27 28 29 |
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 26 def for(source_attribute) @source_attribute = source_attribute.to_s self end |
#matches?(subject) ⇒ Boolean
8 9 10 11 12 |
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 8 def matches?(subject) @klass = subject.class @klass.attribute_aliases.has_key?(@expected_alias_name) && (@source_attribute ? @klass.attribute_aliases[@expected_alias_name] == @source_attribute : true) end |
#negative_failure_message ⇒ Object
18 19 20 |
# File 'lib/foundation_api/shoulda_matcher/attribute_alias_matcher.rb', line 18 def "Didn't expect attribute alias #{@expected_alias_name} but got one anyway" end |