2016-03-07 16:52:19 -08:00
# frozen_string_literal: true
2014-02-16 20:13:58 +03:00
module Capybara
module Node
module DocumentMatchers
##
# Asserts that the page has the given title.
#
# @!macro title_query_params
# @overload $0(string, options = {})
# @param string [String] The string that title should include
# @overload $0(regexp, options = {})
# @param regexp [Regexp] The regexp that title should match to
2015-04-14 13:56:30 -07:00
# @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum time that Capybara will wait for title to eq/match given string/regexp argument
2014-02-16 20:13:58 +03:00
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
# @return [true]
#
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
##
# Asserts that the page doesn't have the given title.
#
# @macro title_query_params
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
# @return [true]
#
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
##
# Checks if the page has the given title.
#
# @macro title_query_params
# @return [Boolean]
#
def has_title? ( title , options = { } )
assert_title ( title , options )
rescue Capybara :: ExpectationNotMet
return false
end
##
# Checks if the page doesn't have the given title.
#
# @macro title_query_params
# @return [Boolean]
#
def has_no_title? ( title , options = { } )
assert_no_title ( title , options )
rescue Capybara :: ExpectationNotMet
return false
end
end
end
end