Class: Capybara::RSpecMatchers::HaveSelector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#wrap

Constructor Details

#initialize(*args) ⇒ HaveSelector

Returns a new instance of HaveSelector.



18
19
20
# File 'lib/capybara/rspec/matchers.rb', line 18

def initialize(*args)
  @args = args
end

Instance Attribute Details

#failure_messageObject (readonly) Also known as: failure_message_for_should

Returns the value of attribute failure_message.



16
17
18
# File 'lib/capybara/rspec/matchers.rb', line 16

def failure_message
  @failure_message
end

#failure_message_when_negatedObject (readonly) Also known as: failure_message_for_should_not

Returns the value of attribute failure_message_when_negated.



16
17
18
# File 'lib/capybara/rspec/matchers.rb', line 16

def failure_message_when_negated
  @failure_message_when_negated
end

Instance Method Details

#descriptionObject



36
37
38
# File 'lib/capybara/rspec/matchers.rb', line 36

def description
  "have #{query.description}"
end

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/capybara/rspec/matchers.rb', line 29

def does_not_match?(actual)
  wrap(actual).assert_no_selector(*@args)
rescue Capybara::ExpectationNotMet => e
  @failure_message_when_negated = e.message
  return false
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/capybara/rspec/matchers.rb', line 22

def matches?(actual)
  wrap(actual).assert_selector(*@args)
rescue Capybara::ExpectationNotMet => e
  @failure_message = e.message
  return false
end

#queryObject



40
41
42
# File 'lib/capybara/rspec/matchers.rb', line 40

def query
  @query ||= Capybara::Query.new(*@args)
end