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



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

def description
  "has #{selector_name}"
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
21
22
23
24
# File 'lib/capybara/rspec/matchers.rb', line 18

def failure_message_for_should
  if normalized.failure_message
    normalized.failure_message.call(@actual, normalized)
  else
    "expected #{selector_name} to return something"
  end
end

#failure_message_for_should_notObject



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

def failure_message_for_should_not
  "expected #{selector_name} not to return anything"
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

#normalizedObject



48
49
50
# File 'lib/capybara/rspec/matchers.rb', line 48

def normalized
  @normalized ||= Capybara::Selector.normalize(*@args)
end

#selector_nameObject



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

def selector_name
  name = "#{normalized.name} #{normalized.locator.inspect}"
  name << " with text #{normalized.options[:text].inspect}" if normalized.options[:text]
  name
end

#wrap(actual) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/capybara/rspec/matchers.rb', line 40

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