rspec-rails 1.1.12 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/.document +7 -0
  2. data/History.txt +55 -0
  3. data/License.txt +1 -1
  4. data/Manifest.txt +53 -48
  5. data/README.txt +5 -4
  6. data/Rakefile +9 -2
  7. data/TODO.txt +1 -0
  8. data/Upgrade.markdown +103 -0
  9. data/generators/rspec/rspec_generator.rb +1 -0
  10. data/generators/rspec/templates/rspec.rake +134 -111
  11. data/generators/rspec/templates/script/autospec +1 -0
  12. data/generators/rspec/templates/script/spec +21 -4
  13. data/generators/rspec/templates/script/spec_server +34 -107
  14. data/generators/rspec/templates/spec_helper.rb +1 -1
  15. data/generators/rspec_controller/rspec_controller_generator.rb +1 -5
  16. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +13 -17
  17. data/generators/rspec_scaffold/templates/controller_spec.rb +27 -29
  18. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +2 -2
  19. data/generators/rspec_scaffold/templates/helper_spec.rb +1 -1
  20. data/generators/rspec_scaffold/templates/index_erb_spec.rb +2 -2
  21. data/generators/rspec_scaffold/templates/new_erb_spec.rb +2 -2
  22. data/generators/rspec_scaffold/templates/routing_spec.rb +24 -20
  23. data/generators/rspec_scaffold/templates/show_erb_spec.rb +2 -2
  24. data/lib/spec/rails.rb +10 -9
  25. data/lib/spec/rails/example.rb +2 -2
  26. data/lib/spec/rails/example/assigns_hash_proxy.rb +1 -2
  27. data/lib/spec/rails/example/controller_example_group.rb +117 -123
  28. data/lib/spec/rails/example/functional_example_group.rb +7 -22
  29. data/lib/spec/rails/example/helper_example_group.rb +15 -33
  30. data/lib/spec/rails/example/model_example_group.rb +1 -1
  31. data/lib/spec/rails/example/render_observer.rb +0 -26
  32. data/lib/spec/rails/example/routing_example_group.rb +13 -0
  33. data/lib/spec/rails/example/routing_helpers.rb +68 -0
  34. data/lib/spec/rails/example/view_example_group.rb +50 -47
  35. data/lib/spec/rails/extensions.rb +2 -1
  36. data/lib/spec/rails/extensions/action_controller/rescue.rb +25 -8
  37. data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
  38. data/lib/spec/rails/extensions/action_controller/test_response.rb +4 -3
  39. data/lib/spec/rails/extensions/action_view/base.rb +9 -9
  40. data/lib/spec/rails/extensions/active_record/base.rb +39 -23
  41. data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
  42. data/lib/spec/rails/extensions/spec/matchers/have.rb +8 -6
  43. data/lib/spec/rails/extensions/spec/runner/configuration.rb +12 -44
  44. data/lib/spec/rails/matchers/ar_be_valid.rb +8 -5
  45. data/lib/spec/rails/matchers/assert_select.rb +36 -21
  46. data/lib/spec/rails/matchers/have_text.rb +3 -3
  47. data/lib/spec/rails/matchers/include_text.rb +4 -4
  48. data/lib/spec/rails/matchers/redirect_to.rb +30 -19
  49. data/lib/spec/rails/matchers/render_template.rb +7 -3
  50. data/lib/spec/rails/mocks.rb +1 -1
  51. data/lib/spec/rails/spec_server.rb +97 -0
  52. data/lib/spec/rails/story_adapter.rb +4 -4
  53. data/lib/spec/rails/version.rb +2 -2
  54. data/spec/resources/controllers/controller_spec_controller.rb +14 -6
  55. data/spec/resources/controllers/example.txt +1 -0
  56. data/spec/resources/controllers/redirect_spec_controller.rb +4 -0
  57. data/spec/resources/controllers/render_spec_controller.rb +1 -1
  58. data/spec/resources/controllers/rjs_spec_controller.rb +1 -1
  59. data/spec/resources/helpers/explicit_helper.rb +1 -1
  60. data/spec/resources/views/controller_spec/{_partial.rhtml → _partial.html.erb} +0 -0
  61. data/spec/resources/views/controller_spec/{action_setting_flash_after_session_reset.rhtml → action_setting_flash_after_session_reset.html.erb} +0 -0
  62. data/spec/resources/views/controller_spec/{action_setting_flash_before_session_reset.rhtml → action_setting_flash_before_session_reset.html.erb} +0 -0
  63. data/spec/resources/views/controller_spec/{action_setting_the_assigns_hash.rhtml → action_setting_the_assigns_hash.html.erb} +0 -0
  64. data/spec/resources/views/controller_spec/{action_with_errors_in_template.rhtml → action_with_errors_in_template.html.erb} +0 -0
  65. data/spec/resources/views/controller_spec/{action_with_template.rhtml → action_with_template.html.erb} +0 -0
  66. data/spec/resources/views/layouts/{application.rhtml → application.html.erb} +0 -0
  67. data/spec/resources/views/layouts/{simple.rhtml → simple.html.erb} +0 -0
  68. data/spec/resources/views/render_spec/{_a_partial.rhtml → _a_partial.html.erb} +0 -0
  69. data/spec/resources/views/render_spec/{action_with_alternate_layout.rhtml → action_with_alternate_layout.html.erb} +0 -0
  70. data/spec/resources/views/rjs_spec/{_replacement_partial.rhtml → _replacement_partial.html.erb} +0 -0
  71. data/spec/resources/views/rjs_spec/{hide_div.rjs → hide_div.js.rjs} +0 -0
  72. data/spec/resources/views/rjs_spec/{hide_page_element.rjs → hide_page_element.js.rjs} +0 -0
  73. data/spec/resources/views/rjs_spec/{insert_html.rjs → insert_html.js.rjs} +0 -0
  74. data/spec/resources/views/rjs_spec/{replace.rjs → replace.js.rjs} +0 -0
  75. data/spec/resources/views/rjs_spec/{replace_html.rjs → replace_html.js.rjs} +0 -0
  76. data/spec/resources/views/rjs_spec/{replace_html_with_partial.rjs → replace_html_with_partial.js.rjs} +0 -0
  77. data/spec/resources/views/rjs_spec/{visual_effect.rjs → visual_effect.js.rjs} +0 -0
  78. data/spec/resources/views/rjs_spec/{visual_toggle_effect.rjs → visual_toggle_effect.js.rjs} +0 -0
  79. data/spec/resources/views/tag_spec/{no_tags.rhtml → no_tags.html.erb} +0 -0
  80. data/spec/resources/views/tag_spec/{single_div_with_no_attributes.rhtml → single_div_with_no_attributes.html.erb} +0 -0
  81. data/spec/resources/views/tag_spec/{single_div_with_one_attribute.rhtml → single_div_with_one_attribute.html.erb} +0 -0
  82. data/spec/resources/views/view_spec/{_partial.rhtml → _partial.html.erb} +0 -0
  83. data/spec/resources/views/view_spec/{_partial_used_twice.rhtml → _partial_used_twice.html.erb} +0 -0
  84. data/spec/resources/views/view_spec/{_partial_with_local_variable.rhtml → _partial_with_local_variable.html.erb} +0 -0
  85. data/spec/resources/views/view_spec/{_partial_with_sub_partial.rhtml → _partial_with_sub_partial.html.erb} +0 -0
  86. data/spec/resources/views/view_spec/{_spacer.rhtml → _spacer.html.erb} +0 -0
  87. data/spec/resources/views/view_spec/{accessor.rhtml → accessor.html.erb} +0 -0
  88. data/spec/resources/views/view_spec/{block_helper.rhtml → block_helper.html.erb} +0 -0
  89. data/spec/resources/views/view_spec/{entry_form.rhtml → entry_form.html.erb} +0 -0
  90. data/spec/resources/views/view_spec/{explicit_helper.rhtml → explicit_helper.html.erb} +0 -0
  91. data/spec/resources/views/view_spec/foo/{show.rhtml → show.html.erb} +0 -0
  92. data/spec/resources/views/view_spec/{implicit_helper.rhtml → implicit_helper.html.erb} +0 -0
  93. data/spec/resources/views/view_spec/{multiple_helpers.rhtml → multiple_helpers.html.erb} +0 -0
  94. data/spec/resources/views/view_spec/{should_not_receive.rhtml → should_not_receive.html.erb} +0 -0
  95. data/spec/resources/views/view_spec/{template_with_partial.rhtml → template_with_partial.html.erb} +0 -0
  96. data/spec/resources/views/view_spec/{template_with_partial_using_collection.rhtml → template_with_partial_using_collection.html.erb} +0 -0
  97. data/spec/resources/views/view_spec/{template_with_partial_with_array.rhtml → template_with_partial_with_array.html.erb} +0 -0
  98. data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +18 -5
  99. data/spec/spec/rails/example/configuration_spec.rb +15 -29
  100. data/spec/spec/rails/example/{controller_spec_spec.rb → controller_example_group_spec.rb} +40 -96
  101. data/spec/spec/rails/example/cookies_proxy_spec.rb +32 -36
  102. data/spec/spec/rails/example/error_handling_spec.rb +90 -0
  103. data/spec/spec/rails/example/example_group_factory_spec.rb +5 -5
  104. data/spec/spec/rails/example/{helper_spec_spec.rb → helper_example_group_spec.rb} +45 -13
  105. data/spec/spec/rails/example/{model_spec_spec.rb → model_example_group_spec.rb} +3 -1
  106. data/spec/spec/rails/example/routing_example_group_spec.rb +9 -0
  107. data/spec/spec/rails/example/shared_routing_example_group_examples.rb +45 -0
  108. data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +1 -1
  109. data/spec/spec/rails/example/{view_spec_spec.rb → view_example_group_spec.rb} +44 -17
  110. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +10 -0
  111. data/spec/spec/rails/matchers/assert_select_spec.rb +59 -60
  112. data/spec/spec/rails/matchers/have_text_spec.rb +12 -4
  113. data/spec/spec/rails/matchers/include_text_spec.rb +11 -13
  114. data/spec/spec/rails/matchers/redirect_to_spec.rb +224 -189
  115. data/spec/spec/rails/matchers/render_template_spec.rb +169 -158
  116. data/spec/spec/rails/spec_server_spec.rb +18 -7
  117. data/spec/spec_helper.rb +21 -9
  118. metadata +68 -53
  119. data/lib/spec/rails/example/rails_example_group.rb +0 -28
  120. data/lib/spec/rails/extensions/action_controller/base.rb +0 -14
  121. data/rspec-rails.gemspec +0 -36
  122. data/spec/resources/views/render_spec/some_action.rjs +0 -1
  123. data/spec/spec/rails/example/shared_behaviour_spec.rb +0 -16
  124. data/spec/spec/rails/extensions/action_controller_rescue_action_spec.rb +0 -57
