Raise ArgumentError rather than warning when extra parameters passed to SelectorQuery

This commit is contained in:
Thomas Walpole 2018-02-01 14:02:39 -08:00
parent 5b31ac1031
commit 6ef251e728
4 changed files with 10 additions and 8 deletions

View File

@ -18,7 +18,7 @@ module Capybara
@locator = args.shift @locator = args.shift
@filter_block = filter_block @filter_block = filter_block
warn "Unused parameters passed to #{self.class.name} : #{args}" unless args.empty? raise ArgumentError, "Unused parameters passed to #{self.class.name} : #{args}" unless args.empty?
@expression = @selector.call(@locator, @options.merge(enable_aria_label: session_options.enable_aria_label)) @expression = @selector.call(@locator, @options.merge(enable_aria_label: session_options.enable_aria_label))

View File

@ -26,9 +26,10 @@ Capybara::SpecHelper.spec '#first' do
expect(@session.first(@xpath).value).to eq('John') expect(@session.first(@xpath).value).to eq('John')
end end
it "should warn when unused parameters are passed" do it "should raise when unused parameters are passed" do
expect_any_instance_of(Kernel).to receive(:warn).with(/Unused parameters passed.*unused text/) expect {
@session.first(:css, 'h1', 'unused text') @session.first(:css, 'h1', 'unused text')
}.to raise_error ArgumentError, /Unused parameters passed.*unused text/
end end
context "with css selectors" do context "with css selectors" do

View File

@ -72,9 +72,10 @@ Capybara::SpecHelper.spec '#has_selector?' do
expect(@session).not_to have_selector("//p//a", text: /Red$/) expect(@session).not_to have_selector("//p//a", text: /Red$/)
end end
it "should warn when extra parameters passed" do it "should raise when extra parameters passed" do
expect_any_instance_of(Kernel).to receive(:warn).with(/extra/) expect {
expect(@session).to have_selector(:css, "p a#foo", 'extra') expect(@session).to have_selector(:css, "p a#foo", 'extra')
}.to raise_error ArgumentError, /extra/
end end
end end

View File

@ -104,7 +104,7 @@ RSpec.describe Capybara do
Capybara.default_host = old_default Capybara.default_host = old_default
end end
it "should warn if not a valid URL" do it "should raise if not a valid URL" do
expect { Capybara.default_host = "www.example.com" }.to raise_error(ArgumentError, /Capybara\.default_host should be set to a url/) expect { Capybara.default_host = "www.example.com" }.to raise_error(ArgumentError, /Capybara\.default_host should be set to a url/)
end end