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\""
|
|
|
|
running do
|
|
|
|
@session.choose('does not exist')
|
|
|
|
end.should 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
|
|
|
|
running do
|
|
|
|
@session.choose('Disabled Radio')
|
|
|
|
end.should raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|