@@ -53,10 +53,6 @@ Use **[`rspec-rails` 1.x][]** for Rails 2.x.
53
53
create spec
54
54
create spec/spec_helper.rb
55
55
create spec/rails_helper.rb
56
-
57
- # Rails 4+ only: generate a binstub
58
- # (so you can run `bin/rspec` instead of `bundle exec rspec`)
59
- $ bundle binstubs rspec-core
60
56
```
61
57
62
58
## Upgrading
@@ -119,6 +115,14 @@ $ bundle exec rspec spec/controllers/accounts_controller_spec.rb:8
119
115
$ bundle exec rspec --help
120
116
```
121
117
118
+ ** Optional:** If ` bundle exec rspec ` is too verbose for you,
119
+ you can generate a binstub at ` bin/rspec `
120
+ and use that instead (Rails 4+ only):
121
+
122
+ ``` sh
123
+ $ bundle binstubs rspec-core
124
+ ```
125
+
122
126
## RSpec DSL Basics (or, how do I write a spec?)
123
127
124
128
In RSpec, application behavior is described
@@ -241,6 +245,25 @@ or for official Rails API documentation on the given `TestCase` class.
241
245
> to encourage good testing practices, but there’s no “right” way to do it.
242
246
> Ultimately, it’s up to you to decide how your test suite will be composed.
243
247
248
+ When creating a spec file,
249
+ assign it a type by placing it [ in the appropriate folder] [ ]
250
+ (_ e.g.,_ ` spec/models/ ` for model specs).
251
+ If you want to be extra explicit,
252
+ you can set the ` :type ` option at the top of the file, like so:
253
+
254
+ ``` ruby
255
+ # spec/models/user_spec.rb
256
+
257
+ RSpec .describe User , type: :model do
258
+ ...
259
+ ```
260
+
261
+ If you use the built-in generators, these details will be handled automatically:
262
+
263
+ ``` sh
264
+ $ rails generate rspec:< type> < name>
265
+ ```
266
+
244
267
[ request ] : https://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec
245
268
[ feature ] : https://www.relishapp.com/rspec/rspec-rails/docs/feature-specs/feature-spec
246
269
[ system ] : https://relishapp.com/rspec/rspec-rails/docs/system-specs/system-spec
@@ -254,23 +277,6 @@ or for official Rails API documentation on the given `TestCase` class.
254
277
[ `ActionDispatch::IntegrationTest` ] : https://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html
255
278
[ `ActionDispatch::SystemTestCase` ] : https://api.rubyonrails.org/classes/ActionDispatch/SystemTestCase.html
256
279
[ `ActionController::TestCase` ] : https://api.rubyonrails.org/classes/ActionController/TestCase.html
257
-
258
- ### I’m writing a spec file from scratch. How do I assign it a type?
259
-
260
- Simply place the spec [ in the appropriate folder] [ ]
261
- (_ e.g.,_ ` spec/models/ ` for model specs)
262
- and RSpec will set its type automatically.
263
-
264
- If you want to be extra explicit,
265
- you can set the ` :type ` option at the top of the file, like so:
266
-
267
- ``` ruby
268
- # spec/models/user_spec.rb
269
-
270
- RSpec .describe User , type: :model do
271
- ...
272
- ```
273
-
274
280
[ in the appropriate folder ] : https://relishapp.com/rspec/rspec-rails/docs/directory-structure
275
281
276
282
### System specs, feature specs, request specs–what’s the difference?
0 commit comments