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, if passed a full url this will compare against the full url, if passed a path only the path+query portion will be compared, if passed a regexp the comparison will depend on the :url option

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)

    a customizable set of options

Options Hash (**options):

  • :url (Boolean) — default: true if `string` ia a full url, otherwise false

    Whether the compare should be done against the full current url or just the path

  • :ignore_query (Boolean) — default: false

    Whether the query portion of the current url/path should be ignored

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

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

Returns:

  • (true)

Raises:



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

def assert_current_path(path, **options)
  _verify_current_path(path, options) { |query| raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self) }
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. By default, if passed a full url this will compare against the full url, if passed a path only the path+query portion will be compared, if passed a regexp the comparison will depend on the :url option

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)

    a customizable set of options

Options Hash (**options):

  • :url (Boolean) — default: true if `string` ia a full url, otherwise false

    Whether the compare should be done against the full current url or just the path

  • :ignore_query (Boolean) — default: false

    Whether the query portion of the current url/path should be ignored

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

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

Returns:

  • (true)

Raises:



36
37
38
# File 'lib/capybara/session/matchers.rb', line 36

def assert_no_current_path(path, **options)
  _verify_current_path(path, options) { |query| raise Capybara::ExpectationNotMet, query.negative_failure_message if query.resolves_for?(self) }
end

#has_current_path?(string, **options) ⇒ Boolean #has_current_path?(regexp, **options) ⇒ Boolean

Checks if the page has the given path. By default, if passed a full url this will compare against the full url, if passed a path only the path+query portion will be compared, if passed a regexp the comparison will depend on the :url option

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)

    a customizable set of options

Options Hash (**options):

  • :url (Boolean) — default: true if `string` ia a full url, otherwise false

    Whether the compare should be done against the full current url or just the path

  • :ignore_query (Boolean) — default: false

    Whether the query portion of the current url/path should be ignored

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

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

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/capybara/session/matchers.rb', line 49

def has_current_path?(path, **options)
  assert_current_path(path, options)
rescue Capybara::ExpectationNotMet
  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. By default, if passed a full url this will compare against the full url, if passed a path only the path+query portion will be compared, if passed a regexp the comparison will depend on the :url option

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)

    a customizable set of options

Options Hash (**options):

  • :url (Boolean) — default: true if `string` ia a full url, otherwise false

    Whether the compare should be done against the full current url or just the path

  • :ignore_query (Boolean) — default: false

    Whether the query portion of the current url/path should be ignored

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

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

Returns:

  • (Boolean)


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
  false
end