mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Raise error when nonsensical option given to match
This commit is contained in:
parent
ab8f723349
commit
b0280624f9
2 changed files with 17 additions and 7 deletions
|
@ -3,6 +3,7 @@ module Capybara
|
|||
attr_accessor :selector, :locator, :options, :expression, :find, :negative
|
||||
|
||||
VALID_KEYS = [:text, :visible, :between, :count, :maximum, :minimum, :exact, :match]
|
||||
VALID_MATCH = [:first, :smart, :prefer_exact, :one]
|
||||
|
||||
def initialize(*args)
|
||||
@options = if args.last.is_a?(Hash) then args.pop.dup else {} end
|
||||
|
@ -111,6 +112,9 @@ module Capybara
|
|||
valid_names = valid_keys.map(&:inspect).join(", ")
|
||||
raise ArgumentError, "invalid keys #{invalid_names}, should be one of #{valid_names}"
|
||||
end
|
||||
unless VALID_MATCH.include?(match)
|
||||
raise ArgumentError, "invalid option #{match.inspect} for :match, should be one of #{VALID_MATCH.map(&:inspect).join(", ")}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ Capybara::SpecHelper.spec '#find' do
|
|||
@session.find(:css, 'h1').text.should == 'This is a test'
|
||||
@session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
|
||||
end
|
||||
|
||||
|
||||
it "should support pseudo selectors" do
|
||||
@session.find(:css, 'input:disabled').value.should == 'This is disabled'
|
||||
end
|
||||
|
@ -157,18 +157,18 @@ Capybara::SpecHelper.spec '#find' do
|
|||
end
|
||||
it "raises an error if there is no match" do
|
||||
expect do
|
||||
@session.find(:css, ".does-not-exist", :match => :any)
|
||||
@session.find(:css, ".does-not-exist", :match => :one)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "when set to `any`" do
|
||||
context "when set to `first`" do
|
||||
it "returns the first matched element" do
|
||||
@session.find(:css, ".multiple", :match => :any).text.should == "multiple one"
|
||||
@session.find(:css, ".multiple", :match => :first).text.should == "multiple one"
|
||||
end
|
||||
it "raises an error if there is no match" do
|
||||
expect do
|
||||
@session.find(:css, ".does-not-exist", :match => :any)
|
||||
@session.find(:css, ".does-not-exist", :match => :first)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
@ -285,9 +285,15 @@ Capybara::SpecHelper.spec '#find' do
|
|||
expect do
|
||||
@session.find(:css, ".multiple")
|
||||
end.to raise_error(Capybara::Ambiguous)
|
||||
Capybara.match = :any
|
||||
Capybara.match = :first
|
||||
@session.find(:css, ".multiple").text.should == "multiple one"
|
||||
end
|
||||
|
||||
it "raises an error when unknown option given" do
|
||||
expect do
|
||||
@session.find(:css, ".singular", :match => :schmoo)
|
||||
end.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
context "within a scope" do
|
||||
|
@ -300,7 +306,7 @@ Capybara::SpecHelper.spec '#find' do
|
|||
@session.find('.//li[1]').text.should =~ /With Simple HTML/
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
it "should support pseudo selectors" do
|
||||
@session.within(:xpath, "//div[@id='for_bar']") do
|
||||
@session.find(:css, 'input:disabled').value.should == 'James'
|
||||
|
|
Loading…
Reference in a new issue