Class: Capybara::RSpecMatchers::HaveSelector

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ HaveSelector

Returns a new instance of HaveSelector.



4
5
6
# File 'lib/capybara/rspec/matchers.rb', line 4

def initialize(*args)
  @args = args
end

Instance Method Details

#descriptionObject



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

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

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/capybara/rspec/matchers.rb', line 13

def does_not_match?(actual)
  @actual = wrap(actual)
  @actual.has_no_selector?(*@args)
end

#failure_message_for_shouldObject



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

def failure_message_for_should
  query.failure_message(:assert, @actual)
end

#failure_message_for_should_notObject



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

def failure_message_for_should_not
  query.negative_failure_message(:assert, @actual)
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/capybara/rspec/matchers.rb', line 8

def matches?(actual)
  @actual = wrap(actual)
  @actual.has_selector?(*@args)
end

#queryObject



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

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

#wrap(actual) ⇒ Object



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

def wrap(actual)
  if actual.respond_to?("has_selector?")
    actual
  else
    Capybara.string(actual.to_s)
  end
end