Add spec suite to replace test suite

This commit is contained in:
Bryan Helmkamp 2008-04-23 10:54:07 -04:00
parent 2ef317f2cf
commit f23193bea0
9 changed files with 140 additions and 166 deletions

View File

@ -1,37 +1,33 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class ChecksTest < Test::Unit::TestCase describe "checks" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_fail_if_no_checkbox_found it "should_fail_if_no_checkbox_found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.checks "remember_me" }.should raise_error
@session.checks "remember_me"
end
end end
def test_should_fail_if_input_is_not_a_checkbox it "should_fail_if_input_is_not_a_checkbox" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" name="remember_me" /> <input type="text" name="remember_me" />
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.checks "remember_me" }.should raise_error
@session.checks "remember_me"
end
end end
def test_should_check_rails_style_checkboxes it "should_check_rails_style_checkboxes" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" />
@ -45,7 +41,7 @@ class ChecksTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_the_value_on_being_posted_if_not_specified it "should_result_in_the_value_on_being_posted_if_not_specified" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="remember_me" /> <input type="checkbox" name="remember_me" />
@ -57,7 +53,7 @@ class ChecksTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_a_custom_value_being_posted it "should_result_in_a_custom_value_being_posted" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" /> <input type="checkbox" name="remember_me" value="yes" />
@ -70,38 +66,34 @@ class ChecksTest < Test::Unit::TestCase
end end
end end
class UnchecksTest < Test::Unit::TestCase describe "unchecks" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_fail_if_no_checkbox_found it "should_fail_if_no_checkbox_found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.unchecks "remember_me" }.should raise_error
@session.unchecks "remember_me"
end
end end
def test_should_fail_if_input_is_not_a_checkbox it "should_fail_if_input_is_not_a_checkbox" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" name="remember_me" /> <input type="text" name="remember_me" />
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.unchecks "remember_me" }.should raise_error
@session.unchecks "remember_me"
end
end end
def test_should_uncheck_rails_style_checkboxes it "should_uncheck_rails_style_checkboxes" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
@ -116,7 +108,7 @@ class UnchecksTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_value_not_being_posted it "should_result_in_value_not_being_posted" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" checked="checked" /> <input type="checkbox" name="remember_me" value="yes" checked="checked" />

View File

@ -1,38 +1,33 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class ChoosesTest < Test::Unit::TestCase describe "chooses" do
before do
def setup
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_fail_if_no_radio_buttons_found it "should_fail_if_no_radio_buttons_found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.chooses "first option" }.should raise_error
@session.chooses "first option"
end
end end
def test_should_fail_if_input_is_not_a_radio_button it "should_fail_if_input_is_not_a_radio_button" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" name="first_option" /> <input type="text" name="first_option" />
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.chooses "first_option" }.should raise_error
@session.chooses "first_option"
end
end end
def test_should_check_rails_style_radio_buttons it "should_check_rails_style_radio_buttons" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
@ -47,7 +42,7 @@ class ChoosesTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_only_submit_last_chosen_value it "should_only_submit_last_chosen_value" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
@ -63,7 +58,7 @@ class ChoosesTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_the_value_on_being_posted_if_not_specified it "should_result_in_the_value_on_being_posted_if_not_specified" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="radio" name="first_option" /> <input type="radio" name="first_option" />
@ -75,7 +70,7 @@ class ChoosesTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_the_value_on_being_posted_if_not_specified_and_checked_by_default it "should_result_in_the_value_on_being_posted_if_not_specified_and_checked_by_default" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="radio" name="first_option" checked="checked"/> <input type="radio" name="first_option" checked="checked"/>
@ -85,5 +80,4 @@ class ChoosesTest < Test::Unit::TestCase
@session.expects(:post_via_redirect).with("/login", "first_option" => "on") @session.expects(:post_via_redirect).with("/login", "first_option" => "on")
@session.clicks_button @session.clicks_button
end end
end end

View File