@@ -2,17 +2,25 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
3
  describe "have_text" do
4
4
 
5
+
6
+ it "should have a helpful description" do
7
+ matcher = have_text("foo bar")
8
+ matcher.description.should == 'have text "foo bar"'
9
+ end
10
+
5
11
  describe "where target is a Regexp" do
6
12
  it 'should should match submitted text using a regexp' do
7
- string = 'foo'
8
- string.should have_text(/fo*/)
13
+ matcher = have_text(/fo*/)
14
+ matcher.matches?('foo').should be_true
15
+ matcher.matches?('bar').should be_nil
9
16
  end
10
17
  end
11
18
 
12
19
  describe "where target is a String" do
13
20
  it 'should match submitted text using a string' do
14
- string = 'foo'
15
- string.should have_text('foo')
21
+ matcher = have_text('foo')
22
+ matcher.matches?('foo').should be_true
23
+ matcher.matches?('foo bar').should be_false
16
24
  end
17
25
  end
18
26
 
@@ -2,21 +2,19 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
3
  describe "include_text" do
4
4
 
5
- describe "where target is a String" do
6
- it 'should match submitted text using a string' do
7
- string = 'foo'
8
- string.should include_text('foo')
9
- end
5
+ it "should have a helpful description" do
6
+ matcher = include_text("foo bar")
7
+ matcher.description.should == 'include text "foo bar"'
8
+ end
10
9
 
