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

Overloads:

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

    Parameters:

    • string (String)

      The string that the current ‘path’ should equal

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

    Parameters:

    • regexp (Regexp)

      The regexp that the current ‘path’ should match to

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

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

Returns:

  • (true)

Raises:



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

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.

Overloads:

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

    Parameters:

    • string (String)

      The string that the current ‘path’ should equal

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

    Parameters:

    • regexp (Regexp)

      The regexp that the current ‘path’ should match to

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

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

Returns:

  • (true)

Raises:



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

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.

Overloads:

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

    Parameters:

    • string (String)

      The string that the current ‘path’ should equal

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

    Parameters:

    • regexp (Regexp)

      The regexp that the current ‘path’ should match to

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

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

Returns:

  • (Boolean)


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

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.

Overloads:

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

    Parameters:

    • string (String)

      The string that the current ‘path’ should equal

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

    Parameters:

    • regexp (Regexp)

      The regexp that the current ‘path’ should match to

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

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

Returns:

  • (Boolean)


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

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