@ -1,7 +1,7 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class ClicksButtonTest < Test::Unit::TestCase describe "clicks_button" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@ -11,29 +11,25 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.stubs(:response).returns(@response) @session.stubs(:response).returns(@response)
end end
def test_should_fail_if_no_buttons it "should_fail_if_no_buttons" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"></form> <form method="get" action="/login"></form>
EOS EOS
assert_raises RuntimeError do lambda { @session.clicks_button }.should raise_error
@session.clicks_button
end
end end
def test_should_fail_if_input_is_not_a_submit_button it "should_fail_if_input_is_not_a_submit_button" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input type="reset" /> <input type="reset" />
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.clicks_button }.should raise_error
@session.clicks_button
end
end end
def test_should_default_to_get_method it "should_default_to_get_method" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form action="/login"> <form action="/login">
<input type="submit" /> <input type="submit" />
@ -43,7 +39,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_assert_valid_response it "should_assert_valid_response" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form action="/login"> <form action="/login">
<input type="submit" /> <input type="submit" />
@ -53,7 +49,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_default_to_current_url it "should_default_to_current_url" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get"> <form method="get">
<input type="submit" /> <input type="submit" />
@ -64,7 +60,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_submit_the_first_form_by_default it "should_submit_the_first_form_by_default" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/form1"> <form method="get" action="/form1">
<input type="submit" /> <input type="submit" />
@ -77,7 +73,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_not_explode_on_file_fields it "should_not_explode_on_file_fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/form1"> <form method="get" action="/form1">
<input type="file" /> <input type="file" />
@ -87,7 +83,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_submit_the_form_with_the_specified_button it "should_submit_the_form_with_the_specified_button" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/form1"> <form method="get" action="/form1">
<input type="submit" /> <input type="submit" />
@ -100,7 +96,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button "Form2" @session.clicks_button "Form2"
end end
def test_should_use_action_from_form it "should_use_action_from_form" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input type="submit" /> <input type="submit" />
@ -110,7 +106,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_use_method_from_form it "should_use_method_from_form" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="submit" /> <input type="submit" />
@ -120,7 +116,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_button_as_param_if_it_has_a_name it "should_send_button_as_param_if_it_has_a_name" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="submit" name="cancel" value="Cancel" /> <input type="submit" name="cancel" value="Cancel" />
@ -131,7 +127,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button("Login") @session.clicks_button("Login")
end end
def test_should_not_send_button_as_param_if_it_has_no_name it "should_not_send_button_as_param_if_it_has_no_name" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="submit" name="cancel" value="Cancel" /> <input type="submit" name="cancel" value="Cancel" />
@ -142,7 +138,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button("Login") @session.clicks_button("Login")
end end
def test_should_send_default_password_field_values it "should_send_default_password_field_values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_password" name="user[password]" value="mypass" type="password" /> <input id="user_password" name="user[password]" value="mypass" type="password" />
@ -153,7 +149,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_hidden_field_values it "should_send_default_hidden_field_values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="test@example.com" type="hidden" /> <input id="user_email" name="user[email]" value="test@example.com" type="hidden" />
@ -164,7 +160,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_text_field_values it "should_send_default_text_field_values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="test@example.com" type="text" /> <input id="user_email" name="user[email]" value="test@example.com" type="text" />
@ -175,7 +171,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_checked_fields it "should_send_default_checked_fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" value="1" type="checkbox" checked="checked" /> <input id="user_tos" name="user[tos]" value="1" type="checkbox" checked="checked" />
@ -186,7 +182,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_radio_options it "should_send_default_radio_options" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
@ -200,7 +196,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_correct_data_for_rails_style_unchecked_fields it "should_send_correct_data_for_rails_style_unchecked_fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" />
@ -212,7 +208,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_correct_data_for_rails_style_checked_fields it "should_send_correct_data_for_rails_style_checked_fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
@ -224,7 +220,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_collection_fields it "should_send_default_collection_fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="options[]" value="burger" checked="checked" /> <input type="checkbox" name="options[]" value="burger" checked="checked" />
@ -246,7 +242,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_not_send_default_unchecked_fields it "should_not_send_default_unchecked_fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" value="1" type="checkbox" /> <input id="user_tos" name="user[tos]" value="1" type="checkbox" />
@ -257,7 +253,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_textarea_values it "should_send_default_textarea_values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/posts"> <form method="post" action="/posts">
<textarea name="post[body]">Post body here!</textarea> <textarea name="post[body]">Post body here!</textarea>
@ -268,7 +264,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_selected_option_value_from_select it "should_send_default_selected_option_value_from_select" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"> <select name="month">
@ -282,7 +278,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_selected_option_inner_html_from_select_when_no_value_attribute it "should_send_default_selected_option_inner_html_from_select_when_no_value_attribute" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"> <select name="month">
@ -296,7 +292,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_first_select_option_value_when_no_option_selected it "should_send_first_select_option_value_when_no_option_selected" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"> <select name="month">
@ -310,7 +306,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_handle_nested_properties it "should_handle_nested_properties" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" id="contestant_scores_12" name="contestant[scores][1]" value="2"/> <input type="text" id="contestant_scores_12" name="contestant[scores][1]" value="2"/>
@ -322,7 +318,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_empty_text_field_values it "should_send_default_empty_text_field_values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" /> <input id="user_email" name="user[email]" value="" type="text" />
@ -333,7 +329,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_recognize_button_tags it "should_recognize_button_tags" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" /> <input id="user_email" name="user[email]" value="" type="text" />
@ -344,7 +340,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_recognize_button_tags_by_content it "should_recognize_button_tags_by_content" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" /> <input id="user_email" name="user[email]" value="" type="text" />