11
- it 'should match if the text is contained' do
12
- string = 'I am a big piece of text'
13
- string.should include_text('big piece')
14
- end
10
+ it 'should match if the text is contained' do
11
+ matcher = include_text('big piece')
12
+ matcher.matches?('I am a big piece of text').should be_true
13
+ end
15
14
 
16
- it 'should not match if text is not contained' do
17
- string = 'I am a big piece of text'
18
- string.should_not include_text('corey')
19
- end
15
+ it 'should not match if text is not contained' do
16
+ matcher = include_text('foo bar')
17
+ matcher.matches?('hello world').should be_false
20
18
  end
21
19
 
22
20
  end
@@ -1,218 +1,253 @@
1
1
  require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
- ['isolation','integration'].each do |mode|
4
- describe "redirect_to behaviour", :type => :controller do
5
- if mode == 'integration'
6
- integrate_views
7
- end
8
- controller_name :redirect_spec
9
-
10
- it "redirected to another action" do
11
- get 'action_with_redirect_to_somewhere'
12
- response.should redirect_to(:action => 'somewhere')
13
- end
14
-
15
- it "redirected to another controller and action" do
16
- get 'action_with_redirect_to_other_somewhere'
17
- response.should redirect_to(:controller => 'render_spec', :action => 'text_action')
18
- end
19
-
20
- it "redirected to another action (with 'and return')" do
21
- get 'action_with_redirect_to_somewhere_and_return'
22
- response.should redirect_to(:action => 'somewhere')
23
- end
3
+ [:response, :controller].each do |subject_method|
4
+ ['isolation','integration'].each do |mode|
5
+ describe "redirect_to behaviour", :type => :controller do
6
+ if mode == 'integration'
7
+ integrate_views
8
+ end
9
+ controller_name :redirect_spec
10
+
11
+ subject { send(subject_method) }
12
+
13
+ it "redirected to another action" do
14
+ get 'action_with_redirect_to_somewhere'
15
+ should redirect_to(:action => 'somewhere')
16
+ end
17
+
18
+ it "redirected to another controller and action" do
19
+ get 'action_with_redirect_to_other_somewhere'
20
+ should redirect_to(:controller => 'render_spec', :action => 'text_action')
21
+ end
22
+
23
+ it "redirected to another action (with 'and return')" do
24
+ get 'action_with_redirect_to_somewhere_and_return'
25
+ should redirect_to(:action => 'somewhere')
26
+ end
27
+
28
+ it "redirected from an SSL action to a non-SSL action" do
29
+ request.stub!(:ssl?).and_return true
30
+ get 'action_with_redirect_to_somewhere'
31
+ should redirect_to(:action => 'somewhere')
32
+ end
24
33
 
