Class: FriendlyAttributes::Test::Matchers::HaveFriendlyAttribute
- Inherits:
-
Object
- Object
- FriendlyAttributes::Test::Matchers::HaveFriendlyAttribute
- Defined in:
- lib/friendly_attributes/test/matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(example, type, *attributes) ⇒ HaveFriendlyAttribute
constructor
A new instance of HaveFriendlyAttribute.
- #matches?(actual) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(example, type, *attributes) ⇒ HaveFriendlyAttribute
Returns a new instance of HaveFriendlyAttribute.
5 6 7 8 9 10 11 |
# File 'lib/friendly_attributes/test/matchers.rb', line 5 def initialize(example, type, *attributes) @example = example @type = type @options = attributes. @through = @options[:through] @attributes = attributes end |
Instance Method Details
#description ⇒ Object
29 30 31 |
# File 'lib/friendly_attributes/test/matchers.rb', line 29 def description "have [#{@actual}] friendly_attributes of type #{@type} => #{@attributes.inspect}" end |
#failure_message ⇒ Object
21 22 23 |
# File 'lib/friendly_attributes/test/matchers.rb', line 21 def "expected #{@actual.inspect} to have friendly attributes #{@attributes.inspect} of type #{@type}" end |
#matches?(actual) ⇒ Boolean
13 14 15 16 17 18 19 |
# File 'lib/friendly_attributes/test/matchers.rb', line 13 def matches?(actual) @actual = Class === actual ? actual : actual.class result = @actual.ancestors.include?(FriendlyAttributes) && @attributes.all? { |attr| @through.attributes.include?(attr) && @through.attributes[attr].type == @type } end |
#negative_failure_message ⇒ Object
25 26 27 |
# File 'lib/friendly_attributes/test/matchers.rb', line 25 def "expected #{@actual.inspect} not to have friendly attributes #{@attributes.inspect}" end |