webrat/spec/public/choose_spec.rb

119 lines
3.7 KiB
Ruby
Raw Normal View History

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2008-04-07 17:48:45 +00:00
2008-11-05 23:29:04 +00:00
describe "choose" do
2008-04-27 16:45:01 +00:00
it "should fail if no radio buttons found" do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<html>
2008-04-07 17:48:45 +00:00
<form method="post" action="/login">
</form>
</html>
2008-11-23 05:22:49 +00:00
HTML
2009-04-08 00:30:12 +00:00
2008-11-23 05:22:49 +00:00
lambda { choose "first option" }.should raise_error(Webrat::NotFoundError)
2008-04-07 17:48:45 +00:00
end
2009-04-08 00:30:12 +00:00
2008-04-27 16:45:01 +00:00
it "should fail if input is not a radio button" do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<html>
2008-04-07 17:48:45 +00:00
<form method="post" action="/login">
<input type="text" name="first_option" />
</form>
</html>
2008-11-23 05:22:49 +00:00
HTML
2009-04-08 00:30:12 +00:00
2008-11-23 05:22:49 +00:00
lambda { choose "first_option" }.should raise_error(Webrat::NotFoundError)
2008-04-07 17:48:45 +00:00
end
2009-04-08 00:30:12 +00:00
2008-04-27 16:45:01 +00:00
it "should check rails style radio buttons" do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<html>
2008-04-07 17:48:45 +00:00
<form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
<input id="user_gender_female" name="user[gender]" type="radio" value="F" />
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
2008-11-23 05:22:49 +00:00
HTML
2009-04-08 00:37:26 +00:00
webrat_session.should_receive(:get).with("http://www.example.com/login", "user" => {"gender" => "M"})
2008-11-23 05:22:49 +00:00
choose "Male"
click_button
2008-07-08 17:31:44 +00:00
end
2009-04-08 00:30:12 +00:00
2008-04-27 16:45:01 +00:00
it "should only submit last chosen value" do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<html>
2008-04-07 17:48:45 +00:00
<form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
<input id="user_gender_female" name="user[gender]" type="radio" value="F" />
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
2008-11-23 05:22:49 +00:00
HTML
2009-04-08 00:37:26 +00:00
webrat_session.should_receive(:get).with("http://www.example.com/login", "user" => {"gender" => "M"})
2008-11-23 05:22:49 +00:00
choose "Female"
choose "Male"
click_button
end
2009-04-08 00:30:12 +00:00
it "should fail if the radio button is disabled" do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<html>
<form method="post" action="/login">
<input type="radio" name="first_option" disabled="disabled" />
<input type="submit" />
</form>
</html>
2008-11-23 05:22:49 +00:00
HTML
2009-04-08 00:30:12 +00:00
2008-11-23 05:22:49 +00:00
lambda { choose "first_option" }.should raise_error(Webrat::DisabledFieldError)
end
2009-04-08 00:30:12 +00:00
2008-04-27 16:45:01 +00:00
it "should result in the value on being posted if not specified" do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<html>
2008-04-07 17:48:45 +00:00
<form method="post" action="/login">
<input type="radio" name="first_option" />
<input type="submit" />
</form>
</html>
2008-11-23 05:22:49 +00:00
HTML
2009-04-08 00:37:26 +00:00
webrat_session.should_receive(:post).with("http://www.example.com/login", "first_option" => "on")
2008-11-23 05:22:49 +00:00
choose "first_option"
click_button
2008-04-07 17:48:45 +00:00
end
2009-04-08 00:30:12 +00:00
2008-04-27 16:45:01 +00:00
it "should result in the value on being posted if not specified and checked by default" do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<html>
2008-04-07 17:48:45 +00:00
<form method="post" action="/login">
<input type="radio" name="first_option" checked="checked"/>
<input type="submit" />
</form>
</html>
2008-11-23 05:22:49 +00:00
HTML
2009-04-08 00:37:26 +00:00
webrat_session.should_receive(:post).with("http://www.example.com/login", "first_option" => "on")
2008-11-23 05:22:49 +00:00
click_button
2008-04-07 17:48:45 +00:00
end
2009-04-08 00:30:12 +00:00
it "should result in the value of the selected radio button being posted when a subsequent one is checked by default" do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<html>
<form method="post" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
<input id="user_gender_female" name="user[gender]" type="radio" value="F" checked="checked" />
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
2008-11-23 05:22:49 +00:00
HTML
2009-04-08 00:37:26 +00:00
webrat_session.should_receive(:post).with("http://www.example.com/login", "user" => {"gender" => "M"})
2008-11-23 05:22:49 +00:00
choose "Male"
click_button
end
2008-04-27 16:45:01 +00:00
end