25
- it "redirected from an SSL action to a non-SSL action" do
26
- request.stub!(:ssl?).and_return true
27
- get 'action_with_redirect_to_somewhere'
28
- response.should redirect_to(:action => 'somewhere')
29
- end
30
-
31
- it "redirected to correct path with leading /" do
32
- get 'action_with_redirect_to_somewhere'
33
- response.should redirect_to('/redirect_spec/somewhere')
34
- end
34
+ it "redirected to correct path with leading /" do
35
+ get 'action_with_redirect_to_somewhere'
36
+ should redirect_to('/redirect_spec/somewhere')
37
+ end
38
+
39
+ it "redirected to correct path without leading /" do
40
+ get 'action_with_redirect_to_somewhere'
41
+ should redirect_to('redirect_spec/somewhere')
42
+ end
43
+
44
+ it "redirected to correct internal URL" do
45
+ get 'action_with_redirect_to_somewhere'
46
+ should redirect_to("http://test.host/redirect_spec/somewhere")
47
+ end
35
48
 
36
- it "redirected to correct path without leading /" do
37
- get 'action_with_redirect_to_somewhere'
38
- response.should redirect_to('redirect_spec/somewhere')
39
- end
49
+ it "redirected to correct external URL" do
50
+ get 'action_with_redirect_to_rspec_site'
51
+ should redirect_to("http://rspec.rubyforge.org")
52
+ end
40
53
 
