Skip to content

Commit 762021b

Browse files
author
Sam Phippen
authored
Merge pull request rspec#1839 from rlue/master
Discourage controller specs in README
2 parents ade09c0 + 73e387e commit 762021b

File tree

1 file changed

+20
-49
lines changed

1 file changed

+20
-49
lines changed

README.md

+20-49
Original file line numberDiff line numberDiff line change
@@ -160,57 +160,12 @@ end
160160
For more information, see [cucumber scenarios for model
161161
specs](https://www.relishapp.com/rspec/rspec-rails/docs/model-specs).
162162

163-
## Controller Specs
164-
165-
Use controller specs to describe behavior of Rails controllers.
166-
167-
Controller specs default to residing in the `spec/controllers` folder. Tagging
168-
any context with the metadata `:type => :controller` treats its examples as
169-
controller specs.
170-
171-
For example:
172-
173-
```ruby
174-
require "rails_helper"
175-
176-
RSpec.describe PostsController, :type => :controller do
177-
describe "GET #index" do
178-
it "responds successfully with an HTTP 200 status code" do
179-
get :index
180-
expect(response).to be_success
181-
expect(response).to have_http_status(200)
182-
end
183-
184-
it "renders the index template" do
185-
get :index
186-
expect(response).to render_template("index")
187-
end
188-
189-
it "loads all of the posts into @posts" do
190-
post1, post2 = Post.create!, Post.create!
191-
get :index
192-
193-
expect(assigns(:posts)).to match_array([post1, post2])
194-
end
195-
end
196-
end
197-
```
198-
199-
For more information, see [cucumber scenarios for controller
200-
specs](https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs).
201-
202-
**Note:** To encourage more isolated testing, views are not rendered by default
203-
in controller specs. If you are verifying discrete view logic, use a [view
204-
spec](#view-specs). If you are verifying the behaviour of a controller and view
205-
together, consider a [request spec](#request-specs). You can use
206-
[render\_views](https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs/render-views)
207-
if you must verify the rendered view contents within a controller spec, but
208-
this is not recommended.
209-
210163
## Request Specs
211164

212-
Use request specs to specify one or more request/response cycles from end to
213-
end using a black box approach.
165+
Use request specs to describe the client-facing behavior of the application —
166+
specifically, the HTTP response to be issued for a given request (a.k.a.
167+
integration tests). Since such client-facing behavior encompasses controller
168+
actions, this is the type of spec to use for controller testing.
214169

215170
Request specs default to residing in the `spec/requests`, `spec/api`, and
216171
`spec/integration` directories. Tagging any context with the metadata `:type =>
@@ -277,6 +232,22 @@ FactoryGirl and Capybara seem to be the most widely used. Whether you choose
277232
these or other libs, we strongly recommend using something for each of these
278233
roles.
279234

235+
For more information, see [cucumber scenarios for request
236+
specs](https://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec).
237+
238+
## Controller Specs
239+
240+
Controller specs can be used to describe the behavior of Rails controllers. As
241+
of version 3.5, however, controller specs are discouraged in favor of request
242+
specs (which also focus largely on controllers, but capture other critical
243+
aspects of application behavior as well). Controller specs will continue to be
244+
supported until at least version 4.0 (see the [release
245+
notes](http://rspec.info/blog/2016/07/rspec-3-5-has-been-released/#rails-support-for-rails-5)
246+
for details).
247+
248+
For more information, see [cucumber scenarios for controller
249+
specs](https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs).
250+
280251
## Feature Specs
281252

282253
Feature specs test your application from the outside by simulating a browser.

0 commit comments

Comments
 (0)