View File

@ -1,14 +1,14 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class ClicksLinkTest < Test::Unit::TestCase describe "clicks_link" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_use_get_by_default it "should_use_get_by_default" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -16,7 +16,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_click_get_links it "should_click_get_links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -24,7 +24,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_get_link "Link text" @session.clicks_get_link "Link text"
end end
def test_should_click_delete_links it "should_click_delete_links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -32,7 +32,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_delete_link "Link text" @session.clicks_delete_link "Link text"
end end
def test_should_click_post_links it "should_click_post_links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -40,7 +40,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_post_link "Link text" @session.clicks_post_link "Link text"
end end
def test_should_click_put_links it "should_click_put_links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -48,7 +48,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_put_link "Link text" @session.clicks_put_link "Link text"
end end
def test_should_click_rails_javascript_links_with_authenticity_tokens it "should_click_rails_javascript_links_with_authenticity_tokens" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
@ -67,7 +67,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Posts" @session.clicks_link "Posts"
end end
def test_should_click_rails_javascript_delete_links it "should_click_rails_javascript_delete_links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/posts/1" onclick="var f = document.createElement('form'); <a href="/posts/1" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
@ -86,7 +86,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Delete" @session.clicks_link "Delete"
end end
def test_should_click_rails_javascript_post_links it "should_click_rails_javascript_post_links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
@ -100,7 +100,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Posts" @session.clicks_link "Posts"
end end
def test_should_click_rails_javascript_put_links it "should_click_rails_javascript_put_links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
@ -119,7 +119,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Put" @session.clicks_link "Put"
end end
def test_should_assert_valid_response it "should_assert_valid_response" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -127,7 +127,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_not_be_case_sensitive it "should_not_be_case_sensitive" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -135,7 +135,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "LINK TEXT" @session.clicks_link "LINK TEXT"
end end
def test_should_match_link_substrings it "should_match_link_substrings" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">This is some cool link text, isn't it?</a> <a href="/page">This is some cool link text, isn't it?</a>
EOS EOS
@ -143,7 +143,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_work_with_elements_in_the_link it "should_work_with_elements_in_the_link" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page"><span>Link text</span></a> <a href="/page"><span>Link text</span></a>
EOS EOS
@ -151,7 +151,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_match_the_first_matching_link it "should_match_the_first_matching_link" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page1">Link text</a> <a href="/page1">Link text</a>
<a href="/page2">Link text</a> <a href="/page2">Link text</a>
@ -160,7 +160,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_choose_the_shortest_link_text_match it "should_choose_the_shortest_link_text_match" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page1">Linkerama</a> <a href="/page1">Linkerama</a>
<a href="/page2">Link</a> <a href="/page2">Link</a>
@ -170,7 +170,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link" @session.clicks_link "Link"
end end
def test_should_click_link_within_a_selector it "should_click_link_within_a_selector" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page1">Link</a> <a href="/page1">Link</a>
<div id="container"> <div id="container">
@ -182,7 +182,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link_within "#container", "Link" @session.clicks_link_within "#container", "Link"
end end
def test_should_not_make_request_when_link_is_local_anchor it "should_not_make_request_when_link_is_local_anchor" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="#section-1">Jump to Section 1</a> <a href="#section-1">Jump to Section 1</a>
EOS EOS
@ -191,7 +191,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Jump to Section 1" @session.clicks_link "Jump to Section 1"
end end
def test_should_follow_relative_links it "should_follow_relative_links" do
@session.current_page.stubs(:url).returns("/page") @session.current_page.stubs(:url).returns("/page")
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="sub">Jump to sub page</a> <a href="sub">Jump to sub page</a>
@ -200,7 +200,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Jump to sub page" @session.clicks_link "Jump to sub page"
end end
def test_should_follow_query_parameters it "should_follow_query_parameters" do
@session.current_page.stubs(:url).returns("/page") @session.current_page.stubs(:url).returns("/page")
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="?foo=bar">Jump to foo bar</a> <a href="?foo=bar">Jump to foo bar</a>