41
- it "redirected to correct internal URL" do
42
- get 'action_with_redirect_to_somewhere'
43
- response.should redirect_to("http://test.host/redirect_spec/somewhere")
44
- end
45
-
46
- it "redirected to correct external URL" do
47
- get 'action_with_redirect_to_rspec_site'
48
- response.should redirect_to("http://rspec.rubyforge.org")
49
- end
50
-
51
- it "redirected :back" do
52
- request.env['HTTP_REFERER'] = "http://test.host/previous/page"
53
- get 'action_with_redirect_back'
54
- response.should redirect_to(:back)
55
- end
56
-
57
- it "redirected :back and should redirect_to URL matches" do
58
- request.env['HTTP_REFERER'] = "http://test.host/previous/page"
59
- get 'action_with_redirect_back'
60
- response.should redirect_to("http://test.host/previous/page")
61
- end
54
+ it "redirected :back" do
55
+ request.env['HTTP_REFERER'] = "http://test.host/previous/page"
56
+ get 'action_with_redirect_back'
57
+ should redirect_to(:back)
58
+ end
62
59
 
63
- it "redirected from within a respond_to block" do
64
- get 'action_with_redirect_in_respond_to'
65
- response.should redirect_to('redirect_spec/somewhere')
66
- end
60
+ it "redirected :back and should redirect_to URL matches" do
61
+ request.env['HTTP_REFERER'] = "http://test.host/previous/page"
62
+ get 'action_with_redirect_back'
63
+ should redirect_to("http://test.host/previous/page")
64
+ end
65
+
66
+ it "redirected from within a respond_to block" do
67
+ get 'action_with_redirect_in_respond_to'
68
+ should redirect_to('redirect_spec/somewhere')
69
+ end
67
70
 
68
- params_as_hash = {:action => "somewhere", :id => 1111, :param1 => "value1", :param2 => "value2"}
71
+ params_as_hash = {:action => "somewhere", :id => 1111, :param1 => "value1", :param2 => "value2"}
69
72
 
70
- it "redirected to an internal URL containing a query string" do
71
- get "action_with_redirect_which_creates_query_string"
72
- response.should redirect_to(params_as_hash)
73
- end
73
+ it "redirected to an internal URL containing a query string" do
74
+ get "action_with_redirect_which_creates_query_string"
75
+ should redirect_to(params_as_hash)
76
+ end
74
77
 
75
- it "redirected to an internal URL containing a query string, one way it might be generated" do
76
- get "action_with_redirect_with_query_string_order1"
77
- response.should redirect_to(params_as_hash)
78
- end
78
+ it "redirected to an internal URL containing a query string, one way it might be generated" do
79
+ get "action_with_redirect_with_query_string_order1"
80
+ should redirect_to(params_as_hash)
81
+ end
79
82
 
80
- it "redirected to an internal URL containing a query string, another way it might be generated" do
81
- get "action_with_redirect_with_query_string_order2"
82
- response.should redirect_to(params_as_hash)
83
- end
83
+ it "redirected to an internal URL containing a query string, another way it might be generated" do
84
+ get "action_with_redirect_with_query_string_order2"
85
+ should redirect_to(params_as_hash)
86
+ end
84
87
 
85
- it "redirected to an internal URL which is unroutable but matched via a string" do
86
- get "action_with_redirect_to_unroutable_url_inside_app"
87
- response.should redirect_to("http://test.host/nonexistant/none")
88
- end
88
+ it "redirected to an internal URL which is unroutable but matched via a string" do
89
+ get "action_with_redirect_to_unroutable_url_inside_app"
90
+ should redirect_to("http://test.host/nonexistant/none")
91
+ end
89
92
 
