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



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

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



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

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



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

def failure_message_when_negated
  @failure_message_when_negated
end

Instance Method Details

#descriptionObject



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

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

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


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

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

#queryObject



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

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