Class: Dommy::RSpec::Matchers::HaveDomAttribute Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/rspec/matchers.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(name, value) ⇒ HaveDomAttribute

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HaveDomAttribute.



122
123
124
125
# File 'lib/dommy/rspec/matchers.rb', line 122

def initialize(name, value)
  @name = name.to_s
  @value = value
end

Instance Method Details

#descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



139
140
141
142
143
144
145
# File 'lib/dommy/rspec/matchers.rb', line 139

def description
  if unset?(@value)
    "have DOM attribute #{@name.inspect}"
  else
    "have DOM attribute #{@name.inspect} = #{@value.inspect}"
  end
end

#does_not_match?(element) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


135
136
137
# File 'lib/dommy/rspec/matchers.rb', line 135

def does_not_match?(element)
  !matches?(element)
end

#failure_messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



147
148
149
150
151
152
153
# File 'lib/dommy/rspec/matchers.rb', line 147

def failure_message
  if unset?(@value)
    "expected element to have attribute #{@name.inspect}, but it was missing"
  else
    "expected attribute #{@name.inspect} to equal #{@value.inspect}, got #{@actual.inspect}"
  end
end

#failure_message_when_negatedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



155
156
157
158
159
160
161
# File 'lib/dommy/rspec/matchers.rb', line 155

def failure_message_when_negated
  if unset?(@value)
    "expected element NOT to have attribute #{@name.inspect}, but it was present (#{@actual.inspect})"
  else
    "expected attribute #{@name.inspect} not to equal #{@value.inspect}"
  end
end

#matches?(element) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


127
128
129
130
131
132
133
# File 'lib/dommy/rspec/matchers.rb', line 127

def matches?(element)
  @element = element
  return false unless element.has_attribute?(@name)

  @actual = element.get_attribute(@name)
  unset?(@value) ? true : @actual.to_s == @value.to_s
end