90
- end
93
+ it "redirected to a URL with a specific status code" do
94
+ get "action_with_redirect_to_somewhere_with_status"
95
+ should redirect_to(:action => 'somewhere').with(:status => 301)
96
+ end
97
+
98
+ it "redirected to a URL with a specific status code (using names)" do
99
+ get "action_with_redirect_to_somewhere_with_status"
100
+ should redirect_to(:action => 'somewhere').with(:status => :moved_permanently)
101
+ end
91
102
 
92
-
93
- describe "redirect_to with a controller spec in #{mode} mode and a custom request.host", :type => :controller do
94
- if mode == 'integration'
95
- integrate_views
96
- end
97
- controller_name :redirect_spec
98
- before do
99
- request.host = "some.custom.host"
100
- end
101
-
102
- it "should pass when redirected to another action" do
103
- get 'action_with_redirect_to_somewhere'
104
- response.should redirect_to(:action => 'somewhere')
105
- end
106
- end
107
-
108
- describe "Given a controller spec in #{mode} mode", :type => :controller do
109
- if mode == 'integration'
110
- integrate_views
111
- end
112
- controller_name :redirect_spec
113
-
114
- it "an action that redirects should not result in an error if no should redirect_to expectation is called" do
115
- get 'action_with_redirect_to_somewhere'
116
103
  end
104
+
117
105
 
118
- it "an action that redirects should not result in an error if should_not redirect_to expectation was called, but not to that action" do
119
- get 'action_with_redirect_to_somewhere'
120
- response.should_not redirect_to(:action => 'another_destination')
121
- end
106
+ describe "redirect_to with a controller spec in #{mode} mode and a custom request.host", :type => :controller do
107
+ if mode == 'integration'
108
+ integrate_views
109
+ end
110
+ controller_name :redirect_spec
122
111
 
123
- it "an action that redirects should result in an error if should_not redirect_to expectation was called to that action" do
124
- get 'action_with_redirect_to_somewhere'
125
- lambda {
126
- response.should_not redirect_to(:action => 'somewhere')
127
- }.should fail_with("expected not to be redirected to {:action=>\"somewhere\"}, but was")
112
+ subject { send(subject_method) }
113
+
114
+ before do
115
+ request.host = "some.custom.host"
116
+ end
117
+
118
+ it "should pass when redirected to another action" do
119
+ get 'action_with_redirect_to_somewhere'
120
+ should redirect_to(:action => 'somewhere')
121
+ end
128
122
  end
123
+
124
+ describe "Given a controller spec in #{mode} mode", :type => :controller do
125
+ if mode == 'integration'
126
+ integrate_views
127
+ end
128
+ controller_name :redirect_spec
129
+
130
+ subject { send(subject_method) }
131
+
132
+ it "an action that redirects should not result in an error if no should redirect_to expectation is called" do
133
+ get 'action_with_redirect_to_somewhere'
134
+ end
135
+
136
+ it "an action that redirects should not result in an error if should_not redirect_to expectation was called, but not to that action" do
137
+ get 'action_with_redirect_to_somewhere'
138
+ should_not redirect_to(:action => 'another_destination')
139
+ end
129
140
 
130
- it "an action that does not redirects should not result in an error if should_not redirect_to expectation was called" do
131
- get 'action_with_no_redirect'
132
- response.should_not redirect_to(:action => 'any_destination')
141
+ it "an action that redirects should result in an error if should_not redirect_to expectation was called to that action" do
142
+ get 'action_with_redirect_to_somewhere'
143
+ lambda {
144
+ should_not redirect_to(:action => 'somewhere')
145
+ }.should fail_with("expected not to be redirected to {:action=>\"somewhere\"}, but was")
146
+ end
147
+
148
+ it "an action that does not redirects should not result in an error if should_not redirect_to expectation was called" do
149
+ get 'action_with_no_redirect'
150
+ should_not redirect_to(:action => 'any_destination')
151
+ end
152
+
153
+
133
154
  end
