Module: Capybara::SessionMatchers

Included in:
Session
Defined in:
lib/capybara/session/matchers.rb

Instance Method Summary collapse

Instance Method Details

#assert_current_path(string, options = {}) ⇒ true #assert_current_path(regexp, options = {}) ⇒ true

Asserts that the page has the given path. By default this will compare against the path+query portion of the full url

Options Hash (options):

  • :wait (Numeric) — default: Capybara.default_max_wait_time

    Maximum time that Capybara will wait for the current path to eq/match given string/regexp argument

  • :url (Boolean) — default: false

    Whether the compare should be done against the full url

  • :only_path (Boolean) — default: false

    Whether the compare should be done against just the path protion of the url

Raises:



19
20
21
22
23
24
25
26
27
# File 'lib/capybara/session/matchers.rb', line 19

def assert_current_path(path, options={})
  query = Capybara::Queries::CurrentPathQuery.new(path, options)
  document.synchronize(query.wait) do
    unless query.resolves_for?(self)
      raise Capybara::ExpectationNotMet, query.failure_message
    end
  end
  return true
end

#assert_no_current_path(string, options = {}) ⇒ true #assert_no_current_path(regexp, options = {}) ⇒ true

Asserts that the page doesn't have the given path.

Options Hash (options):

  • :wait (Numeric) — default: Capybara.default_max_wait_time

    Maximum time that Capybara will wait for the current path to eq/match given string/regexp argument

  • :url (Boolean) — default: false

    Whether the compare should be done against the full url

  • :only_path (Boolean) — default: false

    Whether the compare should be done against just the path protion of the url

Raises:



36
37
38
39
40
41
42
43
44
# File 'lib/capybara/session/matchers.rb', line 36

def assert_no_current_path(path, options={})
  query = Capybara::Queries::CurrentPathQuery.new(path, options)
  document.synchronize(query.wait) do
    if query.resolves_for?(self)
      raise Capybara::ExpectationNotMet, query.negative_failure_message
    end
  end
  return true
end

#has_current_path?(string, options = {}) ⇒ Boolean #has_current_path?(regexp, options = {}) ⇒ Boolean

Checks if the page has the given path.

Options Hash (options):

  • :wait (Numeric) — default: Capybara.default_max_wait_time

    Maximum time that Capybara will wait for the current path to eq/match given string/regexp argument

  • :url (Boolean) — default: false

    Whether the compare should be done against the full url

  • :only_path (Boolean) — default: false

    Whether the compare should be done against just the path protion of the url



52
53
54
55
56
# File 'lib/capybara/session/matchers.rb', line 52

def has_current_path?(path, options={})
  assert_current_path(path, options)
rescue Capybara::ExpectationNotMet
  return false
end

#has_no_current_path?(string, options = {}) ⇒ Boolean #has_no_current_path?(regexp, options = {}) ⇒ Boolean

Checks if the page doesn't have the given path.

Options Hash (options):

  • :wait (Numeric) — default: Capybara.default_max_wait_time

    Maximum time that Capybara will wait for the current path to eq/match given string/regexp argument

  • :url (Boolean) — default: false

    Whether the compare should be done against the full url

  • :only_path (Boolean) — default: false

    Whether the compare should be done against just the path protion of the url



64
65
66
67
68
# File 'lib/capybara/session/matchers.rb', line 64

def has_no_current_path?(path, options={})
  assert_no_current_path(path, options)
rescue Capybara::ExpectationNotMet
  return false
end