1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/lib/capybara/spec/session/assert_current_path_spec.rb

74 lines
2.4 KiB
Ruby
Raw Normal View History

2016-03-07 19:52:19 -05:00
# frozen_string_literal: true
2018-02-28 19:11:41 -05:00
2015-08-24 01:14:48 -04:00
Capybara::SpecHelper.spec '#assert_current_path' do
before do
@session.visit('/with_js')
end
it "should not raise if the page has the given current path" do
2018-02-28 19:11:41 -05:00
expect { @session.assert_current_path('/with_js') }.not_to raise_error
2015-08-24 01:14:48 -04:00
end
it "should allow regexp matches" do
expect { @session.assert_current_path(/w[a-z]{3}_js/) }.not_to raise_error
end
2016-10-04 14:10:29 -04:00
it "should wait for current_path", requires: [:js] do
2015-08-24 01:14:48 -04:00
@session.click_link("Change page")
expect { @session.assert_current_path("/with_html") }.not_to raise_error
end
it "should raise if the page has not the given current_path" do
2018-02-28 19:11:41 -05:00
expect { @session.assert_current_path('/with_html') }.to raise_error(Capybara::ExpectationNotMet, 'expected "/with_js" to equal "/with_html"')
2015-08-24 01:14:48 -04:00
end
it "should check query options" do
@session.visit('/with_js?test=test')
2018-02-28 19:11:41 -05:00
expect { @session.assert_current_path('/with_js?test=test') }.not_to raise_error
2015-08-24 01:14:48 -04:00
end
it "should compare the full url" do
2018-02-28 19:11:41 -05:00
expect { @session.assert_current_path(%r{\Ahttp://[^/]*/with_js\Z}, url: true) }.not_to raise_error
2015-08-24 01:14:48 -04:00
end
it "should ignore the query" do
@session.visit('/with_js?test=test')
2018-02-28 19:11:41 -05:00
expect { @session.assert_current_path('/with_js', ignore_query: true) }.not_to raise_error
2015-08-24 01:14:48 -04:00
end
it "should not cause an exception when current_url is nil" do
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
2018-02-28 19:11:41 -05:00
expect { @session.assert_current_path(nil) }.not_to raise_error
end
2015-08-24 01:14:48 -04:00
end
Capybara::SpecHelper.spec '#assert_no_current_path?' do
2015-08-24 01:14:48 -04:00
before do
@session.visit('/with_js')
end
it "should raise if the page has the given current_path" do
2018-02-28 19:11:41 -05:00
expect { @session.assert_no_current_path('/with_js') }.to raise_error(Capybara::ExpectationNotMet)
2015-08-24 01:14:48 -04:00
end
it "should allow regexp matches" do
2018-02-28 19:11:41 -05:00
expect { @session.assert_no_current_path(/monkey/) }.not_to raise_error
2015-08-24 01:14:48 -04:00
end
2016-10-04 14:10:29 -04:00
it "should wait for current_path to disappear", requires: [:js] do
2015-08-24 01:14:48 -04:00
@session.click_link("Change page")
2018-02-28 19:11:41 -05:00
expect { @session.assert_no_current_path('/with_js') }.not_to raise_error
2015-08-24 01:14:48 -04:00
end
it "should not raise if the page has not the given current_path" do
2018-02-28 19:11:41 -05:00
expect { @session.assert_no_current_path('/with_html') }.not_to raise_error
2015-08-24 01:14:48 -04:00
end
it "should not cause an exception when current_url is nil" do
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
2018-02-28 19:11:41 -05:00
expect { @session.assert_no_current_path('/with_html') }.not_to raise_error
end
2015-08-24 01:14:48 -04:00
end