Class: Dommy::Rails::RSpec::Matchers::HaveXPath

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

Instance Method Summary collapse

Constructor Details

#initialize(expression, text:, count:) ⇒ HaveXPath

Returns a new instance of HaveXPath.



163
164
165
166
167
# File 'lib/dommy/rails/rspec/matchers.rb', line 163

def initialize(expression, text:, count:)
  @expression = expression
  @text = text
  @count = count
end

Instance Method Details

#descriptionObject



178
179
180
# File 'lib/dommy/rails/rspec/matchers.rb', line 178

def description
  "have XPath #{@expression.inspect}"
end

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/dommy/rails/rspec/matchers.rb', line 174

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

#failure_messageObject



182
183
184
# File 'lib/dommy/rails/rspec/matchers.rb', line 182

def failure_message
  "expected to find XPath #{@expression.inspect}, found #{@matched.size}"
end

#failure_message_when_negatedObject



186
187
188
# File 'lib/dommy/rails/rspec/matchers.rb', line 186

def failure_message_when_negated
  "expected not to find XPath #{@expression.inspect}, found #{@matched.size}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


169
170
171
172
# File 'lib/dommy/rails/rspec/matchers.rb', line 169

def matches?(actual)
  @matched = Dommy::Rails::PageInspector.xpath_matches(MatchTarget.document(actual), @expression, text: @text)
  Dommy::Internal::DomMatching.count_matches?(@matched.size, @count)
end