From f23193bea0a632d48fa96d5e51c12598064c4e53 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Wed, 23 Apr 2008 10:54:07 -0400 Subject: [PATCH] Add spec suite to replace test suite --- test/checks_test.rb => spec/checks_spec.rb | 46 +++++------- test/chooses_test.rb => spec/chooses_spec.rb | 28 +++---- .../clicks_button_spec.rb | 74 +++++++++---------- .../clicks_link_spec.rb | 44 +++++------ .../fills_in_test.rb => spec/fills_in_spec.rb | 36 +++++---- test/reloads_test.rb => spec/reloads_spec.rb | 11 ++- test/selects_test.rb => spec/selects_spec.rb | 44 +++++------ test/helper.rb => spec/spec_helper.rb | 6 +- test/visits_test.rb => spec/visits_spec.rb | 17 ++--- 9 files changed, 140 insertions(+), 166 deletions(-) rename test/checks_test.rb => spec/checks_spec.rb (76%) rename test/chooses_test.rb => spec/chooses_spec.rb (78%) rename test/clicks_button_test.rb => spec/clicks_button_spec.rb (85%) rename test/clicks_link_test.rb => spec/clicks_link_spec.rb (85%) rename test/fills_in_test.rb => spec/fills_in_spec.rb (83%) rename test/reloads_test.rb => spec/reloads_spec.rb (71%) rename test/selects_test.rb => spec/selects_spec.rb (81%) rename test/helper.rb => spec/spec_helper.rb (84%) rename test/visits_test.rb => spec/visits_spec.rb (60%) diff --git a/test/checks_test.rb b/spec/checks_spec.rb similarity index 76% rename from test/checks_test.rb rename to spec/checks_spec.rb index 7d3113b..166c3a5 100644 --- a/test/checks_test.rb +++ b/spec/checks_spec.rb @@ -1,37 +1,33 @@ -require File.dirname(__FILE__) + "/helper" +require File.expand_path(File.dirname(__FILE__) + "/spec_helper") -class ChecksTest < Test::Unit::TestCase - def setup +describe "checks" do + before do @session = ActionController::Integration::Session.new @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) end - def test_should_fail_if_no_checkbox_found + it "should_fail_if_no_checkbox_found" do @response.stubs(:body).returns(<<-EOS)
EOS - assert_raises RuntimeError do - @session.checks "remember_me" - end + lambda { @session.checks "remember_me" }.should raise_error 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)
EOS - assert_raises RuntimeError do - @session.checks "remember_me" - end + lambda { @session.checks "remember_me" }.should raise_error end - def test_should_check_rails_style_checkboxes + it "should_check_rails_style_checkboxes" do @response.stubs(:body).returns(<<-EOS)
@@ -45,7 +41,7 @@ class ChecksTest < Test::Unit::TestCase @session.clicks_button 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) @@ -57,7 +53,7 @@ class ChecksTest < Test::Unit::TestCase @session.clicks_button 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) @@ -70,38 +66,34 @@ class ChecksTest < Test::Unit::TestCase end end -class UnchecksTest < Test::Unit::TestCase - def setup +describe "unchecks" do + before do @session = ActionController::Integration::Session.new @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) end - def test_should_fail_if_no_checkbox_found + it "should_fail_if_no_checkbox_found" do @response.stubs(:body).returns(<<-EOS)
EOS - assert_raises RuntimeError do - @session.unchecks "remember_me" - end + lambda { @session.unchecks "remember_me" }.should raise_error 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)
EOS - assert_raises RuntimeError do - @session.unchecks "remember_me" - end + lambda { @session.unchecks "remember_me" }.should raise_error end - def test_should_uncheck_rails_style_checkboxes + it "should_uncheck_rails_style_checkboxes" do @response.stubs(:body).returns(<<-EOS)
@@ -116,7 +108,7 @@ class UnchecksTest < Test::Unit::TestCase @session.clicks_button end - def test_should_result_in_value_not_being_posted + it "should_result_in_value_not_being_posted" do @response.stubs(:body).returns(<<-EOS) @@ -127,4 +119,4 @@ class UnchecksTest < Test::Unit::TestCase @session.unchecks "remember_me" @session.clicks_button end -end +end \ No newline at end of file diff --git a/test/chooses_test.rb b/spec/chooses_spec.rb similarity index 78% rename from test/chooses_test.rb rename to spec/chooses_spec.rb index 6b9afa8..f569d14 100644 --- a/test/chooses_test.rb +++ b/spec/chooses_spec.rb @@ -1,38 +1,33 @@ -require File.dirname(__FILE__) + "/helper" +require File.expand_path(File.dirname(__FILE__) + "/spec_helper") -class ChoosesTest < Test::Unit::TestCase - - def setup +describe "chooses" do + before do @session = ActionController::Integration::Session.new @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) end - def test_should_fail_if_no_radio_buttons_found + it "should_fail_if_no_radio_buttons_found" do @response.stubs(:body).returns(<<-EOS)
EOS - assert_raises RuntimeError do - @session.chooses "first option" - end + lambda { @session.chooses "first option" }.should raise_error 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)
EOS - assert_raises RuntimeError do - @session.chooses "first_option" - end + lambda { @session.chooses "first_option" }.should raise_error end - def test_should_check_rails_style_radio_buttons + it "should_check_rails_style_radio_buttons" do @response.stubs(:body).returns(<<-EOS)
@@ -47,7 +42,7 @@ class ChoosesTest < Test::Unit::TestCase @session.clicks_button end - def test_should_only_submit_last_chosen_value + it "should_only_submit_last_chosen_value" do @response.stubs(:body).returns(<<-EOS) @@ -63,7 +58,7 @@ class ChoosesTest < Test::Unit::TestCase @session.clicks_button 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) @@ -75,7 +70,7 @@ class ChoosesTest < Test::Unit::TestCase @session.clicks_button 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) @@ -85,5 +80,4 @@ class ChoosesTest < Test::Unit::TestCase @session.expects(:post_via_redirect).with("/login", "first_option" => "on") @session.clicks_button end - end \ No newline at end of file diff --git a/test/clicks_button_test.rb b/spec/clicks_button_spec.rb similarity index 85% rename from test/clicks_button_test.rb rename to spec/clicks_button_spec.rb index ea21557..3810a69 100644 --- a/test/clicks_button_test.rb +++ b/spec/clicks_button_spec.rb @@ -1,7 +1,7 @@ -require File.dirname(__FILE__) + "/helper" +require File.expand_path(File.dirname(__FILE__) + "/spec_helper") -class ClicksButtonTest < Test::Unit::TestCase - def setup +describe "clicks_button" do + before do @session = ActionController::Integration::Session.new @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @@ -11,29 +11,25 @@ class ClicksButtonTest < Test::Unit::TestCase @session.stubs(:response).returns(@response) end - def test_should_fail_if_no_buttons + it "should_fail_if_no_buttons" do @response.stubs(:body).returns(<<-EOS)
EOS - assert_raises RuntimeError do - @session.clicks_button - end + lambda { @session.clicks_button }.should raise_error 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)
EOS - - assert_raises RuntimeError do - @session.clicks_button - end + + lambda { @session.clicks_button }.should raise_error end - def test_should_default_to_get_method + it "should_default_to_get_method" do @response.stubs(:body).returns(<<-EOS)
@@ -43,7 +39,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_assert_valid_response + it "should_assert_valid_response" do @response.stubs(:body).returns(<<-EOS) @@ -53,7 +49,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_default_to_current_url + it "should_default_to_current_url" do @response.stubs(:body).returns(<<-EOS) @@ -64,7 +60,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_submit_the_first_form_by_default + it "should_submit_the_first_form_by_default" do @response.stubs(:body).returns(<<-EOS) @@ -77,7 +73,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_not_explode_on_file_fields + it "should_not_explode_on_file_fields" do @response.stubs(:body).returns(<<-EOS) @@ -87,7 +83,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button 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) @@ -100,7 +96,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button "Form2" end - def test_should_use_action_from_form + it "should_use_action_from_form" do @response.stubs(:body).returns(<<-EOS) @@ -110,7 +106,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_use_method_from_form + it "should_use_method_from_form" do @response.stubs(:body).returns(<<-EOS) @@ -120,7 +116,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button 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) @@ -131,7 +127,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button("Login") 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) @@ -142,7 +138,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button("Login") end - def test_should_send_default_password_field_values + it "should_send_default_password_field_values" do @response.stubs(:body).returns(<<-EOS) @@ -153,7 +149,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_send_default_hidden_field_values + it "should_send_default_hidden_field_values" do @response.stubs(:body).returns(<<-EOS) @@ -164,7 +160,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_send_default_text_field_values + it "should_send_default_text_field_values" do @response.stubs(:body).returns(<<-EOS) @@ -175,7 +171,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_send_default_checked_fields + it "should_send_default_checked_fields" do @response.stubs(:body).returns(<<-EOS) @@ -186,7 +182,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_send_default_radio_options + it "should_send_default_radio_options" do @response.stubs(:body).returns(<<-EOS) @@ -200,7 +196,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button 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) @@ -212,7 +208,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button 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) @@ -224,7 +220,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_send_default_collection_fields + it "should_send_default_collection_fields" do @response.stubs(:body).returns(<<-EOS) @@ -246,7 +242,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_not_send_default_unchecked_fields + it "should_not_send_default_unchecked_fields" do @response.stubs(:body).returns(<<-EOS) @@ -257,7 +253,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_send_default_textarea_values + it "should_send_default_textarea_values" do @response.stubs(:body).returns(<<-EOS) @@ -268,7 +264,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button 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) @@ -296,7 +292,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button 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) @@ -322,7 +318,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_send_default_empty_text_field_values + it "should_send_default_empty_text_field_values" do @response.stubs(:body).returns(<<-EOS) @@ -333,7 +329,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_recognize_button_tags + it "should_recognize_button_tags" do @response.stubs(:body).returns(<<-EOS) @@ -344,7 +340,7 @@ class ClicksButtonTest < Test::Unit::TestCase @session.clicks_button end - def test_should_recognize_button_tags_by_content + it "should_recognize_button_tags_by_content" do @response.stubs(:body).returns(<<-EOS) diff --git a/test/clicks_link_test.rb b/spec/clicks_link_spec.rb similarity index 85% rename from test/clicks_link_test.rb rename to spec/clicks_link_spec.rb index 3b1c7e9..dbd10c8 100644 --- a/test/clicks_link_test.rb +++ b/spec/clicks_link_spec.rb @@ -1,14 +1,14 @@ -require File.dirname(__FILE__) + "/helper" +require File.expand_path(File.dirname(__FILE__) + "/spec_helper") -class ClicksLinkTest < Test::Unit::TestCase - def setup +describe "clicks_link" do + before do @session = ActionController::Integration::Session.new @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) end - def test_should_use_get_by_default + it "should_use_get_by_default" do @response.stubs(:body).returns(<<-EOS) Link text EOS @@ -16,7 +16,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link "Link text" end - def test_should_click_get_links + it "should_click_get_links" do @response.stubs(:body).returns(<<-EOS) Link text EOS @@ -24,7 +24,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_get_link "Link text" end - def test_should_click_delete_links + it "should_click_delete_links" do @response.stubs(:body).returns(<<-EOS) Link text EOS @@ -32,7 +32,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_delete_link "Link text" end - def test_should_click_post_links + it "should_click_post_links" do @response.stubs(:body).returns(<<-EOS) Link text EOS @@ -40,7 +40,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_post_link "Link text" end - def test_should_click_put_links + it "should_click_put_links" do @response.stubs(:body).returns(<<-EOS) Link text EOS @@ -48,7 +48,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_put_link "Link text" 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) Link text EOS @@ -127,7 +127,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link "Link text" end - def test_should_not_be_case_sensitive + it "should_not_be_case_sensitive" do @response.stubs(:body).returns(<<-EOS) Link text EOS @@ -135,7 +135,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link "LINK TEXT" end - def test_should_match_link_substrings + it "should_match_link_substrings" do @response.stubs(:body).returns(<<-EOS) This is some cool link text, isn't it? EOS @@ -143,7 +143,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link "Link text" end - def test_should_work_with_elements_in_the_link + it "should_work_with_elements_in_the_link" do @response.stubs(:body).returns(<<-EOS) Link text EOS @@ -151,7 +151,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link "Link text" end - def test_should_match_the_first_matching_link + it "should_match_the_first_matching_link" do @response.stubs(:body).returns(<<-EOS) Link text Link text @@ -160,7 +160,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link "Link text" end - def test_should_choose_the_shortest_link_text_match + it "should_choose_the_shortest_link_text_match" do @response.stubs(:body).returns(<<-EOS) Linkerama Link @@ -170,7 +170,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link "Link" end - def test_should_click_link_within_a_selector + it "should_click_link_within_a_selector" do @response.stubs(:body).returns(<<-EOS) Link
@@ -182,7 +182,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link_within "#container", "Link" 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) Jump to Section 1 EOS @@ -191,7 +191,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link "Jump to Section 1" end - def test_should_follow_relative_links + it "should_follow_relative_links" do @session.current_page.stubs(:url).returns("/page") @response.stubs(:body).returns(<<-EOS) Jump to sub page @@ -200,7 +200,7 @@ class ClicksLinkTest < Test::Unit::TestCase @session.clicks_link "Jump to sub page" end - def test_should_follow_query_parameters + it "should_follow_query_parameters" do @session.current_page.stubs(:url).returns("/page") @response.stubs(:body).returns(<<-EOS) Jump to foo bar diff --git a/test/fills_in_test.rb b/spec/fills_in_spec.rb similarity index 83% rename from test/fills_in_test.rb rename to spec/fills_in_spec.rb index 0ebb567..92529fc 100644 --- a/test/fills_in_test.rb +++ b/spec/fills_in_spec.rb @@ -1,14 +1,14 @@ -require File.dirname(__FILE__) + "/helper" +require File.expand_path(File.dirname(__FILE__) + "/spec_helper") -class FillsInTest < Test::Unit::TestCase - def setup +describe "fills_in" do + before do @session = ActionController::Integration::Session.new @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) end - def test_should_work_with_textareas + it "should_work_with_textareas" do @response.stubs(:body).returns(<<-EOS) @@ -21,7 +21,7 @@ class FillsInTest < Test::Unit::TestCase @session.clicks_button end - def test_should_work_with_password_fields + it "should_work_with_password_fields" do @response.stubs(:body).returns(<<-EOS) @@ -33,18 +33,16 @@ class FillsInTest < Test::Unit::TestCase @session.clicks_button end - def test_should_fail_if_input_not_found + it "should_fail_if_input_not_found" do @response.stubs(:body).returns(<<-EOS) EOS - assert_raises RuntimeError do - @session.fills_in "Email", :with => "foo@example.com" - end + lambda { @session.fills_in "Email", :with => "foo@example.com" }.should raise_error end - def test_should_allow_overriding_default_form_values + it "should_allow_overriding_default_form_values" do @response.stubs(:body).returns(<<-EOS)
@@ -57,7 +55,7 @@ class FillsInTest < Test::Unit::TestCase @session.clicks_button end - def test_should_choose_the_shortest_label_match + it "should_choose_the_shortest_label_match" do @response.stubs(:body).returns(<<-EOS) @@ -73,7 +71,7 @@ class FillsInTest < Test::Unit::TestCase @session.clicks_button 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) @@ -89,7 +87,7 @@ class FillsInTest < Test::Unit::TestCase @session.clicks_button 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) @@ -97,10 +95,10 @@ class FillsInTest < Test::Unit::TestCase
EOS - assert_raises(RuntimeError) { @session.fills_in "mail", :with => "value" } + lambda { @session.fills_in "mail", :with => "value" }.should raise_error end - def test_should_anchor_label_matches_to_word_boundaries + it "should_anchor_label_matches_to_word_boundaries" do @response.stubs(:body).returns(<<-EOS)
@@ -108,10 +106,10 @@ class FillsInTest < Test::Unit::TestCase
EOS - assert_raises(RuntimeError) { @session.fills_in "Email", :with => "value" } + lambda { @session.fills_in "Email", :with => "value" }.should raise_error end - def test_should_work_with_inputs_nested_in_labels + it "should_work_with_inputs_nested_in_labels" do @response.stubs(:body).returns(<<-EOS)