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.
- data/History.txt +29 -2
- data/License.txt +1 -1
- data/Manifest.txt +7 -6
- data/README.txt +5 -4
- data/Rakefile +14 -2
- data/TODO.txt +1 -0
- data/Upgrade.txt +30 -0
- data/generators/rspec/templates/rspec.rake +12 -10
- data/generators/rspec/templates/script/spec_server +10 -111
- data/generators/rspec_controller/rspec_controller_generator.rb +1 -5
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +9 -13
- data/generators/rspec_scaffold/templates/controller_spec.rb +25 -25
- data/generators/rspec_scaffold/templates/edit_erb_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/helper_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/index_erb_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/new_erb_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/routing_spec.rb +24 -20
- data/generators/rspec_scaffold/templates/show_erb_spec.rb +1 -1
- data/lib/spec/rails/example/controller_example_group.rb +46 -16
- data/lib/spec/rails/example/functional_example_group.rb +7 -22
- data/lib/spec/rails/example/helper_example_group.rb +6 -9
- data/lib/spec/rails/example/model_example_group.rb +1 -1
- data/lib/spec/rails/example/render_observer.rb +0 -26
- data/lib/spec/rails/example/view_example_group.rb +32 -34
- data/lib/spec/rails/example.rb +0 -2
- data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
- data/lib/spec/rails/extensions/spec/runner/configuration.rb +12 -44
- data/lib/spec/rails/extensions.rb +1 -1
- data/lib/spec/rails/matchers/ar_be_valid.rb +3 -0
- data/lib/spec/rails/matchers/have_text.rb +1 -1
- data/lib/spec/rails/matchers/include_text.rb +2 -2
- data/lib/spec/rails/matchers/redirect_to.rb +6 -14
- data/lib/spec/rails/matchers/render_template.rb +5 -1
- data/lib/spec/rails/spec_server.rb +86 -0
- data/lib/spec/rails/version.rb +2 -2
- data/lib/spec/rails.rb +10 -9
- data/rspec-rails.gemspec +12 -9
- data/spec/resources/controllers/controller_spec_controller.rb +1 -1
- data/spec/resources/controllers/render_spec_controller.rb +1 -1
- data/spec/resources/controllers/rjs_spec_controller.rb +1 -1
- data/spec/spec/rails/example/configuration_spec.rb +15 -29
- data/spec/spec/rails/example/{controller_spec_spec.rb → controller_example_group_spec.rb} +84 -60
- data/spec/spec/rails/example/cookies_proxy_spec.rb +32 -36
- data/spec/spec/rails/example/example_group_factory_spec.rb +5 -5
- data/spec/spec/rails/example/{helper_spec_spec.rb → helper_example_group_spec.rb} +8 -2
- data/spec/spec/rails/example/{model_spec_spec.rb → model_example_group_spec.rb} +3 -1
- data/spec/spec/rails/example/{view_spec_spec.rb → view_example_group_spec.rb} +33 -15
- data/spec/spec/rails/matchers/ar_be_valid_spec.rb +10 -0
- data/spec/spec/rails/matchers/assert_select_spec.rb +1 -0
- data/spec/spec/rails/matchers/have_text_spec.rb +12 -4
- data/spec/spec/rails/matchers/include_text_spec.rb +11 -13
- data/spec/spec/rails/matchers/redirect_to_spec.rb +221 -210
- data/spec/spec/rails/matchers/render_template_spec.rb +161 -158
- data/spec/spec/rails/spec_server_spec.rb +18 -7
- data/spec/spec_helper.rb +20 -9
- metadata +21 -10
- data/lib/spec/rails/example/rails_example_group.rb +0 -28
- 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
|
-
[
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
71
|
+
params_as_hash = {:action => "somewhere", :id => 1111, :param1 => "value1", :param2 => "value2"}
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
112
|
+
subject { send(subject_method) }
|
101
113
|
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
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
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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
|
-
|
233
|
-
|
234
|
-
|
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
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
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
|