You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### I’m writing a spec file from scratch. How do I assign it a type?
278
255
279
-
Assuming you haven’t [modified the default `rails_helper.rb` configuration][],
280
-
simply place the spec in the appropriate folder
256
+
Simply place the spec in the appropriate folder
281
257
(_e.g.,_`spec/models/` for model specs)
282
258
and RSpec will set its type automatically.
283
259
284
-
If you _have_ modified the default config
285
-
(or if you just want to be extra explicit),
260
+
If you want to be extra explicit,
286
261
you can set the `:type` option at the top of the file, like so:
287
262
288
263
```ruby
@@ -297,12 +272,11 @@ RSpec.describe User, type: :model do
297
272
### System specs, feature specs, request specs–what’s the difference?
298
273
299
274
RSpec Rails provides three types of specs
300
-
for integration testing the application as a whole—in other words,
301
-
specifying what the client sees when interacting with it.
275
+
that do not directly correspond to any Rails application component.
302
276
303
277
#### System specs
304
278
305
-
Sometimes called **acceptance tests**or **browser tests**,
279
+
Also called **acceptance tests**, **browser tests**, or **end-to-end tests**,
306
280
system specs test the application from the perspective of a _human client._
307
281
The test code walks through a user’s browser interactions,
308
282
@@ -323,16 +297,21 @@ but `SystemTestCase` solves some longstanding configuration issues they had,
323
297
so the RSpec team [officially recommends system specs][] over feature specs.
324
298
325
299
If you don’t have the luxury of upgrading,
326
-
you’ll be limited to writing feature specs for your browser tests.
327
-
They require [Capybara][],
328
-
so make sure it’s listed in the `:test` group of your `Gemfile`:
300
+
there’s no problem with using feature specs instead.
301
+
Be sure to add [Capybara][] to the `:test` group of your `Gemfile` first:
329
302
330
303
```ruby
331
304
group :testdo
332
305
gem "capybara"
333
306
end
334
307
```
335
308
309
+
(It’s actually required for both feature and system specs,
310
+
but Rails includes it by default in versions 5.1+.)
311
+
312
+
[officially recommends system specs]: http://rspec.info/blog/2017/10/rspec-3-7-has-been-released/#rails-actiondispatchsystemtest-integration-system-specs
@@ -341,18 +320,16 @@ They begin with an HTTP request and end with the HTTP response,
341
320
so they’re faster than feature specs,
342
321
but do not examine your app’s UI or JavaScript.
343
322
344
-
Request specs provide a high-level alternative to unit testing controllers.
345
-
In fact, as of RSpec 3.5,
346
-
the RSpec team [discourages controller specs entirely][]
347
-
in favor of request specs.
323
+
Request specs provide a high-level alternative to controller specs.
324
+
In fact, as of RSpec 3.5, both the Rails and RSpec teams
325
+
[discourage directly testing controllers][]
326
+
in favor of functional tests like request specs.
348
327
349
328
When writing them, try to answer the question,
350
329
“For a given HTTP request (verb + path + parameters),
351
330
what HTTP response should the application return?”
352
331
353
-
[officially recommends system specs]: http://rspec.info/blog/2017/10/rspec-3-7-has-been-released/#rails-actiondispatchsystemtest-integration-system-specs
0 commit comments