View File

@ -1,14 +1,14 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class FillsInTest < Test::Unit::TestCase describe "fills_in" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_work_with_textareas it "should_work_with_textareas" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_text">User Text</label> <label for="user_text">User Text</label>
@ -21,7 +21,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_with_password_fields it "should_work_with_password_fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input id="user_text" name="user[text]" type="password" /> <input id="user_text" name="user[text]" type="password" />
@ -33,18 +33,16 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_fail_if_input_not_found it "should_fail_if_input_not_found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.fills_in "Email", :with => "foo@example.com" }.should raise_error
@session.fills_in "Email", :with => "foo@example.com"
end
end end
def test_should_allow_overriding_default_form_values it "should_allow_overriding_default_form_values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Email</label> <label for="user_email">Email</label>
@ -57,7 +55,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_choose_the_shortest_label_match it "should_choose_the_shortest_label_match" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_mail1">Some other mail</label> <label for="user_mail1">Some other mail</label>
@ -73,7 +71,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_choose_the_first_label_match_if_closest_is_a_tie it "should_choose_the_first_label_match_if_closest_is_a_tie" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_mail1">Some mail one</label> <label for="user_mail1">Some mail one</label>
@ -89,7 +87,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_anchor_label_matches_to_start_of_label it "should_anchor_label_matches_to_start_of_label" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Some mail</label> <label for="user_email">Some mail</label>
@ -97,10 +95,10 @@ class FillsInTest < Test::Unit::TestCase
</form> </form>
EOS EOS
assert_raises(RuntimeError) { @session.fills_in "mail", :with => "value" } lambda { @session.fills_in "mail", :with => "value" }.should raise_error
end end
def test_should_anchor_label_matches_to_word_boundaries it "should_anchor_label_matches_to_word_boundaries" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Emailtastic</label> <label for="user_email">Emailtastic</label>
@ -108,10 +106,10 @@ class FillsInTest < Test::Unit::TestCase
</form> </form>
EOS EOS
assert_raises(RuntimeError) { @session.fills_in "Email", :with => "value" } lambda { @session.fills_in "Email", :with => "value" }.should raise_error
end end
def test_should_work_with_inputs_nested_in_labels it "should_work_with_inputs_nested_in_labels" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label> <label>
@ -126,7 +124,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_with_full_input_names it "should_work_with_full_input_names" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input id="user_email" name="user[email]" type="text" /> <input id="user_email" name="user[email]" type="text" />
@ -138,7 +136,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_with_symbols it "should_work_with_symbols" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Email</label> <label for="user_email">Email</label>

View File

