2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec "#choose" do
|
|
|
|
before do
|
|
|
|
@session.visit('/form')
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should choose a radio button by id" do
|
|
|
|
@session.choose("gender_male")
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['gender'].should == 'male'
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should choose a radio button by label" do
|
|
|
|
@session.choose("Both")
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['gender'].should == 'both'
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2012-09-06 03:33:43 -04:00
|
|
|
it "casts to string" do
|
|
|
|
@session.choose("Both")
|
|
|
|
@session.click_button(:'awesome')
|
|
|
|
extract_results(@session)['gender'].should == 'both'
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context "with a locator that doesn't exist" do
|
|
|
|
it "should raise an error" do
|
|
|
|
msg = "Unable to find radio button \"does not exist\""
|
2012-10-30 09:26:19 -04:00
|
|
|
expect do
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.choose('does not exist')
|
2012-10-30 09:26:19 -04:00
|
|
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
|
|
|
end
|
2012-09-09 11:18:03 -04:00
|
|
|
|
|
|
|
context "with a disabled radio button" do
|
|
|
|
it "should raise an error" do
|
2012-10-30 09:26:19 -04:00
|
|
|
expect do
|
2012-09-09 11:18:03 -04:00
|
|
|
@session.choose('Disabled Radio')
|
2012-10-30 09:26:19 -04:00
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
2012-09-09 11:18:03 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-24 10:48:14 -05:00
|
|
|
|
|
|
|
context "with :exact option" do
|
|
|
|
it "should accept partial matches when false" do
|
|
|
|
@session.choose("Mal", :exact => false)
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['gender'].should == 'male'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not accept partial matches when true" do
|
|
|
|
expect do
|
|
|
|
@session.choose("Mal", :exact => true)
|
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
2013-10-20 13:59:07 -04:00
|
|
|
|
|
|
|
context "with `option` option" do
|
|
|
|
it "can check radio buttons by their value" do
|
|
|
|
@session.choose('form[gender]', :option => "male")
|
|
|
|
@session.click_button('awesome')
|
|
|
|
extract_results(@session)['gender'].should == "male"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise an error if option not found" do
|
|
|
|
expect do
|
|
|
|
@session.choose('form[gender]', :option => "hermaphrodite")
|
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|