rspec-rails 3.0.0.beta1 → 3.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/Changelog.md +46 -0
- data/README.md +19 -17
- data/features/Generators.md +1 -0
- data/features/README.md +7 -15
- data/features/controller_specs/anonymous_controller.feature +222 -164
- data/lib/generators/rspec/feature/feature_generator.rb +15 -0
- data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +0 -6
- data/lib/generators/rspec/integration/integration_generator.rb +0 -11
- data/lib/generators/rspec/integration/templates/request_spec.rb +0 -5
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +0 -8
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +4 -4
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +0 -9
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +0 -7
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +0 -9
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +0 -7
- data/lib/rspec/rails.rb +1 -1
- data/lib/rspec/rails/adapters.rb +18 -15
- data/lib/rspec/rails/example/controller_example_group.rb +18 -9
- data/lib/rspec/rails/example/view_example_group.rb +3 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +2 -2
- data/lib/rspec/rails/matchers/be_valid.rb +10 -3
- data/lib/rspec/rails/matchers/have_rendered.rb +2 -2
- data/lib/rspec/rails/matchers/redirect_to.rb +2 -2
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +7 -3
- data/lib/rspec/rails/mocks.rb +50 -26
- data/lib/rspec/rails/vendor/capybara.rb +4 -4
- data/lib/rspec/rails/version.rb +1 -1
- data/spec/generators/rspec/controller/controller_generator_spec.rb +16 -16
- data/spec/generators/rspec/feature/feature_generator_spec.rb +43 -0
- data/spec/generators/rspec/helper/helper_generator_spec.rb +4 -4
- data/spec/generators/rspec/install/install_generator_spec.rb +4 -4
- data/spec/generators/rspec/integration/integration_generator_spec.rb +8 -20
- data/spec/generators/rspec/mailer/mailer_generator_spec.rb +11 -11
- data/spec/generators/rspec/model/model_generator_spec.rb +7 -7
- data/spec/generators/rspec/observer/observer_generator_spec.rb +3 -3
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +34 -34
- data/spec/generators/rspec/view/view_generator_spec.rb +6 -6
- data/spec/rspec/rails/assertion_adapter_spec.rb +3 -3
- data/spec/rspec/rails/configuration_spec.rb +2 -2
- data/spec/rspec/rails/deprecations_spec.rb +1 -1
- data/spec/rspec/rails/example/controller_example_group_spec.rb +79 -20
- data/spec/rspec/rails/example/feature_example_group_spec.rb +2 -2
- data/spec/rspec/rails/example/helper_example_group_spec.rb +12 -12
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +3 -3
- data/spec/rspec/rails/example/model_example_group_spec.rb +3 -3
- data/spec/rspec/rails/example/request_example_group_spec.rb +5 -5
- data/spec/rspec/rails/example/routing_example_group_spec.rb +5 -5
- data/spec/rspec/rails/example/view_example_group_spec.rb +44 -29
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +3 -3
- data/spec/rspec/rails/fixture_support_spec.rb +3 -3
- data/spec/rspec/rails/matchers/be_a_new_spec.rb +17 -17
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +2 -2
- data/spec/rspec/rails/matchers/be_routable_spec.rb +8 -8
- data/spec/rspec/rails/matchers/be_valid_spec.rb +33 -4
- data/spec/rspec/rails/matchers/has_spec.rb +1 -1
- data/spec/rspec/rails/matchers/have_rendered_spec.rb +3 -3
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +7 -6
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +6 -6
- data/spec/rspec/rails/matchers/route_to_spec.rb +21 -21
- data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +9 -0
- data/spec/rspec/rails/mocks/mock_model_spec.rb +95 -73
- data/spec/rspec/rails/mocks/stub_model_spec.rb +23 -23
- data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +4 -4
- data/spec/rspec/rails/view_rendering_spec.rb +14 -14
- data/spec/spec_helper.rb +3 -5
- data/spec/support/helpers.rb +15 -1
- metadata +112 -46
- metadata.gz.sig +0 -0
- checksums.yaml +0 -15
- checksums.yaml.gz.sig +0 -2
data.tar.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
### 3.0.0.beta2 / 2014-02-17
|
2
|
+
[full changelog](http://github.com/rspec/rspec-rails/compare/v3.0.0.beta1...v3.0.0.beta2)
|
3
|
+
|
4
|
+
Bug fixes
|
5
|
+
|
6
|
+
* Use `__send__` rather than `send` to prevent naming collisions (Bradley Schaefer)
|
7
|
+
* Supports Rails 4.1. (Andy Lindeman)
|
8
|
+
* Routes are drawn correctly for anonymous controllers with abstract
|
9
|
+
parents. (Billy Chan)
|
10
|
+
* Loads ActiveSupport properly to support changes in Rails 4.1. (Andy Lindeman)
|
11
|
+
* Anonymous controllers inherit from `ActionController::Base` if `ApplicationController`
|
12
|
+
is not present. (Jon Rowe)
|
13
|
+
* Require `rspec/collection_matchers` when `rspec/rails` is required. (Yuji Nakayama)
|
14
|
+
|
15
|
+
Enhancements
|
16
|
+
|
17
|
+
* Improve be_valid matcher for non-ActiveModel::Errors implementations (Ben Hamill)
|
18
|
+
|
19
|
+
Breaking Changes for 3.0.0:
|
20
|
+
|
21
|
+
* Removes the `--webrat` option for the request spec generator (Andy Lindeman)
|
22
|
+
* Methods from `Capybara::DSL` (e.g., `visit`) are no longer available in
|
23
|
+
controller specs. It is more appropriate to use capybara in feature specs
|
24
|
+
(`spec/features`) instead. (Andy Lindeman)
|
25
|
+
* `infer_base_class_for_anonymous_controllers` is
|
26
|
+
enabled by default. (Thomas Holmes)
|
27
|
+
* Capybara 2.2.0 or above is required for feature specs. (Andy Lindeman)
|
28
|
+
|
1
29
|
### 3.0.0.beta1 / 2013-11-07
|
2
30
|
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.99.0.beta1...v3.0.0.beta1)
|
3
31
|
|
@@ -6,6 +34,24 @@ Breaking Changes for 3.0.0:
|
|
6
34
|
* Extracts `autotest` and `autotest-rails` support to `rspec-autotest` gem.
|
7
35
|
(Andy Lindeman)
|
8
36
|
|
37
|
+
### 2.99.0.beta2 / 2014-02-17
|
38
|
+
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.99.0.beta1...v2.99.0.beta2)
|
39
|
+
|
40
|
+
Bug fixes
|
41
|
+
|
42
|
+
* Use `__send__` rather than `send` to prevent naming collisions (Bradley Schaefer)
|
43
|
+
* Supports Rails 4.1. (Andy Lindeman)
|
44
|
+
* Loads ActiveSupport properly to support changes in Rails 4.1. (Andy Lindeman)
|
45
|
+
* Anonymous controllers inherit from `ActionController::Base` if `ApplicationController`
|
46
|
+
is not present. (Jon Rowe)
|
47
|
+
|
48
|
+
Deprecations
|
49
|
+
|
50
|
+
* Deprecates the `--webrat` option to the scaffold and request spec generator (Andy Lindeman)
|
51
|
+
* Deprecates the use of `Capybara::DSL` (e.g., `visit`) in controller specs.
|
52
|
+
It is more appropriate to use capybara in feature specs (`spec/features`)
|
53
|
+
instead. (Andy Lindeman)
|
54
|
+
|
9
55
|
### 2.99.0.beta1 / 2013-11-07
|
10
56
|
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.14.0...v2.99.0.beta1)
|
11
57
|
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Add `rspec-rails` to **both** the `:development` and `:test` groups in the
|
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
group :development, :test do
|
15
|
-
gem 'rspec-rails', '~>
|
15
|
+
gem 'rspec-rails', '~> 3.0.0.beta'
|
16
16
|
end
|
17
17
|
```
|
18
18
|
|
@@ -189,7 +189,24 @@ FactoryGirl and Capybara seem to be the most widely used. Whether you choose
|
|
189
189
|
these or other libs, we strongly recommend using something for each of these
|
190
190
|
roles.
|
191
191
|
|
192
|
-
|
192
|
+
## <a id="feature-specs"></a>Feature Specs
|
193
|
+
|
194
|
+
Feature specs live in spec/features, and mix in functionality from the
|
195
|
+
capybara gem.
|
196
|
+
|
197
|
+
Feature specs test your application from the outside by simulating a browser.
|
198
|
+
capybara is used to manage the simulated browser.
|
199
|
+
|
200
|
+
To use feature specs, add `capybara` to `Gemfile`:
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
gem "capybara"
|
204
|
+
```
|
205
|
+
|
206
|
+
For more information, see the [cucumber scenarios for feature
|
207
|
+
specs](https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/feature-specs/feature-spec).
|
208
|
+
|
209
|
+
## View specs
|
193
210
|
|
194
211
|
View specs live in spec/views, and mix in ActionView::TestCase::Behavior.
|
195
212
|
|
@@ -417,21 +434,6 @@ However, you must first clear the task that rspec-rails defined:
|
|
417
434
|
task("spec").clear
|
418
435
|
```
|
419
436
|
|
420
|
-
### Webrat and Capybara
|
421
|
-
|
422
|
-
You can choose between webrat or capybara for simulating a browser, automating
|
423
|
-
a browser, or setting expectations using the matchers they supply. Just add
|
424
|
-
your preference to the Gemfile:
|
425
|
-
|
426
|
-
```ruby
|
427
|
-
gem "webrat"
|
428
|
-
# ... or ...
|
429
|
-
gem "capybara"
|
430
|
-
```
|
431
|
-
|
432
|
-
See [http://rubydoc.info/gems/rspec-rails/file/Capybara.md](http://rubydoc.info/gems/rspec-rails/file/Capybara.md)
|
433
|
-
for more info on Capybara integration.
|
434
|
-
|
435
437
|
# Contribute
|
436
438
|
|
437
439
|
See [http://github.com/rspec/rspec-dev](http://github.com/rspec/rspec-dev).
|
data/features/Generators.md
CHANGED
data/features/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
rspec-rails extends Rails' built-in testing framework to support rspec
|
2
|
-
for requests, controllers, models, views, helpers, mailers and
|
1
|
+
rspec-rails extends Rails' built-in testing framework to support rspec
|
2
|
+
examples for requests, controllers, models, views, helpers, mailers and
|
3
|
+
routing.
|
3
4
|
|
4
|
-
## Rails
|
5
|
+
## Rails
|
5
6
|
|
6
|
-
rspec-rails
|
7
|
-
|
7
|
+
rspec-rails 3 supports Rails 3.x and 4.x. For earlier versions of Rails, you
|
8
|
+
need [rspec-rails 1](https://github.com/dchelimsky/rspec-rails).
|
8
9
|
|
9
10
|
## Install
|
10
11
|
|
@@ -23,7 +24,7 @@ This installs the following gems:
|
|
23
24
|
Add rspec-rails to the :test and :development groups in the Gemfile:
|
24
25
|
|
25
26
|
group :test, :development do
|
26
|
-
gem
|
27
|
+
gem 'rspec-rails', '~> 3.0.0.beta'
|
27
28
|
end
|
28
29
|
|
29
30
|
It needs to be in the :development group to expose generators and rake tasks
|
@@ -36,15 +37,6 @@ Now you can run:
|
|
36
37
|
This adds the spec directory and some skeleton files, including a .rspec
|
37
38
|
file.
|
38
39
|
|
39
|
-
## Webrat and Capybara
|
40
|
-
|
41
|
-
You can choose between webrat or capybara for simulating a browser, automating
|
42
|
-
a browser, or setting expectations using the matchers they supply. Just add
|
43
|
-
your preference to the Gemfile:
|
44
|
-
|
45
|
-
gem "webrat"
|
46
|
-
gem "capybara"
|
47
|
-
|
48
40
|
## Issues
|
49
41
|
|
50
42
|
The documentation for rspec-rails is a work in progress. We'll be adding
|
@@ -1,23 +1,27 @@
|
|
1
1
|
Feature: anonymous controller
|
2
2
|
|
3
|
-
Use the `controller` method to define an anonymous controller
|
4
|
-
|
5
|
-
error handling.
|
3
|
+
Use the `controller` method to define an anonymous controller
|
4
|
+
that will inherit from the described class. This is useful for
|
5
|
+
specifying behavior like global error handling.
|
6
6
|
|
7
|
-
To specify a different base class
|
8
|
-
controller method:
|
7
|
+
To specify a different base class you can pass the class explicitly
|
8
|
+
to the controller method:
|
9
9
|
|
10
10
|
controller(BaseController)
|
11
11
|
|
12
|
-
You can also
|
12
|
+
You can also disable base type inference, in which case anonymous
|
13
|
+
controllers will inherit from `ApplicationController` instead of
|
14
|
+
the described class by default:
|
13
15
|
|
14
|
-
|
15
|
-
c.infer_base_class_for_anonymous_controllers =
|
16
|
+
Rspec.configure do |c|
|
17
|
+
c.infer_base_class_for_anonymous_controllers = false
|
16
18
|
end
|
17
19
|
|
18
20
|
describe BaseController do
|
19
21
|
controller { ... }
|
20
|
-
# ^^
|
22
|
+
# ^^ would normally create an anonymous subclass of `BaseController`,
|
23
|
+
# but since `infer_base_class_for_anonymous_controllers` is disabled,
|
24
|
+
# it creates a subclass of `ApplicationController` instead
|
21
25
|
|
22
26
|
Scenario: specify error handling in ApplicationController
|
23
27
|
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
@@ -97,10 +101,6 @@ Feature: anonymous controller
|
|
97
101
|
"""ruby
|
98
102
|
require "spec_helper"
|
99
103
|
|
100
|
-
RSpec.configure do |c|
|
101
|
-
c.infer_base_class_for_anonymous_controllers = true
|
102
|
-
end
|
103
|
-
|
104
104
|
class ApplicationController < ActionController::Base; end
|
105
105
|
|
106
106
|
class ApplicationControllerSubclass < ApplicationController; end
|
@@ -120,6 +120,39 @@ Feature: anonymous controller
|
|
120
120
|
When I run `rspec spec`
|
121
121
|
Then the examples should all pass
|
122
122
|
|
123
|
+
Scenario: get name and controller_name from the described class
|
124
|
+
Given a file named "spec/controllers/get_name_and_controller_name_from_described_class_spec.rb" with:
|
125
|
+
"""ruby
|
126
|
+
require "spec_helper"
|
127
|
+
|
128
|
+
class ApplicationController < ActionController::Base; end
|
129
|
+
class FoosController < ApplicationController; end
|
130
|
+
|
131
|
+
describe "FoosController controller_name" do
|
132
|
+
controller FoosController do
|
133
|
+
def index
|
134
|
+
@name = self.class.name
|
135
|
+
@controller_name = controller_name
|
136
|
+
render :text => "Hello World"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
before do
|
141
|
+
get :index
|
142
|
+
end
|
143
|
+
|
144
|
+
it "gets the class name as described" do
|
145
|
+
expect(assigns[:name]).to eq('FoosController')
|
146
|
+
end
|
147
|
+
|
148
|
+
it "gets the controller_name as described" do
|
149
|
+
expect(assigns[:controller_name]).to eq('foos')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
"""
|
153
|
+
When I run `rspec spec`
|
154
|
+
Then the examples should all pass
|
155
|
+
|
123
156
|
Scenario: invoke around filter in base class
|
124
157
|
Given a file named "spec/controllers/application_controller_around_filter_spec.rb" with:
|
125
158
|
"""ruby
|
@@ -153,226 +186,251 @@ Feature: anonymous controller
|
|
153
186
|
|
154
187
|
Scenario: anonymous controllers only create resource routes
|
155
188
|
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
describe ApplicationController do
|
160
|
-
controller do
|
161
|
-
def index
|
162
|
-
render :text => "index called"
|
163
|
-
end
|
189
|
+
"""ruby
|
190
|
+
require "spec_helper"
|
164
191
|
|
165
|
-
|
166
|
-
|
167
|
-
|
192
|
+
describe ApplicationController do
|
193
|
+
controller do
|
194
|
+
def index
|
195
|
+
render :text => "index called"
|
196
|
+
end
|
168
197
|
|
169
|
-
|
170
|
-
|
171
|
-
|
198
|
+
def create
|
199
|
+
render :text => "create called"
|
200
|
+
end
|
172
201
|
|
173
|
-
|
174
|
-
|
175
|
-
|
202
|
+
def new
|
203
|
+
render :text => "new called"
|
204
|
+
end
|
176
205
|
|
177
|
-
|
178
|
-
|
179
|
-
|
206
|
+
def show
|
207
|
+
render :text => "show called"
|
208
|
+
end
|
180
209
|
|
181
|
-
|
182
|
-
|
183
|
-
|
210
|
+
def edit
|
211
|
+
render :text => "edit called"
|
212
|
+
end
|
184
213
|
|
185
|
-
|
186
|
-
|
187
|
-
|
214
|
+
def update
|
215
|
+
render :text => "update called"
|
216
|
+
end
|
188
217
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
end
|
218
|
+
def destroy
|
219
|
+
render :text => "destroy called"
|
220
|
+
end
|
193
221
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
expect(response.body).to eq "index called"
|
222
|
+
def willerror
|
223
|
+
render :text => "will not render"
|
224
|
+
end
|
198
225
|
end
|
199
226
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
227
|
+
describe "#index" do
|
228
|
+
it "responds to GET" do
|
229
|
+
get :index
|
230
|
+
expect(response.body).to eq "index called"
|
231
|
+
end
|
204
232
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
233
|
+
it "also responds to POST" do
|
234
|
+
post :index
|
235
|
+
expect(response.body).to eq "index called"
|
236
|
+
end
|
209
237
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
end
|
238
|
+
it "also responds to PUT" do
|
239
|
+
put :index
|
240
|
+
expect(response.body).to eq "index called"
|
241
|
+
end
|
215
242
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
243
|
+
it "also responds to DELETE" do
|
244
|
+
delete :index
|
245
|
+
expect(response.body).to eq "index called"
|
246
|
+
end
|
220
247
|
end
|
221
248
|
|
222
|
-
#
|
223
|
-
|
224
|
-
|
225
|
-
send(calltype, :create)
|
249
|
+
describe "#create" do
|
250
|
+
it "responds to POST" do
|
251
|
+
post :create
|
226
252
|
expect(response.body).to eq "create called"
|
227
253
|
end
|
228
|
-
end
|
229
|
-
end
|
230
254
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
255
|
+
# And the rest...
|
256
|
+
%w{get post put delete}.each do |calltype|
|
257
|
+
it "responds to #{calltype}" do
|
258
|
+
send(calltype, :create)
|
259
|
+
expect(response.body).to eq "create called"
|
260
|
+
end
|
261
|
+
end
|
235
262
|
end
|
236
263
|
|
237
|
-
#
|
238
|
-
|
239
|
-
|
240
|
-
send(calltype, :new)
|
264
|
+
describe "#new" do
|
265
|
+
it "responds to GET" do
|
266
|
+
get :new
|
241
267
|
expect(response.body).to eq "new called"
|
242
268
|
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
describe "#edit" do
|
247
|
-
it "responds to GET" do
|
248
|
-
get :edit, :id => "anyid"
|
249
|
-
expect(response.body).to eq "edit called"
|
250
|
-
end
|
251
269
|
|
252
|
-
|
253
|
-
|
270
|
+
# And the rest...
|
271
|
+
%w{get post put delete}.each do |calltype|
|
272
|
+
it "responds to #{calltype}" do
|
273
|
+
send(calltype, :new)
|
274
|
+
expect(response.body).to eq "new called"
|
275
|
+
end
|
276
|
+
end
|
254
277
|
end
|
255
278
|
|
256
|
-
#
|
257
|
-
|
258
|
-
|
259
|
-
send(calltype, :edit, {:id => "anyid"})
|
279
|
+
describe "#edit" do
|
280
|
+
it "responds to GET" do
|
281
|
+
get :edit, :id => "anyid"
|
260
282
|
expect(response.body).to eq "edit called"
|
261
283
|
end
|
262
|
-
end
|
263
|
-
end
|
264
284
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
expect(response.body).to eq "show called"
|
269
|
-
end
|
285
|
+
it "requires the :id parameter" do
|
286
|
+
expect { get :edit }.to raise_error(ActionController::RoutingError)
|
287
|
+
end
|
270
288
|
|
271
|
-
|
272
|
-
|
289
|
+
# And the rest...
|
290
|
+
%w{get post put delete}.each do |calltype|
|
291
|
+
it "responds to #{calltype}" do
|
292
|
+
send(calltype, :edit, {:id => "anyid"})
|
293
|
+
expect(response.body).to eq "edit called"
|
294
|
+
end
|
295
|
+
end
|
273
296
|
end
|
274
297
|
|
275
|
-
#
|
276
|
-
|
277
|
-
|
278
|
-
send(calltype, :show, {:id => "anyid"})
|
298
|
+
describe "#show" do
|
299
|
+
it "responds to GET" do
|
300
|
+
get :show, :id => "anyid"
|
279
301
|
expect(response.body).to eq "show called"
|
280
302
|
end
|
281
|
-
end
|
282
|
-
end
|
283
303
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
expect(response.body).to eq "update called"
|
288
|
-
end
|
304
|
+
it "requires the :id parameter" do
|
305
|
+
expect { get :show }.to raise_error(ActionController::RoutingError)
|
306
|
+
end
|
289
307
|
|
290
|
-
|
291
|
-
|
308
|
+
# And the rest...
|
309
|
+
%w{get post put delete}.each do |calltype|
|
310
|
+
it "responds to #{calltype}" do
|
311
|
+
send(calltype, :show, {:id => "anyid"})
|
312
|
+
expect(response.body).to eq "show called"
|
313
|
+
end
|
314
|
+
end
|
292
315
|
end
|
293
316
|
|
294
|
-
#
|
295
|
-
|
296
|
-
|
297
|
-
send(calltype, :update, {:id => "anyid"})
|
317
|
+
describe "#update" do
|
318
|
+
it "responds to PUT" do
|
319
|
+
put :update, :id => "anyid"
|
298
320
|
expect(response.body).to eq "update called"
|
299
321
|
end
|
300
|
-
end
|
301
|
-
end
|
302
322
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
expect(response.body).to eq "destroy called"
|
307
|
-
end
|
323
|
+
it "requires the :id parameter" do
|
324
|
+
expect { put :update }.to raise_error(ActionController::RoutingError)
|
325
|
+
end
|
308
326
|
|
309
|
-
|
310
|
-
|
327
|
+
# And the rest...
|
328
|
+
%w{get post put delete}.each do |calltype|
|
329
|
+
it "responds to #{calltype}" do
|
330
|
+
send(calltype, :update, {:id => "anyid"})
|
331
|
+
expect(response.body).to eq "update called"
|
332
|
+
end
|
333
|
+
end
|
311
334
|
end
|
312
335
|
|
313
|
-
#
|
314
|
-
|
315
|
-
|
316
|
-
send(calltype, :destroy, {:id => "anyid"})
|
336
|
+
describe "#destroy" do
|
337
|
+
it "responds to DELETE" do
|
338
|
+
delete :destroy, :id => "anyid"
|
317
339
|
expect(response.body).to eq "destroy called"
|
318
340
|
end
|
341
|
+
|
342
|
+
it "requires the :id parameter" do
|
343
|
+
expect { delete :destroy }.to raise_error(ActionController::RoutingError)
|
344
|
+
end
|
345
|
+
|
346
|
+
# And the rest...
|
347
|
+
%w{get post put delete}.each do |calltype|
|
348
|
+
it "responds to #{calltype}" do
|
349
|
+
send(calltype, :destroy, {:id => "anyid"})
|
350
|
+
expect(response.body).to eq "destroy called"
|
351
|
+
end
|
352
|
+
end
|
319
353
|
end
|
320
|
-
end
|
321
354
|
|
322
|
-
|
323
|
-
|
324
|
-
|
355
|
+
describe "#willerror" do
|
356
|
+
it "cannot be called" do
|
357
|
+
expect { get :willerror }.to raise_error(ActionController::RoutingError)
|
358
|
+
end
|
325
359
|
end
|
326
360
|
end
|
327
|
-
|
328
|
-
"""
|
361
|
+
"""
|
329
362
|
When I run `rspec spec`
|
330
363
|
Then the examples should all pass
|
331
364
|
|
332
365
|
Scenario: draw custom routes for anonymous controllers
|
333
366
|
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
334
|
-
|
335
|
-
|
367
|
+
"""ruby
|
368
|
+
require "spec_helper"
|
336
369
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
370
|
+
describe ApplicationController do
|
371
|
+
controller do
|
372
|
+
def custom
|
373
|
+
render :text => "custom called"
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
specify "a custom action can be requested if routes are drawn manually" do
|
378
|
+
routes.draw { get "custom" => "anonymous#custom" }
|
379
|
+
|
380
|
+
get :custom
|
381
|
+
expect(response.body).to eq "custom called"
|
341
382
|
end
|
342
383
|
end
|
384
|
+
"""
|
385
|
+
When I run `rspec spec`
|
386
|
+
Then the examples should all pass
|
343
387
|
|
344
|
-
|
345
|
-
|
388
|
+
Scenario: draw custom routes for defined controllers
|
389
|
+
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
390
|
+
"""ruby
|
391
|
+
require "spec_helper"
|
392
|
+
|
393
|
+
class FoosController < ApplicationController; end
|
394
|
+
|
395
|
+
describe ApplicationController do
|
396
|
+
controller FoosController do
|
397
|
+
def custom
|
398
|
+
render :text => "custom called"
|
399
|
+
end
|
400
|
+
end
|
346
401
|
|
347
|
-
|
348
|
-
|
402
|
+
specify "a custom action can be requested if routes are drawn manually" do
|
403
|
+
routes.draw { get "custom" => "foos#custom" }
|
404
|
+
|
405
|
+
get :custom
|
406
|
+
expect(response.body).to eq "custom called"
|
407
|
+
end
|
349
408
|
end
|
350
|
-
|
351
|
-
"""
|
409
|
+
"""
|
352
410
|
When I run `rspec spec`
|
353
411
|
Then the examples should all pass
|
354
412
|
|
355
413
|
Scenario: refer to application routes in the controller under test
|
356
414
|
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
357
|
-
|
358
|
-
|
415
|
+
"""ruby
|
416
|
+
require "spec_helper"
|
359
417
|
|
360
|
-
|
361
|
-
|
362
|
-
|
418
|
+
Rails.application.routes.draw do
|
419
|
+
match "/login" => "sessions#new", :as => "login", :via => "get"
|
420
|
+
end
|
363
421
|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
422
|
+
describe ApplicationController do
|
423
|
+
controller do
|
424
|
+
def index
|
425
|
+
redirect_to login_url
|
426
|
+
end
|
368
427
|
end
|
369
|
-
end
|
370
428
|
|
371
|
-
|
372
|
-
|
373
|
-
|
429
|
+
it "redirects to the login page" do
|
430
|
+
get :index
|
431
|
+
expect(response).to redirect_to("/login")
|
432
|
+
end
|
374
433
|
end
|
375
|
-
|
376
|
-
"""
|
434
|
+
"""
|
377
435
|
When I run `rspec spec`
|
378
436
|
Then the examples should all pass
|