dchelimsky-rspec-rails 1.1.12 → 1.1.99.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/History.txt +29 -2
  2. data/License.txt +1 -1
  3. data/Manifest.txt +7 -6
  4. data/README.txt +5 -4
  5. data/Rakefile +14 -2
  6. data/TODO.txt +1 -0
  7. data/Upgrade.txt +30 -0
  8. data/generators/rspec/templates/rspec.rake +12 -10
  9. data/generators/rspec/templates/script/spec_server +10 -111
  10. data/generators/rspec_controller/rspec_controller_generator.rb +1 -5
  11. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +9 -13
  12. data/generators/rspec_scaffold/templates/controller_spec.rb +25 -25
  13. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +1 -1
  14. data/generators/rspec_scaffold/templates/helper_spec.rb +1 -1
  15. data/generators/rspec_scaffold/templates/index_erb_spec.rb +1 -1
  16. data/generators/rspec_scaffold/templates/new_erb_spec.rb +1 -1
  17. data/generators/rspec_scaffold/templates/routing_spec.rb +24 -20
  18. data/generators/rspec_scaffold/templates/show_erb_spec.rb +1 -1
  19. data/lib/spec/rails/example/controller_example_group.rb +46 -16
  20. data/lib/spec/rails/example/functional_example_group.rb +7 -22
  21. data/lib/spec/rails/example/helper_example_group.rb +6 -9
  22. data/lib/spec/rails/example/model_example_group.rb +1 -1
  23. data/lib/spec/rails/example/render_observer.rb +0 -26
  24. data/lib/spec/rails/example/view_example_group.rb +32 -34
  25. data/lib/spec/rails/example.rb +0 -2
  26. data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
  27. data/lib/spec/rails/extensions/spec/runner/configuration.rb +12 -44
  28. data/lib/spec/rails/extensions.rb +1 -1
  29. data/lib/spec/rails/matchers/ar_be_valid.rb +3 -0
  30. data/lib/spec/rails/matchers/have_text.rb +1 -1
  31. data/lib/spec/rails/matchers/include_text.rb +2 -2
  32. data/lib/spec/rails/matchers/redirect_to.rb +6 -14
  33. data/lib/spec/rails/matchers/render_template.rb +5 -1
  34. data/lib/spec/rails/spec_server.rb +86 -0
  35. data/lib/spec/rails/version.rb +2 -2
  36. data/lib/spec/rails.rb +10 -9
  37. data/rspec-rails.gemspec +12 -9
  38. data/spec/resources/controllers/controller_spec_controller.rb +1 -1
  39. data/spec/resources/controllers/render_spec_controller.rb +1 -1
  40. data/spec/resources/controllers/rjs_spec_controller.rb +1 -1
  41. data/spec/spec/rails/example/configuration_spec.rb +15 -29
  42. data/spec/spec/rails/example/{controller_spec_spec.rb → controller_example_group_spec.rb} +84 -60
  43. data/spec/spec/rails/example/cookies_proxy_spec.rb +32 -36
  44. data/spec/spec/rails/example/example_group_factory_spec.rb +5 -5
  45. data/spec/spec/rails/example/{helper_spec_spec.rb → helper_example_group_spec.rb} +8 -2
  46. data/spec/spec/rails/example/{model_spec_spec.rb → model_example_group_spec.rb} +3 -1
  47. data/spec/spec/rails/example/{view_spec_spec.rb → view_example_group_spec.rb} +33 -15
  48. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +10 -0
  49. data/spec/spec/rails/matchers/assert_select_spec.rb +1 -0
  50. data/spec/spec/rails/matchers/have_text_spec.rb +12 -4
  51. data/spec/spec/rails/matchers/include_text_spec.rb +11 -13
  52. data/spec/spec/rails/matchers/redirect_to_spec.rb +221 -210
  53. data/spec/spec/rails/matchers/render_template_spec.rb +161 -158
  54. data/spec/spec/rails/spec_server_spec.rb +18 -7
  55. data/spec/spec_helper.rb +20 -9
  56. metadata +21 -10
  57. data/lib/spec/rails/example/rails_example_group.rb +0 -28
  58. data/lib/spec/rails/extensions/action_controller/base.rb +0 -14
@@ -1,242 +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
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
19
33
 
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
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
24
48
 
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
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
35
53
 
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
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
40
59
 
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
62
-
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
92
+
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
89
102
 
90
- it "redirected to a URL with a specific status code" do
91
- get "action_with_redirect_to_somewhere_with_status"
92
- response.should redirect_to(:action => 'somewhere').with(:status => 301)
93
103
  end
104
+
94
105
 
95
- it "redirected to a URL with a specific status code (using names)" do
96
- get "action_with_redirect_to_somewhere_with_status"
97
- response.should redirect_to(:action => 'somewhere').with(:status => :moved_permanently)
98
- 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
99
111
 
100
- end
112
+ subject { send(subject_method) }
101
113
 
102
-
103
- describe "redirect_to with a controller spec in #{mode} mode and a custom request.host", :type => :controller do
104
- if mode == 'integration'
105
- integrate_views
106
- end
107
- controller_name :redirect_spec
108
- before do
109
- request.host = "some.custom.host"
110
- end
111
-
112
- it "should pass when redirected to another action" do
113
- get 'action_with_redirect_to_somewhere'
114
- response.should redirect_to(:action => 'somewhere')
115
- end
116
- end
117
-
118
- describe "Given a controller spec in #{mode} mode", :type => :controller do
119
- if mode == 'integration'
120
- integrate_views
121
- end
122
- controller_name :redirect_spec
123
-
124
- it "an action that redirects should not result in an error if no should redirect_to expectation is called" do
125
- get 'action_with_redirect_to_somewhere'
126
- end
114
+ before do
115
+ request.host = "some.custom.host"
116
+ end
127
117
 
