Support non string arguments

Most of this work was done in the xpath gem, this
commit really only adds tests.
This commit is contained in:
Jonas Nicklas 2012-09-06 09:33:43 +02:00
parent d153635e65
commit c7bf8359f2
22 changed files with 86 additions and 4 deletions

View File

@ -95,7 +95,7 @@ end
Capybara.add_selector(:link) do
xpath { |locator| XPath::HTML.link(locator) }
filter(:href) do |node, href|
node.first(:xpath, XPath.axis(:self)[XPath.attr(:href).equals(href)])
node.first(:xpath, XPath.axis(:self)[XPath.attr(:href).equals(href.to_s)])
end
end

View File

@ -17,6 +17,12 @@ Capybara::SpecHelper.spec "#attach_file" do
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
it "casts to string" do
@session.attach_file :"form_image", __FILE__
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
end
context "with multipart form" do

View File

@ -60,6 +60,12 @@ Capybara::SpecHelper.spec "#check" do
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
end
it "casts to string" do
@session.check(:"form_pets_cat")
@session.click_button('awesome')
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
end
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find checkbox \"does not exist\""

View File

@ -15,6 +15,12 @@ Capybara::SpecHelper.spec "#choose" do
extract_results(@session)['gender'].should == 'both'
end
it "casts to string" do
@session.choose("Both")
@session.click_button(:'awesome')
extract_results(@session)['gender'].should == 'both'
end
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find radio button \"does not exist\""

View File

@ -9,6 +9,12 @@ Capybara::SpecHelper.spec '#click_button' do
@session.click_button('New Here')
end
it "casts to string" do
@session.click_button(:'Relative Action')
@session.current_path.should == '/relative'
extract_results(@session)['relative'].should == 'Relative Action'
end
context "with multiple values with the same name" do
it "should use the latest given value" do
@session.check('Terms of Use')

View File

@ -29,6 +29,12 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
@session.click_link_or_button('Has been clicked')
end
it "casts to string" do
@session.visit('/form')
@session.click_link_or_button(:'awe123')
extract_results(@session)['first_name'].should == 'John'
end
context "with a locator that doesn't exist" do
it "should raise an error" do
@session.visit('/with_html')

View File

@ -9,6 +9,11 @@ Capybara::SpecHelper.spec '#click_link' do
@session.click_link('Has been clicked')
end
it "casts to string" do
@session.click_link(:'foo')
@session.should have_content('Another World')
end
context "with id given" do
it "should take user to the linked page" do
@session.click_link('foo')

View File

@ -97,6 +97,12 @@ Capybara::SpecHelper.spec "#fill_in" do
@session.fill_in('new_field', :with => 'Testing...')
end
it "casts to string" do
@session.fill_in(:'form_first_name', :with => :'Harry')
@session.click_button('awesome')
extract_results(@session)['first_name'].should == 'Harry'
end
context 'on a pre-populated textfield with a reformatting onchange', :requires => [:js] do
it 'should only trigger onchange once' do
@session.visit('/with_js')

View File

@ -3,12 +3,16 @@ Capybara::SpecHelper.spec '#find_button' do
@session.visit('/form')
end
it "should find any field" do
it "should find any button" do
@session.find_button('med')[:id].should == "mediocre"
@session.find_button('crap321').value.should == "crappy"
end
it "should raise error if the field doesn't exist" do
it "casts to string" do
@session.find_button(:'med')[:id].should == "mediocre"
end
it "should raise error if the button doesn't exist" do
running do
@session.find_button('Does not exist')
end.should raise_error(Capybara::ElementNotFound)

View File

@ -8,6 +8,10 @@ Capybara::SpecHelper.spec '#find_by_id' do
@session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
end
it "casts to string" do
@session.find_by_id(:'red').tag_name.should == 'a'
end
it "should raise error if no element with id is found" do
running do
@session.find_by_id('nothing_with_this_id')

