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 '#has_current_path?' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be true if the page has the given current path" do
|
|
|
|
expect(@session).to have_current_path('/with_js')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow regexp matches" do
|
|
|
|
expect(@session).to have_current_path(/w[a-z]{3}_js/)
|
|
|
|
expect(@session).not_to have_current_path(/monkey/)
|
|
|
|
end
|
|
|
|
|
2017-11-28 01:35:04 -05:00
|
|
|
it "should not raise an error when non-http" do
|
|
|
|
@session.reset_session!
|
|
|
|
expect(@session.has_current_path?(/monkey/)).to eq false
|
|
|
|
expect(@session.has_current_path?("/with_js")).to eq false
|
|
|
|
end
|
|
|
|
|
2015-12-28 12:34:26 -05:00
|
|
|
it "should handle non-escaped query options" do
|
|
|
|
@session.click_link("Non-escaped query options")
|
|
|
|
expect(@session).to have_current_path("/with_html?options[]=things")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should handle escaped query options" do
|
|
|
|
@session.click_link("Escaped query options")
|
|
|
|
expect(@session).to have_current_path("/with_html?options%5B%5D=things")
|
|
|
|
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")
|
2017-05-10 13:34:53 -04:00
|
|
|
expect(@session).to have_current_path("/with_html", wait: 3)
|
2015-08-24 01:14:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be false if the page has not the given current_path" do
|
|
|
|
expect(@session).not_to have_current_path('/with_html')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should check query options" do
|
|
|
|
@session.visit('/with_js?test=test')
|
|
|
|
expect(@session).to have_current_path('/with_js?test=test')
|
|
|
|
end
|
|
|
|
|
2017-10-04 20:54:04 -04:00
|
|
|
it "should compare the full url if url: true is used" do
|
2015-08-24 01:14:48 -04:00
|
|
|
expect(@session).to have_current_path(%r{\Ahttp://[^/]*/with_js\Z}, url: true)
|
2017-10-04 20:54:04 -04:00
|
|
|
domain_port = if @session.respond_to?(:server) && @session.server
|
|
|
|
"#{@session.server.host}:#{@session.server.port}"
|
|
|
|
else
|
|
|
|
"www.example.com"
|
|
|
|
end
|
|
|
|
expect(@session).to have_current_path("http://#{domain_port}/with_js", url: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not compare the full url if url: true is not passed" do
|
|
|
|
expect(@session).to have_current_path(%r{^/with_js\Z})
|
|
|
|
expect(@session).to have_current_path('/with_js')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not compare the full url if url: false is passed" do
|
|
|
|
expect(@session).to have_current_path(%r{^/with_js\Z}, url: false)
|
|
|
|
expect(@session).to have_current_path('/with_js', url: false)
|
2015-08-24 01:14:48 -04:00
|
|
|
end
|
|
|
|
|
2017-06-20 18:14:32 -04:00
|
|
|
it "should default to full url if value is a url" do
|
|
|
|
url = @session.current_url
|
2017-11-13 16:04:47 -05:00
|
|
|
expect(url).to match(/with_js$/)
|
2017-06-20 18:14:32 -04:00
|
|
|
expect(@session).to have_current_path(url)
|
|
|
|
expect(@session).not_to have_current_path("http://www.not_example.com/with_js")
|
|
|
|
end
|
|
|
|
|
2015-08-24 01:14:48 -04:00
|
|
|
it "should ignore the query" do
|
|
|
|
@session.visit('/with_js?test=test')
|
|
|
|
expect(@session).to have_current_path('/with_js?test=test')
|
2017-06-20 18:14:32 -04:00
|
|
|
expect(@session).to have_current_path('/with_js', ignore_query: true)
|
|
|
|
uri = ::Addressable::URI.parse(@session.current_url)
|
|
|
|
uri.query = nil
|
|
|
|
expect(@session).to have_current_path(uri.to_s, ignore_query: true)
|
2015-08-24 01:14:48 -04:00
|
|
|
end
|
|
|
|
|
2017-01-12 20:55:26 -05:00
|
|
|
it "should not raise an exception if the current_url is nil" do
|
|
|
|
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
|
|
|
|
2017-10-08 17:56:17 -04:00
|
|
|
# Without ignore_query option
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2017-01-12 20:55:26 -05:00
|
|
|
expect(@session).to have_current_path(nil)
|
2018-02-28 19:11:41 -05:00
|
|
|
end.not_to raise_exception
|
2017-01-12 20:55:26 -05:00
|
|
|
|
2017-06-20 18:14:32 -04:00
|
|
|
# With ignore_query option
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2017-06-20 18:14:32 -04:00
|
|
|
expect(@session).to have_current_path(nil, ignore_query: true)
|
2018-02-28 19:11:41 -05:00
|
|
|
end.not_to raise_exception
|
2017-01-12 20:55:26 -05:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara::SpecHelper.spec '#has_no_current_path?' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be false if the page has the given current_path" do
|
|
|
|
expect(@session).not_to have_no_current_path('/with_js')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow regexp matches" do
|
|
|
|
expect(@session).not_to have_no_current_path(/w[a-z]{3}_js/)
|
|
|
|
expect(@session).to have_no_current_path(/monkey/)
|
|
|
|
end
|
|
|
|
|
2016-10-04 14:10:29 -04:00
|
|
|
it "should wait for current_path to disappear", requires: [:js] do
|
2017-05-10 15:27:53 -04:00
|
|
|
Capybara.using_wait_time(3) do
|
|
|
|
@session.click_link("Change page")
|
|
|
|
expect(@session).to have_no_current_path('/with_js')
|
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be true if the page has not the given current_path" do
|
|
|
|
expect(@session).to have_no_current_path('/with_html')
|
|
|
|
end
|
2017-01-12 20:55:26 -05:00
|
|
|
|
|
|
|
it "should not raise an exception if the current_url is nil" do
|
|
|
|
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
|
|
|
|
2017-10-08 17:56:17 -04:00
|
|
|
# Without ignore_query option
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2017-01-12 20:55:26 -05:00
|
|
|
expect(@session).not_to have_current_path('/with_js')
|
2018-02-28 19:11:41 -05:00
|
|
|
end. not_to raise_exception
|
2017-01-12 20:55:26 -05:00
|
|
|
|
2017-06-20 18:14:32 -04:00
|
|
|
# With ignore_query option
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2017-06-20 18:14:32 -04:00
|
|
|
expect(@session).not_to have_current_path('/with_js', ignore_query: true)
|
2018-02-28 19:11:41 -05:00
|
|
|
end. not_to raise_exception
|
2017-01-12 20:55:26 -05:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
end
|