128
- 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
129
- get 'action_with_redirect_to_somewhere'
130
- response.should_not redirect_to(:action => 'another_destination')
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
131
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) }
132
131
 
133
- it "an action that redirects should result in an error if should_not redirect_to expectation was called to that action" do
134
- get 'action_with_redirect_to_somewhere'
135
- lambda {
136
- response.should_not redirect_to(:action => 'somewhere')
137
- }.should fail_with("expected not to be redirected to {:action=>\"somewhere\"}, but was")
138
- end
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
139
140
 
140
- it "an action that does not redirects should not result in an error if should_not redirect_to expectation was called" do
141
- get 'action_with_no_redirect'
142
- response.should_not redirect_to(:action => 'any_destination')
143
- end
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
144
147
 
145
-
146
- end
147
-
148
- describe "Given a controller spec in #{mode} mode, should redirect_to should fail when", :type => :controller do
149
- if mode == 'integration'
150
- integrate_views
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
+
151
154
  end
152
- controller_name :redirect_spec
153
155
 
154
- it "redirected to wrong action" do
155
- get 'action_with_redirect_to_somewhere'
156
- lambda {
157
- response.should redirect_to(:action => 'somewhere_else')
158
- }.should fail_with("expected redirect to {:action=>\"somewhere_else\"}, got redirect to \"http://test.host/redirect_spec/somewhere\"")
159
- end
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) }
160
163
 
161
- it "redirected with wrong status code" do
162
- get 'action_with_redirect_to_somewhere_with_status'
163
- lambda {
164
- response.should redirect_to(:action => 'somewhere').with(:status => 302)
165
- }.should fail_with("expected redirect to {:action=>\"somewhere\"} with status 302 Found, got 301 Moved Permanently")
166
- end
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
167
191
 
168
- it "redirected with wrong status code (using names)" do
169
- get 'action_with_redirect_to_somewhere_with_status'
170
- lambda {
171
- response.should redirect_to(:action => 'somewhere').with(:status => :found)
172
- }.should fail_with("expected redirect to {:action=>\"somewhere\"} with status 302 Found, got 301 Moved Permanently")
173
- end
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
174
198
 
175
- it "redirected to incorrect path with leading /" do
176
- get 'action_with_redirect_to_somewhere'
177
- lambda {
178
- response.should redirect_to('/redirect_spec/somewhere_else')
179
- }.should fail_with('expected redirect to "/redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
180
- end
181
-
182
- it "redirected to incorrect path without leading /" do
183
- get 'action_with_redirect_to_somewhere'
184
- lambda {
185
- response.should redirect_to('redirect_spec/somewhere_else')
186
- }.should fail_with('expected redirect to "redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
187
- end
188
-
189
- it "redirected to incorrect internal URL (based on the action)" do
190
- get 'action_with_redirect_to_somewhere'
191
- lambda {
192
- response.should redirect_to("http://test.host/redirect_spec/somewhere_else")
193
- }.should fail_with('expected redirect to "http://test.host/redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
194
- 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
195
212
 
196
- it "redirected to wrong external URL" do
197
- get 'action_with_redirect_to_rspec_site'
198
- lambda {
199
- response.should redirect_to("http://test.unit.rubyforge.org")
200
- }.should fail_with('expected redirect to "http://test.unit.rubyforge.org", got redirect to "http://rspec.rubyforge.org"')
201
- end
202
-
203
- it "redirected to incorrect internal URL (based on the directory path)" do
204
- get 'action_with_redirect_to_somewhere'
205
- lambda {
206
- response.should redirect_to("http://test.host/non_existent_controller/somewhere")
207
- }.should fail_with('expected redirect to "http://test.host/non_existent_controller/somewhere", got redirect to "http://test.host/redirect_spec/somewhere"')
208
- end
209
-
210
- it "expected redirect :back, but redirected to a new URL" do
211
- get 'action_with_no_redirect'
212
- lambda {
213
- response.should redirect_to(:back)
214
- }.should fail_with('expected redirect to :back, got no redirect')
215
- end
216
-
217
- it "no redirect at all" do
218
- get 'action_with_no_redirect'
219
- lambda {
220
- response.should redirect_to(:action => 'nowhere')
221
- }.should fail_with("expected redirect to {:action=>\"nowhere\"}, got no redirect")
222
- end
223
-
224
- it "redirected to an internal URL which is unroutable and matched via a hash" do
225
- get "action_with_redirect_to_unroutable_url_inside_app"
226
- route = {:controller => "nonexistant", :action => "none"}
227
- lambda {
228
- response.should redirect_to(route)
229
- }.should raise_error(ActionController::RoutingError, /(no route found to match|No route matches) \"\/nonexistant\/none\" with \{.*\}/)
230
- 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
231
219
 
232
- it "provides a description" do
233
- redirect_to("foo/bar").description.should == %q|redirect to "foo/bar"|
234
- 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
226
+
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
235
245
 
236
- it "redirects to action with http method restriction" do
237
- post 'action_to_redirect_to_action_with_method_restriction'
238
- response.should redirect_to(:action => 'action_with_method_restriction')
239
- 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
240
250
 
251
+ end
241
252
  end
242
253
  end