Module: Capybara::Node::DocumentMatchers

Included in:
Document, Simple
Defined in:
lib/capybara/node/document_matchers.rb

Instance Method Summary collapse

Instance Method Details

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

Asserts that the page doesn’t have the given title.

Overloads:

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

    Parameters:

    • string (String)

      The string that title should include

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

    Parameters:

    • regexp (Regexp)

      The regexp that title 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 title to eq/match given string/regexp argument

Returns:

  • (true)

Raises:



34
35
36
37
38
39
40
41
42
# File 'lib/capybara/node/document_matchers.rb', line 34

def assert_no_title(title, options = {})
  query = Capybara::Queries::TitleQuery.new(title, options)
  synchronize(query.wait) do
    if query.resolves_for?(self)
      raise Capybara::ExpectationNotMet, query.negative_failure_message
    end
  end
  return true
end

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

Asserts that the page has the given title.

Overloads:

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

    Parameters:

    • string (String)

      The string that title should include

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

    Parameters:

    • regexp (Regexp)

      The regexp that title 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 title to eq/match given string/regexp argument

Returns:

  • (true)

Raises:



17
18
19
20
21
22
23
24
25
# File 'lib/capybara/node/document_matchers.rb', line 17

def assert_title(title, options = {})
  query = Capybara::Queries::TitleQuery.new(title, options)
  synchronize(query.wait) do
    unless query.resolves_for?(self)
      raise Capybara::ExpectationNotMet, query.failure_message
    end
  end
  return true
end

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

Checks if the page doesn’t have the given title.

Overloads:

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

    Parameters:

    • string (String)

      The string that title should include

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

    Parameters:

    • regexp (Regexp)

      The regexp that title 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 title to eq/match given string/regexp argument

Returns:

  • (Boolean)


62
63
64
65
66
# File 'lib/capybara/node/document_matchers.rb', line 62

def has_no_title?(title, options = {})
  assert_no_title(title, options)
rescue Capybara::ExpectationNotMet
  return false
end

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

Checks if the page has the given title.

Overloads:

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

    Parameters:

    • string (String)

      The string that title should include

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

    Parameters:

    • regexp (Regexp)

      The regexp that title 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 title to eq/match given string/regexp argument

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/capybara/node/document_matchers.rb', line 50

def has_title?(title, options = {})
  assert_title(title, options)
rescue Capybara::ExpectationNotMet
  return false
end