@ -1,10 +1,9 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
RAILS_ROOT = "." unless defined?(RAILS_ROOT) RAILS_ROOT = "." unless defined?(RAILS_ROOT)
class ReloadsTest < Test::Unit::TestCase describe "reloads" do
before do
def setup
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@ -13,13 +12,13 @@ class ReloadsTest < Test::Unit::TestCase
@response.stubs(:body).returns("") @response.stubs(:body).returns("")
end end
def test_should_reload_the_page it "should_reload_the_page" do
@session.expects(:get_via_redirect).with("/", {}).times(2) @session.expects(:get_via_redirect).with("/", {}).times(2)
@session.visits("/") @session.visits("/")
@session.reloads @session.reloads
end end
def test_should_not_request_page_if_not_visited_any_page it "should_not_request_page_if_not_visited_any_page" do
@session.expects(:get_via_redirect).never @session.expects(:get_via_redirect).never
@session.reloads @session.reloads
end end

View File

@ -1,26 +1,24 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class SelectsTest < Test::Unit::TestCase describe "selects" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_fail_if_option_not_found it "should_fail_if_option_not_found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.selects "February", :from => "month" }.should raise_error
@session.selects "February", :from => "month"
end
end end
def test_should_fail_if_option_not_found_in_list_specified_by_element_name it "should_fail_if_option_not_found_in_list_specified_by_element_name" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
@ -28,24 +26,20 @@ class SelectsTest < Test::Unit::TestCase
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.selects "February", :from => "year" }.should raise_error
@session.selects "February", :from => "year"
end
end end
def test_should_fail_if_specified_list_not_found it "should_fail_if_specified_list_not_found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.selects "February", :from => "year" }.should raise_error
@session.selects "February", :from => "year"
end
end end
def test_should_send_value_from_option it "should_send_value_from_option" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
@ -57,7 +51,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_with_empty_select_lists it "should_work_with_empty_select_lists" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"></select> <select name="month"></select>
@ -68,7 +62,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_without_specifying_the_field_name_or_label it "should_work_without_specifying_the_field_name_or_label" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
@ -80,7 +74,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_value_from_option_in_list_specified_by_name it "should_send_value_from_option_in_list_specified_by_name" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="start_month"><option value="s1">January</option></select> <select name="start_month"><option value="s1">January</option></select>
@ -93,7 +87,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_value_from_option_in_list_specified_by_label it "should_send_value_from_option_in_list_specified_by_label" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="start_month">Start Month</label> <label for="start_month">Start Month</label>
@ -108,7 +102,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_use_option_text_if_no_value it "should_use_option_text_if_no_value" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
@ -120,7 +114,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_find_option_by_regexp it "should_find_option_by_regexp" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
@ -132,7 +126,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_find_option_by_regexp_in_list_specified_by_label it "should_find_option_by_regexp_in_list_specified_by_label" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="start_month">Start Month</label> <label for="start_month">Start Month</label>

View File

@ -1,5 +1,5 @@
require "rubygems" require "rubygems"
require "test/unit" require "spec"
# gem install redgreen for colored test output # gem install redgreen for colored test output
begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
require "mocha" require "mocha"
@ -18,3 +18,7 @@ class ActionController::Integration::Session
raise message raise message
end end
end end
Spec::Runner.configure do |config|
config.mock_with :mocha
end

View File

@ -1,10 +1,9 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
RAILS_ROOT = "." unless defined?(RAILS_ROOT) RAILS_ROOT = "." unless defined?(RAILS_ROOT)
class VisitsTest < Test::Unit::TestCase describe "visits" do
before do
def setup
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@ -13,19 +12,17 @@ class VisitsTest < Test::Unit::TestCase
@response.stubs(:body).returns("") @response.stubs(:body).returns("")
end end
def test_should_use_get it "should_use_get" do
@session.expects(:get_via_redirect).with("/", {}) @session.expects(:get_via_redirect).with("/", {})
@session.visits("/") @session.visits("/")
end end
def test_should_assert_valid_response it "should_assert_valid_response" do
@session.expects(:assert_response).with(:success) @session.expects(:assert_response).with(:success)
@session.visits("/") @session.visits("/")
end end
def test_should_require_a_visit_before_manipulating_page it "should_require_a_visit_before_manipulating_page" do
assert_raise(RuntimeError) do lambda { @session.fills_in "foo", :with => "blah" }.should raise_error
@session.fills_in "foo", :with => "blah"
end
end end
end end