webrat/spec/chooses_spec.rb

83 lines
2.8 KiB
Ruby
Raw Normal View History

2008-04-23 14:54:07 +00:00
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2008-04-07 17:48:45 +00:00
2008-04-23 14:54:07 +00:00
describe "chooses" do
before do
2008-04-07 17:48:45 +00:00
@session = ActionController::Integration::Session.new
@session.stubs(:assert_response)
@session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock)
end
2008-04-23 14:54:07 +00:00
it "should_fail_if_no_radio_buttons_found" do
2008-04-07 17:48:45 +00:00
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
</form>
EOS
2008-04-23 14:54:07 +00:00
lambda { @session.chooses "first option" }.should raise_error
2008-04-07 17:48:45 +00:00
end
2008-04-23 14:54:07 +00:00
it "should_fail_if_input_is_not_a_radio_button" do
2008-04-07 17:48:45 +00:00
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<input type="text" name="first_option" />
</form>
EOS
2008-04-23 14:54:07 +00:00
lambda { @session.chooses "first_option" }.should raise_error
2008-04-07 17:48:45 +00:00
end
2008-04-23 14:54:07 +00:00
it "should_check_rails_style_radio_buttons" do
2008-04-07 17:48:45 +00:00
@response.stubs(:body).returns(<<-EOS)
<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>
EOS
@session.expects(:get_via_redirect).with("/login", "user" => {"gender" => "M"})
@session.chooses "Male"
@session.clicks_button
end
2008-04-23 14:54:07 +00:00
it "should_only_submit_last_chosen_value" do
2008-04-07 17:48:45 +00:00
@response.stubs(:body).returns(<<-EOS)
<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>
EOS
@session.expects(:get_via_redirect).with("/login", "user" => {"gender" => "M"})
@session.chooses "Female"
@session.chooses "Male"
@session.clicks_button
end
2008-04-23 14:54:07 +00:00
it "should_result_in_the_value_on_being_posted_if_not_specified" do
2008-04-07 17:48:45 +00:00
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<input type="radio" name="first_option" />
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/login", "first_option" => "on")
@session.chooses "first_option"
@session.clicks_button
end
2008-04-23 14:54:07 +00:00
it "should_result_in_the_value_on_being_posted_if_not_specified_and_checked_by_default" do
2008-04-07 17:48:45 +00:00
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<input type="radio" name="first_option" checked="checked"/>
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/login", "first_option" => "on")
@session.clicks_button
end
end