Class: FriendlyAttributes::Test::Matchers::HaveFriendlyAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_attributes/test/matchers.rb

Instance Method Summary collapse

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.extract_options!
  @through    = @options[:through]
  @attributes = attributes
end

Instance Method Details

#descriptionObject



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_messageObject



21
22
23
# File 'lib/friendly_attributes/test/matchers.rb', line 21

def failure_message
  "expected #{@actual.inspect} to have friendly attributes #{@attributes.inspect} of type #{@type}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (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_messageObject



25
26
27
# File 'lib/friendly_attributes/test/matchers.rb', line 25

def negative_failure_message
  "expected #{@actual.inspect} not to have friendly attributes #{@attributes.inspect}"
end