remove deprecated only_path option
This commit is contained in:
parent
d5a855ac0a
commit
d2670e3315
|
@ -8,12 +8,10 @@ module Capybara
|
||||||
def initialize(expected_path, **options)
|
def initialize(expected_path, **options)
|
||||||
super(options)
|
super(options)
|
||||||
@expected_path = expected_path
|
@expected_path = expected_path
|
||||||
warn "DEPRECATED: The :only_path option is deprecated in favor of the :ignore_query option" if options.has_key?(:only_path)
|
|
||||||
|
|
||||||
@options = {
|
@options = {
|
||||||
url: !@expected_path.is_a?(Regexp) && !::Addressable::URI.parse(@expected_path || "").hostname.nil?,
|
url: !@expected_path.is_a?(Regexp) && !::Addressable::URI.parse(@expected_path || "").hostname.nil?,
|
||||||
only_path: false,
|
ignore_query: false
|
||||||
ignore_query: false }.merge(options)
|
}.merge(options)
|
||||||
assert_valid_keys
|
assert_valid_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,13 +20,9 @@ module Capybara
|
||||||
uri.query = nil if uri && options[:ignore_query]
|
uri.query = nil if uri && options[:ignore_query]
|
||||||
@actual_path = if options[:url]
|
@actual_path = if options[:url]
|
||||||
uri.to_s
|
uri.to_s
|
||||||
else
|
|
||||||
if options[:only_path]
|
|
||||||
uri && uri.path
|
|
||||||
else
|
else
|
||||||
uri && uri.request_uri
|
uri && uri.request_uri
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if @expected_path.is_a? Regexp
|
if @expected_path.is_a? Regexp
|
||||||
@actual_path.to_s.match(@expected_path)
|
@actual_path.to_s.match(@expected_path)
|
||||||
|
@ -53,15 +47,9 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_keys
|
def valid_keys
|
||||||
[:wait, :url, :only_path, :ignore_query]
|
[:wait, :url, :ignore_query]
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_valid_keys
|
|
||||||
super
|
|
||||||
if options[:url] && options[:only_path]
|
|
||||||
raise ArgumentError, "the :url and :only_path options cannot both be true"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ Capybara::SpecHelper.spec '#assert_current_path' do
|
||||||
|
|
||||||
it "should ignore the query" do
|
it "should ignore the query" do
|
||||||
@session.visit('/with_js?test=test')
|
@session.visit('/with_js?test=test')
|
||||||
expect{@session.assert_current_path('/with_js', only_path: true)}.not_to raise_error
|
expect{@session.assert_current_path('/with_js', ignore_query: true)}.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not cause an exception when current_url is nil" do
|
it "should not cause an exception when current_url is nil" do
|
||||||
|
|
|
@ -73,32 +73,20 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
||||||
it "should ignore the query" do
|
it "should ignore the query" do
|
||||||
@session.visit('/with_js?test=test')
|
@session.visit('/with_js?test=test')
|
||||||
expect(@session).to have_current_path('/with_js?test=test')
|
expect(@session).to have_current_path('/with_js?test=test')
|
||||||
expect(@session).to have_current_path('/with_js', only_path: true)
|
|
||||||
expect(@session).to have_current_path('/with_js', ignore_query: true)
|
expect(@session).to have_current_path('/with_js', ignore_query: true)
|
||||||
uri = ::Addressable::URI.parse(@session.current_url)
|
uri = ::Addressable::URI.parse(@session.current_url)
|
||||||
uri.query = nil
|
uri.query = nil
|
||||||
expect(@session).to have_current_path(uri.to_s, ignore_query: true)
|
expect(@session).to have_current_path(uri.to_s, ignore_query: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not allow url and only_path at the same time" do
|
|
||||||
expect {
|
|
||||||
expect(@session).to have_current_path('/with_js', url: true, only_path: true)
|
|
||||||
}.to raise_error ArgumentError
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should not raise an exception if the current_url is nil" do
|
it "should not raise an exception if the current_url is nil" do
|
||||||
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
||||||
|
|
||||||
# Without only_path option
|
# Without ignore_query option
|
||||||
expect {
|
expect {
|
||||||
expect(@session).to have_current_path(nil)
|
expect(@session).to have_current_path(nil)
|
||||||
}.not_to raise_exception
|
}.not_to raise_exception
|
||||||
|
|
||||||
# With only_path option
|
|
||||||
expect {
|
|
||||||
expect(@session).to have_current_path(nil, only_path: true)
|
|
||||||
}.not_to raise_exception
|
|
||||||
|
|
||||||
# With ignore_query option
|
# With ignore_query option
|
||||||
expect {
|
expect {
|
||||||
expect(@session).to have_current_path(nil, ignore_query: true)
|
expect(@session).to have_current_path(nil, ignore_query: true)
|
||||||
|
@ -134,16 +122,11 @@ Capybara::SpecHelper.spec '#has_no_current_path?' do
|
||||||
it "should not raise an exception if the current_url is nil" do
|
it "should not raise an exception if the current_url is nil" do
|
||||||
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
||||||
|
|
||||||
# Without only_path option
|
# Without ignore_query option
|
||||||
expect {
|
expect {
|
||||||
expect(@session).not_to have_current_path('/with_js')
|
expect(@session).not_to have_current_path('/with_js')
|
||||||
}. not_to raise_exception
|
}. not_to raise_exception
|
||||||
|
|
||||||
# With only_path option
|
|
||||||
expect {
|
|
||||||
expect(@session).not_to have_current_path('/with_js', only_path: true)
|
|
||||||
}. not_to raise_exception
|
|
||||||
|
|
||||||
# With ignore_query option
|
# With ignore_query option
|
||||||
expect {
|
expect {
|
||||||
expect(@session).not_to have_current_path('/with_js', ignore_query: true)
|
expect(@session).not_to have_current_path('/with_js', ignore_query: true)
|
||||||
|
|
Loading…
Reference in New Issue