Add options for click_button

This commit is contained in:
CJ Kihlbom and Jonas Nicklas 2013-02-24 16:36:08 +01:00
parent f063375b9b
commit e67f7bf1c2
2 changed files with 28 additions and 15 deletions

View File

@ -33,8 +33,8 @@ module Capybara
# #
# @param [String] locator Text, id or value of button # @param [String] locator Text, id or value of button
# #
def click_button(locator) def click_button(locator, options={})
find(:button, locator).click find(:button, locator, options).click
end end
## ##

View File

@ -137,7 +137,7 @@ Capybara::SpecHelper.spec '#click_button' do
end end
end end
end end
context "with id given on a submit button" do context "with id given on a submit button" do
it "should submit the associated form" do it "should submit the associated form" do
@session.click_button('awe123') @session.click_button('awe123')
@ -161,17 +161,17 @@ Capybara::SpecHelper.spec '#click_button' do
extract_results(@session)['first_name'].should == 'John' extract_results(@session)['first_name'].should == 'John'
end end
end end
context "with fields associated with the form using the form attribute" do context "with fields associated with the form using the form attribute" do
before do before do
@session.click_button('submit_form1') @session.click_button('submit_form1')
@results = extract_results(@session) @results = extract_results(@session)
end end
it "should serialize and submit text fields" do it "should serialize and submit text fields" do
@results['outside_input'].should == 'outside_input' @results['outside_input'].should == 'outside_input'
end end
it "should serialize text areas" do it "should serialize text areas" do
@results['outside_textarea'].should == 'Some text here' @results['outside_textarea'].should == 'Some text here'
end end
@ -179,23 +179,23 @@ Capybara::SpecHelper.spec '#click_button' do
it "should serialize select tags" do it "should serialize select tags" do
@results['outside_select'].should == 'Ruby' @results['outside_select'].should == 'Ruby'
end end
it "should not serliaze fields associated with a different form" do it "should not serliaze fields associated with a different form" do
@results['for_form2'].should be_nil @results['for_form2'].should be_nil
end end
end end
context "with submit button outside the form defined by <button> tag" do context "with submit button outside the form defined by <button> tag" do
before do before do
@session.click_button('outside_button') @session.click_button('outside_button')
@results = extract_results(@session) @results = extract_results(@session)
end end
it "should submit the associated form" do it "should submit the associated form" do
@results['which_form'].should == 'form2' @results['which_form'].should == 'form2'
end end
it "should submit the button that was clicked, but not other buttons" do it "should submit the button that was clicked, but not other buttons" do
@results['outside_button'].should == 'outside_button' @results['outside_button'].should == 'outside_button'
@results['unused'].should be_nil @results['unused'].should be_nil
@ -207,24 +207,24 @@ Capybara::SpecHelper.spec '#click_button' do
@session.click_button('outside_submit') @session.click_button('outside_submit')
@results = extract_results(@session) @results = extract_results(@session)
end end
it "should submit the associated form" do it "should submit the associated form" do
@results['which_form'].should == 'form1' @results['which_form'].should == 'form1'
end end
it "should submit the button that was clicked, but not other buttons" do it "should submit the button that was clicked, but not other buttons" do
@results['outside_submit'].should == 'outside_submit' @results['outside_submit'].should == 'outside_submit'
@results['submit_form1'].should be_nil @results['submit_form1'].should be_nil
end end
end end
context "with submit button for form1 located within form2" do context "with submit button for form1 located within form2" do
it "should submit the form associated with the button" do it "should submit the form associated with the button" do
@session.click_button('other_form_button') @session.click_button('other_form_button')
extract_results(@session)['which_form'].should == "form1" extract_results(@session)['which_form'].should == "form1"
end end
end end
context "with alt given on an image button" do context "with alt given on an image button" do
it "should submit the associated form" do it "should submit the associated form" do
@session.click_button('oh hai thar') @session.click_button('oh hai thar')
@ -395,4 +395,17 @@ Capybara::SpecHelper.spec '#click_button' do
addresses[1]["city"].should == 'Mikolaiv' addresses[1]["city"].should == 'Mikolaiv'
addresses[1]["country"].should == 'Ukraine' addresses[1]["country"].should == 'Ukraine'
end end
context "with :exact option" do
it "should accept partial matches when false" do
@session.click_button('What an Awesome', :exact => false)
extract_results(@session)['first_name'].should == 'John'
end
it "should not accept partial matches when true" do
expect do
@session.click_button('What an Awesome', :exact => true)
end.to raise_error(Capybara::ElementNotFound)
end
end
end end