155
+
156
+ describe "Given a controller spec in #{mode} mode, should redirect_to should fail when", :type => :controller do
157
+ if mode == 'integration'
158
+ integrate_views
159
+ end
160
+ controller_name :redirect_spec
161
+
162
+ subject { send(subject_method) }
134
163
 
164
+ it "redirected to wrong action" do
165
+ get 'action_with_redirect_to_somewhere'
166
+ lambda {
167
+ should redirect_to(:action => 'somewhere_else')
168
+ }.should fail_with("expected redirect to {:action=>\"somewhere_else\"}, got redirect to \"http://test.host/redirect_spec/somewhere\"")
169
+ end
170
+
171
+ it "redirected with wrong status code" do
172
+ get 'action_with_redirect_to_somewhere_with_status'
173
+ lambda {
174
+ should redirect_to(:action => 'somewhere').with(:status => 302)
175
+ }.should fail_with("expected redirect to {:action=>\"somewhere\"} with status 302 Found, got 301 Moved Permanently")
176
+ end
177
+
178
+ it "redirected with wrong status code (using names)" do
179
+ get 'action_with_redirect_to_somewhere_with_status'
180
+ lambda {
181
+ should redirect_to(:action => 'somewhere').with(:status => :found)
182
+ }.should fail_with("expected redirect to {:action=>\"somewhere\"} with status 302 Found, got 301 Moved Permanently")
183
+ end
184
+
185
+ it "redirected to incorrect path with leading /" do
186
+ get 'action_with_redirect_to_somewhere'
187
+ lambda {
188
+ should redirect_to('/redirect_spec/somewhere_else')
189
+ }.should fail_with('expected redirect to "/redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
190
+ end
135
191
 
136
- end
137
-
138
- describe "Given a controller spec in #{mode} mode, should redirect_to should fail when", :type => :controller do
139
- if mode == 'integration'
140
- integrate_views
141
- end
142
- controller_name :redirect_spec
192
+ it "redirected to incorrect path without leading /" do
193
+ get 'action_with_redirect_to_somewhere'
194
+ lambda {
195
+ should redirect_to('redirect_spec/somewhere_else')
196
+ }.should fail_with('expected redirect to "redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
197
+ end
143
198
 
144
- it "redirected to wrong action" do
145
- get 'action_with_redirect_to_somewhere'
146
- lambda {
147
- response.should redirect_to(:action => 'somewhere_else')
148
- }.should fail_with("expected redirect to {:action=>\"somewhere_else\"}, got redirect to \"http://test.host/redirect_spec/somewhere\"")
149
- end
199
+ it "redirected to incorrect internal URL (based on the action)" do
200
+ get 'action_with_redirect_to_somewhere'
201
+ lambda {
202
+ should redirect_to("http://test.host/redirect_spec/somewhere_else")
203
+ }.should fail_with('expected redirect to "http://test.host/redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
204
+ end
205
+
206
+ it "redirected to wrong external URL" do
207
+ get 'action_with_redirect_to_rspec_site'
208
+ lambda {
209
+ should redirect_to("http://test.unit.rubyforge.org")
210
+ }.should fail_with('expected redirect to "http://test.unit.rubyforge.org", got redirect to "http://rspec.rubyforge.org"')
211
+ end
150
212
 
151
- it "redirected to incorrect path with leading /" do
152
- get 'action_with_redirect_to_somewhere'
153
- lambda {
154
- response.should redirect_to('/redirect_spec/somewhere_else')
155
- }.should fail_with('expected redirect to "/redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
156
- end
157
-
158
- it "redirected to incorrect path without leading /" do
159
- get 'action_with_redirect_to_somewhere'
160
- lambda {
161
- response.should redirect_to('redirect_spec/somewhere_else')
162
- }.should fail_with('expected redirect to "redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
163
- end
164
-
165
- it "redirected to incorrect internal URL (based on the action)" do
166
- get 'action_with_redirect_to_somewhere'
167
- lambda {
168
- response.should redirect_to("http://test.host/redirect_spec/somewhere_else")
169
- }.should fail_with('expected redirect to "http://test.host/redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
170
- end
213
+ it "redirected to incorrect internal URL (based on the directory path)" do
214
+ get 'action_with_redirect_to_somewhere'
215
+ lambda {
216
+ should redirect_to("http://test.host/non_existent_controller/somewhere")
217
+ }.should fail_with('expected redirect to "http://test.host/non_existent_controller/somewhere", got redirect to "http://test.host/redirect_spec/somewhere"')
218
+ end
171
219
 
172
- it "redirected to wrong external URL" do
173
- get 'action_with_redirect_to_rspec_site'
174
- lambda {
175
- response.should redirect_to("http://test.unit.rubyforge.org")
176
- }.should fail_with('expected redirect to "http://test.unit.rubyforge.org", got redirect to "http://rspec.rubyforge.org"')
177
- end
178
-
179
- it "redirected to incorrect internal URL (based on the directory path)" do
180
- get 'action_with_redirect_to_somewhere'
181
- lambda {
182
- response.should redirect_to("http://test.host/non_existent_controller/somewhere")
183
- }.should fail_with('expected redirect to "http://test.host/non_existent_controller/somewhere", got redirect to "http://test.host/redirect_spec/somewhere"')
184
- end
185
-
186
- it "expected redirect :back, but redirected to a new URL" do
187
- get 'action_with_no_redirect'
188
- lambda {
189
- response.should redirect_to(:back)
190
- }.should fail_with('expected redirect to :back, got no redirect')
191
- end
192
-
193
- it "no redirect at all" do
194
- get 'action_with_no_redirect'
195
- lambda {
196
- response.should redirect_to(:action => 'nowhere')
197
- }.should fail_with("expected redirect to {:action=>\"nowhere\"}, got no redirect")
198
- end
199
-
200
- it "redirected to an internal URL which is unroutable and matched via a hash" do
201
- get "action_with_redirect_to_unroutable_url_inside_app"
202
- route = {:controller => "nonexistant", :action => "none"}
203
- lambda {
204
- response.should redirect_to(route)
205
- }.should raise_error(ActionController::RoutingError, /(no route found to match|No route matches) \"\/nonexistant\/none\" with \{.*\}/)
206
- end
220
+ it "expected redirect :back, but redirected to a new URL" do
221
+ get 'action_with_no_redirect'
222
+ lambda {
223
+ should redirect_to(:back)
224
+ }.should fail_with('expected redirect to :back, got no redirect')
225
+ end
207
226
 
208
- it "provides a description" do
209
- redirect_to("foo/bar").description.should == %q|redirect to "foo/bar"|
210
- end
227
+ it "no redirect at all" do
228
+ get 'action_with_no_redirect'
229
+ lambda {
230
+ should redirect_to(:action => 'nowhere')
231
+ }.should fail_with("expected redirect to {:action=>\"nowhere\"}, got no redirect")
232
+ end
233
+
234
+ it "redirected to an internal URL which is unroutable and matched via a hash" do
235
+ get "action_with_redirect_to_unroutable_url_inside_app"
236
+ route = {:controller => "nonexistant", :action => "none"}
237
+ lambda {
238
+ should redirect_to(route)
239
+ }.should raise_error(ActionController::RoutingError, /(no route found to match|No route matches) \"\/nonexistant\/none\" with \{.*\}/)
240
+ end
241
+
242
+ it "provides a description" do
243
+ redirect_to("foo/bar").description.should == %q|redirect to "foo/bar"|
244
+ end
211
245
 
212
- it "redirects to action with http method restriction" do
213
- post 'action_to_redirect_to_action_with_method_restriction'
214
- response.should redirect_to(:action => 'action_with_method_restriction')
215
- end
246
+ it "redirects to action with http method restriction" do
247
+ post 'action_to_redirect_to_action_with_method_restriction'
248
+ should redirect_to(:action => 'action_with_method_restriction')
249
+ end
216
250
 
251
+ end
217
252
  end
218
253
  end