2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2014-02-16 12:13:58 -05:00
|
|
|
Capybara::SpecHelper.spec '#assert_title' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
end
|
|
|
|
|
2017-05-31 13:29:44 -04:00
|
|
|
it "should not raise if the page's title contains the given string" do
|
|
|
|
expect do
|
|
|
|
@session.assert_title('js')
|
|
|
|
end.not_to raise_error
|
2014-02-16 12:13:58 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should not raise when given an empty string' do
|
2017-05-31 13:29:44 -04:00
|
|
|
expect do
|
|
|
|
@session.assert_title('')
|
|
|
|
end.not_to raise_error
|
2014-02-16 12:13:58 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should allow regexp matches' do
|
2017-05-31 13:29:44 -04:00
|
|
|
expect do
|
|
|
|
@session.assert_title(/w[a-z]{3}_js/)
|
|
|
|
end.not_to raise_error
|
|
|
|
|
2014-02-16 12:13:58 -05:00
|
|
|
expect do
|
|
|
|
@session.assert_title(/w[a-z]{10}_js/)
|
|
|
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to match /w[a-z]{10}_js/')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should wait for title', requires: [:js] do
|
|
|
|
@session.click_link('Change title')
|
2017-05-31 13:29:44 -04:00
|
|
|
expect do
|
2018-07-10 17:18:39 -04:00
|
|
|
@session.assert_title('changed title', wait: 3)
|
2017-05-31 13:29:44 -04:00
|
|
|
end.not_to raise_error
|
2014-02-16 12:13:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise error if the title doesn't contain the given string" do
|
|
|
|
expect do
|
|
|
|
@session.assert_title('monkey')
|
|
|
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to include "monkey"')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should not normalize given title' do
|
2018-03-05 17:57:33 -05:00
|
|
|
@session.visit('/with_js')
|
|
|
|
expect { @session.assert_title(' with_js ') }.to raise_error(Capybara::ExpectationNotMet)
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should match correctly normalized title' do
|
2018-03-05 17:57:33 -05:00
|
|
|
uri = Addressable::URI.parse('/with_title')
|
|
|
|
uri.query_values = { title: ' with space title ' }
|
|
|
|
@session.visit(uri.to_s)
|
|
|
|
@session.assert_title(' with space title')
|
|
|
|
expect { @session.assert_title('with space title') }.to raise_error(Capybara::ExpectationNotMet)
|
2014-02-16 12:13:58 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should not normalize given title in error message' do
|
2014-02-16 12:13:58 -05:00
|
|
|
expect do
|
|
|
|
@session.assert_title(2)
|
|
|
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to include "2"')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Capybara::SpecHelper.spec '#assert_no_title' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should raise error if the title contains the given string' do
|
2014-02-16 12:13:58 -05:00
|
|
|
expect do
|
|
|
|
@session.assert_no_title('with_j')
|
|
|
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" not to include "with_j"')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should allow regexp matches' do
|
2014-02-16 12:13:58 -05:00
|
|
|
expect do
|
|
|
|
@session.assert_no_title(/w[a-z]{3}_js/)
|
|
|
|
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" not to match /w[a-z]{3}_js/')
|
|
|
|
@session.assert_no_title(/monkey/)
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should wait for title to disappear', requires: [:js] do
|
|
|
|
@session.click_link('Change title')
|
2017-05-31 13:29:44 -04:00
|
|
|
expect do
|
|
|
|
@session.assert_no_title('with_js', wait: 3)
|
|
|
|
end.not_to raise_error
|
2014-02-16 12:13:58 -05:00
|
|
|
end
|
|
|
|
|
2017-05-31 13:29:44 -04:00
|
|
|
it "should not raise if the title doesn't contain the given string" do
|
|
|
|
expect do
|
|
|
|
@session.assert_no_title('monkey')
|
|
|
|
end.not_to raise_error
|
2014-02-16 12:13:58 -05:00
|
|
|
end
|
|
|
|
end
|