View File

@ -9,6 +9,10 @@ Capybara::SpecHelper.spec '#find_field' do
@session.find_field('Region')[:name].should == 'form[region]'
end
it "casts to string" do
@session.find_field(:'Dog').value.should == 'dog'
end
it "should raise error if the field doesn't exist" do
running do
@session.find_field('Does not exist')

View File

@ -8,6 +8,10 @@ Capybara::SpecHelper.spec '#find_link' do
@session.find_link('labore')[:href].should =~ %r(/with_simple_html$)
end
it "casts to string" do
@session.find_link(:'foo').text.should == "ullamco"
end
it "should raise error if the field doesn't exist" do
running do
@session.find_link('Does not exist')

View File

@ -6,6 +6,7 @@ Capybara::SpecHelper.spec '#has_button?' do
it "should be true if the given button is on the page" do
@session.should have_button('med')
@session.should have_button('crap321')
@session.should have_button(:'crap321')
end
it "should be false if the given button is not on the page" do

View File

@ -5,6 +5,7 @@ Capybara::SpecHelper.spec '#has_field' do
@session.should have_field('Dog')
@session.should have_field('form_description')
@session.should have_field('Region')
@session.should have_field(:'Region')
end
it "should be false if the field is not on the page" do

View File

@ -7,6 +7,7 @@ Capybara::SpecHelper.spec '#has_link?' do
@session.should have_link('foo')
@session.should have_link('awesome title')
@session.should have_link('A link', :href => '/with_simple_html')
@session.should have_link(:'A link', :href => :'/with_simple_html')
end
it "should be false if the given link is not on the page" do

View File

@ -5,6 +5,7 @@ Capybara::SpecHelper.spec '#has_select?' do
@session.should have_select('Locale')
@session.should have_select('form_region')
@session.should have_select('Languages')
@session.should have_select(:'Languages')
end
it "should be false if the field is not on the page" do

View File

@ -6,6 +6,7 @@ Capybara::SpecHelper.spec '#has_table?' do
it "should be true if the table is on the page" do
@session.should have_table('Villain')
@session.should have_table('villain_table')
@session.should have_table(:'villain_table')
end
it "should be false if the table is not on the page" do

View File

@ -4,6 +4,7 @@ Capybara::SpecHelper.spec '#has_text?' do
@session.should have_text('est')
@session.should have_text('Lorem')
@session.should have_text('Redirect')
@session.should have_text(:'Redirect')
end
it "should be true if scoped to an element which has the text" do

View File

@ -54,6 +54,11 @@ Capybara::SpecHelper.spec "#select" do
extract_results(@session)['locale'].should == 'jbo'
end
it "casts to string" do
@session.select(:"Miss", :from => :'Title')
@session.find_field('Title').value.should == 'Miss'
end
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find select box \"does not exist\""

View File

@ -16,4 +16,11 @@ Capybara::SpecHelper.spec "#uncheck" do
extract_results(@session)['pets'].should include('dog')
extract_results(@session)['pets'].should_not include('hamster')
end
it "casts to string" do
@session.uncheck(:"form_pets_hamster")
@session.click_button('awesome')
extract_results(@session)['pets'].should include('dog')
extract_results(@session)['pets'].should_not include('hamster')
end
end

View File

@ -37,6 +37,13 @@ Capybara::SpecHelper.spec "#unselect" do
@session.click_button('awesome')
extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
end
it "casts to string" do
@session.unselect(:"Briefs", :from => :'Underwear')
@session.click_button('awesome')
extract_results(@session)['underwear'].should include('Commando', 'Boxerbriefs')
extract_results(@session)['underwear'].should_not include('Briefs')
end
end
context "with single select" do

2
xpath

@ -1 +1 @@
Subproject commit 8a9d7ccce7183bed900dd337db1553e20f504273
Subproject commit 6873e1655e1945b624673956a0595e64b865d64a