rspec-rails 5.1.1 → 6.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +65 -6
- data/README.md +35 -35
- data/lib/generators/rspec/channel/channel_generator.rb +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +4 -4
- data/lib/generators/rspec/feature/feature_generator.rb +1 -1
- data/lib/generators/rspec/generator/generator_generator.rb +1 -1
- data/lib/generators/rspec/helper/helper_generator.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +19 -2
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +3 -4
- data/lib/generators/rspec/integration/integration_generator.rb +10 -3
- data/lib/generators/rspec/job/job_generator.rb +1 -1
- data/lib/generators/rspec/mailbox/mailbox_generator.rb +1 -1
- data/lib/generators/rspec/mailer/mailer_generator.rb +3 -3
- data/lib/generators/rspec/model/model_generator.rb +3 -3
- data/lib/generators/rspec/request/request_generator.rb +10 -3
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +4 -4
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +16 -1
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +8 -4
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +15 -0
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +1 -1
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/generators/rspec.rb +18 -1
- data/lib/rspec/rails/adapters.rb +11 -0
- data/lib/rspec/rails/configuration.rb +12 -11
- data/lib/rspec/rails/example/rails_example_group.rb +1 -0
- data/lib/rspec/rails/example/system_example_group.rb +12 -11
- data/lib/rspec/rails/example/view_example_group.rb +4 -4
- data/lib/rspec/rails/feature_check.rb +6 -2
- data/lib/rspec/rails/file_fixture_support.rb +3 -0
- data/lib/rspec/rails/fixture_file_upload_support.rb +13 -30
- data/lib/rspec/rails/fixture_support.rb +7 -2
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +5 -2
- data/lib/rspec/rails/matchers/active_job.rb +4 -4
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +3 -2
- data/lib/rspec/rails/matchers/have_http_status.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +2 -2
- data/lib/rspec/rails/vendor/capybara.rb +1 -3
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +0 -18
- data/lib/rspec/rails/view_rendering.rb +13 -11
- data/lib/rspec-rails.rb +1 -5
- data.tar.gz.sig +0 -0
- metadata +23 -35
- metadata.gz.sig +0 -0
- /data/lib/generators/rspec/{integration → request}/templates/request_spec.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ea5e598eb640cb98f6c236d15d50ebf4eb2b2a9b3933f9d54e26c641a02a883
|
4
|
+
data.tar.gz: 1cc9b5c8781149e0e1d0c4ef11d4b39289aef77e01fdd0fe88db1936060134e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 738369d092e738e50c111b93a1fdc2e02ecacce35cd1595a5e1c00453dad3901ed6a69f162b01d20e5265edda7dbcdb34a2c772f198d1b2a8c1d46d1e9c0ca0f
|
7
|
+
data.tar.gz: dcd63e6c5faf232419774b29406ffc3492bfb28367a629fd792245227899b07afe12adc13249b29ee9ef3077ec261f6210f6c53b2413f291e57b0d63182a4436
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,5 +1,63 @@
|
|
1
1
|
### Development
|
2
|
-
[Full Changelog](https://github.com/rspec/rspec-rails/compare/
|
2
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.3...6-0-maintenance)
|
3
|
+
|
4
|
+
### 6.0.3 / 2023-05-31
|
5
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.2...v6.0.3)
|
6
|
+
|
7
|
+
Bug Fixes:
|
8
|
+
|
9
|
+
* Set `ActiveStorage::FixtureSet.file_fixture_path` when including file fixture support.
|
10
|
+
(Jason Yates, #2671)
|
11
|
+
* Allow `broadcast_to` matcher to take Symbols. (@Vagab, #2680)
|
12
|
+
|
13
|
+
### 6.0.2 / 2023-05-04
|
14
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.1...v6.0.2)
|
15
|
+
|
16
|
+
Bug Fixes:
|
17
|
+
|
18
|
+
* Fix ActionView::PathSet when `render_views` is off for Rails 7.1.
|
19
|
+
(Eugene Kenny, Iliana, #2631)
|
20
|
+
* Support Rails 7.1's `#fixtures_paths` in example groups (removes a deprecation warning).
|
21
|
+
(Nicholas Simmons, #2664)
|
22
|
+
* Fix `have_enqueued_job` to properly detect enqueued jobs when other jobs were
|
23
|
+
performed inside the expectation block. (Slava Kardakov, Phil Pirozhkov, #2573)
|
24
|
+
|
25
|
+
### 6.0.1 / 2022-10-18
|
26
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.0.0...v6.0.1)
|
27
|
+
|
28
|
+
Bug Fixes:
|
29
|
+
|
30
|
+
* Prevent tagged logged support in Rails 7 calling `#name`. (Jon Rowe, #2625)
|
31
|
+
|
32
|
+
### 6.0.0 / 2022-10-10
|
33
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.1.2...v6.0.0)
|
34
|
+
|
35
|
+
Enhancements:
|
36
|
+
|
37
|
+
* Support Rails 7
|
38
|
+
* Template tweaks to remove instance variables from generated specs. (Takuma Ishikawa, #2599)
|
39
|
+
* Generators now respects default path configuration option. (@vivekmiyani, #2508)
|
40
|
+
|
41
|
+
Breaking Changes:
|
42
|
+
|
43
|
+
* Drop support for Rails below 6.1
|
44
|
+
* Drop support for Ruby below 2.5 (following supported versions of Rails 6.1)
|
45
|
+
* Change the order of `after_teardown` from `after` to `around` in system
|
46
|
+
specs to improve compatibility with extensions and Capybara. (Tim Diggins, #2596)
|
47
|
+
|
48
|
+
Deprecations:
|
49
|
+
|
50
|
+
* Deprecates integration spec generator (`rspec:integration`)
|
51
|
+
which was an alias of request spec generator (`rspec:request`)
|
52
|
+
(Luka Lüdicke, #2374)
|
53
|
+
|
54
|
+
### 5.1.2 / 2022-04-24
|
55
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.1.1...v5.1.2)
|
56
|
+
|
57
|
+
Bug Fixes:
|
58
|
+
|
59
|
+
* Fix controller scaffold templates parameter name. (Taketo Takashima, #2591)
|
60
|
+
* Include generator specs in the inferred list of specs. (Jason Karns, #2597)
|
3
61
|
|
4
62
|
### 5.1.1 / 2022-03-07
|
5
63
|
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.1.0...v5.1.1)
|
@@ -26,8 +84,9 @@ Bug Fixes:
|
|
26
84
|
|
27
85
|
* Properly name params in controller and request spec templates when
|
28
86
|
using the `--model-name` parameter. (@kenzo-tanaka, #2534)
|
29
|
-
* Fix
|
30
|
-
(Fabio Napoleoni,
|
87
|
+
* Fix parameter matching with mail delivery job and
|
88
|
+
ActionMailer::MailDeliveryJob. (Fabio Napoleoni, #2516, #2546)
|
89
|
+
* Fix Rails 7 `have_enqueued_mail` compatibility (Mikael Henriksson, #2537, #2546)
|
31
90
|
|
32
91
|
### 5.0.2 / 2021-08-14
|
33
92
|
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.1...v5.0.2)
|
@@ -73,7 +132,7 @@ Bug Fixes:
|
|
73
132
|
|
74
133
|
Enhancements:
|
75
134
|
|
76
|
-
* Issue a warning when using job matchers with `#at`
|
135
|
+
* Issue a warning when using job matchers with `#at` mismatch on `usec` precision.
|
77
136
|
(Jon Rowe, #2350)
|
78
137
|
* Generated request specs now have a bare `_spec` suffix instead of `request_spec`.
|
79
138
|
(Eloy Espinaco, Luka Lüdicke, #2355, #2356, #2378)
|
@@ -200,7 +259,7 @@ Bug Fixes:
|
|
200
259
|
|
201
260
|
Bug Fixes:
|
202
261
|
|
203
|
-
* Namespaced fixtures now generate a `/`
|
262
|
+
* Namespaced fixtures now generate a `/` separated path rather than an `_`.
|
204
263
|
(@nxlith, #2077)
|
205
264
|
* Check the arity of `errors` before attempting to use it to generate the `be_valid`
|
206
265
|
error message. (Kevin Kuchta, #2096)
|
@@ -360,7 +419,7 @@ Enhancements:
|
|
360
419
|
|
361
420
|
Bug fixes:
|
362
421
|
|
363
|
-
* Prevent asset helpers from taking
|
422
|
+
* Prevent asset helpers from taking precedence over route helpers. (Prem Sichanugrist, #1496)
|
364
423
|
* Prevent `NoMethodError` during failed `have_rendered` assertions on weird templates.
|
365
424
|
(Jon Rowe, #1623).
|
366
425
|
|
data/README.md
CHANGED
@@ -9,13 +9,12 @@ detailed explanations of how the application is supposed to behave,
|
|
9
9
|
expressed in plain English.
|
10
10
|
|
11
11
|
According to [RSpec Rails new versioning strategy][] use:
|
12
|
-
* **[`rspec-rails`
|
12
|
+
* **[`rspec-rails` 6.x][]** for Rails 6.1 or 7.x.
|
13
|
+
* **[`rspec-rails` 5.x][]** for Rails 5.2 or 6.x.
|
13
14
|
* **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x.
|
14
15
|
* **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
|
15
16
|
* **[`rspec-rails` 1.x][]** for Rails 2.x.
|
16
17
|
|
17
|
-
[Build Status]: https://secure.travis-ci.org/rspec/rspec-rails.svg?branch=main
|
18
|
-
[travis-ci]: https://travis-ci.org/rspec/rspec-rails
|
19
18
|
[Code Climate]: https://codeclimate.com/github/rspec/rspec-rails.svg
|
20
19
|
[code-climate]: https://codeclimate.com/github/rspec/rspec-rails
|
21
20
|
[Gem Version]: https://badge.fury.io/rb/rspec-rails.svg
|
@@ -25,13 +24,14 @@ According to [RSpec Rails new versioning strategy][] use:
|
|
25
24
|
[`rspec-rails` 1.x]: https://github.com/dchelimsky/rspec-rails
|
26
25
|
[`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
|
27
26
|
[`rspec-rails` 4.x]: https://github.com/rspec/rspec-rails/tree/4-1-maintenance
|
28
|
-
[`rspec-rails` 5.x]: https://github.com/rspec/rspec-rails/tree/5-
|
27
|
+
[`rspec-rails` 5.x]: https://github.com/rspec/rspec-rails/tree/5-1-maintenance
|
28
|
+
[`rspec-rails` 6.x]: https://github.com/rspec/rspec-rails/tree/6-0-maintenance
|
29
29
|
[RSpec Rails new versioning strategy]: https://github.com/rspec/rspec-rails/blob/main/rfcs/versioning-strategy.md
|
30
30
|
|
31
31
|
## Installation
|
32
32
|
|
33
33
|
**IMPORTANT** This README / branch refers to the current development build.
|
34
|
-
See the [`
|
34
|
+
See the [`6-0-maintenance` branch on Github](https://github.com/rspec/rspec-rails/tree/6-0-maintenance) if you want or require the latest stable release.
|
35
35
|
|
36
36
|
1. Add `rspec-rails` to **both** the `:development` and `:test` groups
|
37
37
|
of your app’s `Gemfile`:
|
@@ -39,7 +39,7 @@ See the [`5-0-maintenance` branch on Github](https://github.com/rspec/rspec-rail
|
|
39
39
|
```ruby
|
40
40
|
# Run against this stable release
|
41
41
|
group :development, :test do
|
42
|
-
gem 'rspec-rails', '~>
|
42
|
+
gem 'rspec-rails', '~> 6.0.0'
|
43
43
|
end
|
44
44
|
|
45
45
|
# Or, run against the main branch
|
@@ -86,8 +86,8 @@ read the [`rspec-rails` upgrade notes][] to find out what to watch out for.
|
|
86
86
|
|
87
87
|
Be sure to check the general [RSpec upgrade notes][] as well.
|
88
88
|
|
89
|
-
[`rspec-rails` upgrade notes]: https://
|
90
|
-
[RSpec upgrade notes]: https://
|
89
|
+
[`rspec-rails` upgrade notes]: https://rspec.info/features/6-0/rspec-rails/upgrade
|
90
|
+
[RSpec upgrade notes]: https://rspec.info/upgrading-from-rspec-2/
|
91
91
|
|
92
92
|
## Usage
|
93
93
|
|
@@ -181,7 +181,7 @@ rspec ./spec/models/post_spec.rb:3 # Post before publication cannot have comment
|
|
181
181
|
For an in-depth look at the RSpec DSL, including lots of examples,
|
182
182
|
read the official Cucumber documentation for [RSpec Core][].
|
183
183
|
|
184
|
-
[RSpec Core]: https://
|
184
|
+
[RSpec Core]: https://rspec.info/features/3-12/rspec-core
|
185
185
|
|
186
186
|
### Helpful Rails Matchers
|
187
187
|
|
@@ -207,23 +207,23 @@ to test the various parts of a Rails system:
|
|
207
207
|
|
208
208
|
Follow the links above for examples of how each matcher is used.
|
209
209
|
|
210
|
-
[the matchers that come standard in RSpec]: https://
|
211
|
-
[`be_a_new`]: https://
|
212
|
-
[`render_template`]: https://
|
213
|
-
[`redirect_to`]: https://
|
214
|
-
[`route_to`]: https://
|
215
|
-
[`be_routable`]: https://
|
216
|
-
[`have_http_status`]: https://
|
217
|
-
[`match_array`]: https://
|
218
|
-
[`have_been_enqueued`]: https://
|
219
|
-
[`have_enqueued_job`]: https://
|
210
|
+
[the matchers that come standard in RSpec]: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers
|
211
|
+
[`be_a_new`]: https://rspec.info/features/6-0/rspec-rails/matchers/new-record-matcher
|
212
|
+
[`render_template`]: https://rspec.info/features/6-0/rspec-rails/matchers/render-template-matcher
|
213
|
+
[`redirect_to`]: https://rspec.info/features/6-0/rspec-rails/matchers/redirect-to-matcher
|
214
|
+
[`route_to`]: https://rspec.info/features/6-0/rspec-rails/routing-specs/route-to-matcher
|
215
|
+
[`be_routable`]: https://rspec.info/features/6-0/rspec-rails/routing-specs/be-routable-matcher
|
216
|
+
[`have_http_status`]: https://rspec.info/features/6-0/rspec-rails/matchers/have-http-status-matcher
|
217
|
+
[`match_array`]: https://rspec.info/features/6-0/rspec-rails/matchers/relation-match-array
|
218
|
+
[`have_been_enqueued`]: https://rspec.info/features/6-0/rspec-rails/matchers/have-been-enqueued-matcher
|
219
|
+
[`have_enqueued_job`]: https://rspec.info/features/6-0/rspec-rails/matchers/have-enqueued-job-matcher
|
220
220
|
|
221
221
|
### What else does RSpec Rails add?
|
222
222
|
|
223
223
|
For a comprehensive look at RSpec Rails’ features,
|
224
224
|
read the [official Cucumber documentation][].
|
225
225
|
|
226
|
-
[official Cucumber documentation]: https://
|
226
|
+
[official Cucumber documentation]: https://rspec.info/features/6-0/rspec-rails
|
227
227
|
|
228
228
|
## What tests should I write?
|
229
229
|
|
@@ -268,20 +268,20 @@ RSpec.describe User, type: :model do
|
|
268
268
|
...
|
269
269
|
```
|
270
270
|
|
271
|
-
[request]: https://
|
272
|
-
[feature]: https://
|
273
|
-
[system]: https://
|
274
|
-
[model]: https://
|
275
|
-
[controller]: https://
|
276
|
-
[mailer]: https://
|
277
|
-
[job]: https://
|
278
|
-
[view]: https://
|
279
|
-
[routing]: https://
|
280
|
-
[helper]: https://
|
271
|
+
[request]: https://rspec.info/features/6-0/rspec-rails/request-specs/request-spec
|
272
|
+
[feature]: https://rspec.info/features/6-0/rspec-rails/feature-specs/feature-spec
|
273
|
+
[system]: https://rspec.info/features/6-0/rspec-rails/system-specs/system-specs
|
274
|
+
[model]: https://rspec.info/features/6-0/rspec-rails/model-specs
|
275
|
+
[controller]: https://rspec.info/features/6-0/rspec-rails/controller-specs
|
276
|
+
[mailer]: https://rspec.info/features/6-0/rspec-rails/mailer-specs
|
277
|
+
[job]: https://rspec.info/features/6-0/rspec-rails/job-specs/job-spec
|
278
|
+
[view]: https://rspec.info/features/6-0/rspec-rails/view-specs/view-spec
|
279
|
+
[routing]: https://rspec.info/features/6-0/rspec-rails/routing-specs
|
280
|
+
[helper]: https://rspec.info/features/6-0/rspec-rails/helper-specs/helper-spec
|
281
281
|
[`ActionDispatch::IntegrationTest`]: https://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html
|
282
282
|
[`ActionDispatch::SystemTestCase`]: https://api.rubyonrails.org/classes/ActionDispatch/SystemTestCase.html
|
283
283
|
[`ActionController::TestCase`]: https://api.rubyonrails.org/classes/ActionController/TestCase.html
|
284
|
-
[in the appropriate folder]: https://
|
284
|
+
[in the appropriate folder]: https://rspec.info/features/6-0/rspec-rails/directory-structure
|
285
285
|
|
286
286
|
### System specs, feature specs, request specs–what’s the difference?
|
287
287
|
|
@@ -364,10 +364,10 @@ you can run the specs and Cucumber features, or submit a pull request.
|
|
364
364
|
|
365
365
|
### RSpec base libraries
|
366
366
|
|
367
|
-
*
|
368
|
-
*
|
369
|
-
*
|
370
|
-
*
|
367
|
+
* https://github.com/rspec/rspec
|
368
|
+
* https://github.com/rspec/rspec-core
|
369
|
+
* https://github.com/rspec/rspec-expectations
|
370
|
+
* https://github.com/rspec/rspec-mocks
|
371
371
|
|
372
372
|
### Recommended third-party extensions
|
373
373
|
|
@@ -5,7 +5,7 @@ module Rspec
|
|
5
5
|
# @private
|
6
6
|
class ChannelGenerator < Base
|
7
7
|
def create_channel_spec
|
8
|
-
template 'channel_spec.rb.erb',
|
8
|
+
template 'channel_spec.rb.erb', target_path('channels', class_path, "#{file_name}_channel_spec.rb")
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -16,14 +16,14 @@ module Rspec
|
|
16
16
|
return unless options[:request_specs]
|
17
17
|
|
18
18
|
template 'request_spec.rb',
|
19
|
-
|
19
|
+
target_path('requests', class_path, "#{file_name}_spec.rb")
|
20
20
|
end
|
21
21
|
|
22
22
|
def generate_controller_spec
|
23
23
|
return unless options[:controller_specs]
|
24
24
|
|
25
25
|
template 'controller_spec.rb',
|
26
|
-
|
26
|
+
target_path('controllers', class_path, "#{file_name}_controller_spec.rb")
|
27
27
|
end
|
28
28
|
|
29
29
|
def generate_view_specs
|
@@ -35,7 +35,7 @@ module Rspec
|
|
35
35
|
actions.each do |action|
|
36
36
|
@action = action
|
37
37
|
template 'view_spec.rb',
|
38
|
-
|
38
|
+
target_path('views', file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -44,7 +44,7 @@ module Rspec
|
|
44
44
|
return unless options[:routing_specs]
|
45
45
|
|
46
46
|
template 'routing_spec.rb',
|
47
|
-
|
47
|
+
target_path('routing', class_path, "#{file_name}_routing_spec.rb")
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -10,7 +10,7 @@ module Rspec
|
|
10
10
|
def generate_feature_spec
|
11
11
|
return unless options[:feature_specs]
|
12
12
|
|
13
|
-
template template_name,
|
13
|
+
template template_name, target_path('features', class_path, filename)
|
14
14
|
end
|
15
15
|
|
16
16
|
def template_name
|
@@ -9,7 +9,7 @@ module Rspec
|
|
9
9
|
def generate_generator_spec
|
10
10
|
return unless options[:generator_specs]
|
11
11
|
|
12
|
-
template template_name,
|
12
|
+
template template_name, target_path('generator', class_path, filename)
|
13
13
|
end
|
14
14
|
|
15
15
|
def template_name
|
@@ -9,7 +9,7 @@ module Rspec
|
|
9
9
|
def generate_helper_spec
|
10
10
|
return unless options[:helper_specs]
|
11
11
|
|
12
|
-
template 'helper_spec.rb',
|
12
|
+
template 'helper_spec.rb', target_path('helpers', class_path, "#{file_name}_helper_spec.rb")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -12,6 +12,8 @@ Description:
|
|
12
12
|
Copy rspec files to your application.
|
13
13
|
DESC
|
14
14
|
|
15
|
+
class_option :default_path, type: :string, default: 'spec'
|
16
|
+
|
15
17
|
def self.source_root
|
16
18
|
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
17
19
|
end
|
@@ -20,12 +22,12 @@ DESC
|
|
20
22
|
Dir.mktmpdir do |dir|
|
21
23
|
generate_rspec_init dir
|
22
24
|
template File.join(dir, '.rspec'), '.rspec'
|
23
|
-
directory File.join(dir, 'spec'),
|
25
|
+
directory File.join(dir, 'spec'), default_path
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
29
|
def copy_rails_files
|
28
|
-
template 'spec/rails_helper.rb'
|
30
|
+
template 'spec/rails_helper.rb', "#{default_path}/rails_helper.rb"
|
29
31
|
end
|
30
32
|
|
31
33
|
private
|
@@ -41,6 +43,12 @@ DESC
|
|
41
43
|
|
42
44
|
replace_generator_command(spec_helper_path)
|
43
45
|
remove_warnings_configuration(spec_helper_path)
|
46
|
+
|
47
|
+
unless default_path == "spec"
|
48
|
+
dot_rspec_path = File.join(tmpdir, '.rspec')
|
49
|
+
|
50
|
+
append_default_path(dot_rspec_path)
|
51
|
+
end
|
44
52
|
end
|
45
53
|
|
46
54
|
def replace_generator_command(spec_helper_path)
|
@@ -58,6 +66,15 @@ DESC
|
|
58
66
|
'',
|
59
67
|
verbose: false
|
60
68
|
end
|
69
|
+
|
70
|
+
def append_default_path(dot_rspec_path)
|
71
|
+
append_to_file dot_rspec_path,
|
72
|
+
"--default-path #{default_path}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def default_path
|
76
|
+
options[:default_path]
|
77
|
+
end
|
61
78
|
end
|
62
79
|
end
|
63
80
|
end
|
@@ -28,8 +28,7 @@ require 'rspec/rails'
|
|
28
28
|
begin
|
29
29
|
ActiveRecord::Migration.maintain_test_schema!
|
30
30
|
rescue ActiveRecord::PendingMigrationError => e
|
31
|
-
|
32
|
-
exit 1
|
31
|
+
abort e.to_s.strip
|
33
32
|
end
|
34
33
|
<% end -%>
|
35
34
|
RSpec.configure do |config|
|
@@ -49,7 +48,7 @@ RSpec.configure do |config|
|
|
49
48
|
# Remove this line to enable support for ActiveRecord
|
50
49
|
config.use_active_record = false
|
51
50
|
|
52
|
-
# If you enable ActiveRecord support you should
|
51
|
+
# If you enable ActiveRecord support you should uncomment these lines,
|
53
52
|
# note if you'd prefer not to run each example within a transaction, you
|
54
53
|
# should set use_transactional_fixtures to false.
|
55
54
|
#
|
@@ -69,7 +68,7 @@ RSpec.configure do |config|
|
|
69
68
|
# end
|
70
69
|
#
|
71
70
|
# The different available types are documented in the features, such as in
|
72
|
-
# https://
|
71
|
+
# https://rspec.info/features/6-0/rspec-rails
|
73
72
|
config.infer_spec_type_from_file_location!
|
74
73
|
|
75
74
|
# Filter lines from Rails gems in backtraces.
|
@@ -1,21 +1,28 @@
|
|
1
1
|
require 'generators/rspec'
|
2
|
+
require 'rspec/core/warnings'
|
2
3
|
|
3
4
|
module Rspec
|
4
5
|
module Generators
|
5
6
|
# @private
|
6
7
|
class IntegrationGenerator < Base
|
7
|
-
# Add a deprecation for this class, before rspec-rails 4, to use the
|
8
|
-
# `RequestGenerator` instead
|
9
8
|
class_option :request_specs,
|
10
9
|
type: :boolean,
|
11
10
|
default: true,
|
12
11
|
desc: "Generate request specs"
|
13
12
|
|
13
|
+
source_paths << File.expand_path('../request/templates', __dir__)
|
14
|
+
|
14
15
|
def generate_request_spec
|
15
16
|
return unless options[:request_specs]
|
16
17
|
|
18
|
+
RSpec.warn_deprecation <<-WARNING.gsub(/\s*\|/, ' ')
|
19
|
+
|The integration generator is deprecated
|
20
|
+
|and will be deleted in RSpec-Rails 7.
|
21
|
+
|Please use the request generator instead.
|
22
|
+
WARNING
|
23
|
+
|
17
24
|
template 'request_spec.rb',
|
18
|
-
|
25
|
+
target_path('requests', "#{name.underscore.pluralize}_spec.rb")
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
@@ -6,7 +6,7 @@ module Rspec
|
|
6
6
|
class JobGenerator < Base
|
7
7
|
def create_job_spec
|
8
8
|
file_suffix = file_name.end_with?('job') ? 'spec.rb' : 'job_spec.rb'
|
9
|
-
template 'job_spec.rb.erb',
|
9
|
+
template 'job_spec.rb.erb', target_path('jobs', class_path, [file_name, file_suffix].join('_'))
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -6,7 +6,7 @@ module Rspec
|
|
6
6
|
class MailboxGenerator < Base
|
7
7
|
def create_mailbox_spec
|
8
8
|
template('mailbox_spec.rb.erb',
|
9
|
-
|
9
|
+
target_path('mailboxes', class_path, "#{file_name}_mailbox_spec.rb")
|
10
10
|
)
|
11
11
|
end
|
12
12
|
end
|
@@ -8,20 +8,20 @@ module Rspec
|
|
8
8
|
argument :actions, type: :array, default: [], banner: "method method"
|
9
9
|
|
10
10
|
def generate_mailer_spec
|
11
|
-
template "mailer_spec.rb",
|
11
|
+
template "mailer_spec.rb", target_path('mailers', class_path, "#{file_name}_spec.rb")
|
12
12
|
end
|
13
13
|
|
14
14
|
def generate_fixtures_files
|
15
15
|
actions.each do |action|
|
16
16
|
@action, @path = action, File.join(file_path, action)
|
17
|
-
template "fixture",
|
17
|
+
template "fixture", target_path("fixtures", @path)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def generate_preview_files
|
22
22
|
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
|
23
23
|
|
24
|
-
template "preview.rb",
|
24
|
+
template "preview.rb", target_path("mailers/previews", class_path, "#{file_name}_preview.rb")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -11,8 +11,8 @@ module Rspec
|
|
11
11
|
class_option :fixture, type: :boolean
|
12
12
|
|
13
13
|
def create_model_spec
|
14
|
-
template_file =
|
15
|
-
'
|
14
|
+
template_file = target_path(
|
15
|
+
'models',
|
16
16
|
class_path,
|
17
17
|
"#{file_name}_spec.rb"
|
18
18
|
)
|
@@ -24,7 +24,7 @@ module Rspec
|
|
24
24
|
def create_fixture_file
|
25
25
|
return unless missing_fixture_replacement?
|
26
26
|
|
27
|
-
template 'fixtures.yml',
|
27
|
+
template 'fixtures.yml', target_path('fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
@@ -1,10 +1,17 @@
|
|
1
|
-
require 'generators/rspec
|
1
|
+
require 'generators/rspec'
|
2
2
|
|
3
3
|
module Rspec
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
|
-
class RequestGenerator <
|
7
|
-
|
6
|
+
class RequestGenerator < Base
|
7
|
+
class_option :request_specs, type: :boolean, default: true, desc: 'Generate request specs'
|
8
|
+
|
9
|
+
def generate_request_spec
|
10
|
+
return unless options[:request_specs]
|
11
|
+
|
12
|
+
template 'request_spec.rb',
|
13
|
+
target_path('requests', "#{name.underscore.pluralize}_spec.rb")
|
14
|
+
end
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
@@ -58,8 +58,8 @@ module Rspec
|
|
58
58
|
def generate_routing_spec
|
59
59
|
return unless options[:routing_specs]
|
60
60
|
|
61
|
-
template_file =
|
62
|
-
'
|
61
|
+
template_file = target_path(
|
62
|
+
'routing',
|
63
63
|
controller_class_path,
|
64
64
|
"#{controller_file_name}_routing_spec.rb"
|
65
65
|
)
|
@@ -72,7 +72,7 @@ module Rspec
|
|
72
72
|
|
73
73
|
def copy_view(view)
|
74
74
|
template "#{view}_spec.rb",
|
75
|
-
|
75
|
+
target_path("views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
|
76
76
|
end
|
77
77
|
|
78
78
|
# support for namespaced-resources
|
@@ -121,7 +121,7 @@ module Rspec
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def template_file(folder:, suffix: '')
|
124
|
-
|
124
|
+
target_path(folder, controller_class_path, "#{controller_file_name}#{suffix}_spec.rb")
|
125
125
|
end
|
126
126
|
|
127
127
|
def banner
|
@@ -100,7 +100,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
100
100
|
|
101
101
|
it "renders a JSON response with the <%= singular_table_name %>" do
|
102
102
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
103
|
-
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>:
|
103
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
104
104
|
expect(response).to have_http_status(:ok)
|
105
105
|
expect(response.content_type).to eq('application/json')
|
106
106
|
end
|
@@ -90,10 +90,17 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
90
90
|
end
|
91
91
|
|
92
92
|
context "with invalid params" do
|
93
|
+
<% if Rails.version.to_f < 7.0 %>
|
93
94
|
it "returns a success response (i.e. to display the 'new' template)" do
|
94
95
|
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
95
96
|
expect(response).to be_successful
|
96
97
|
end
|
98
|
+
<% else %>
|
99
|
+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
100
|
+
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
101
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
102
|
+
end
|
103
|
+
<% end %>
|
97
104
|
end
|
98
105
|
end
|
99
106
|
|
@@ -112,17 +119,25 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
112
119
|
|
113
120
|
it "redirects to the <%= singular_table_name %>" do
|
114
121
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
115
|
-
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>:
|
122
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
116
123
|
expect(response).to redirect_to(<%= file_name %>)
|
117
124
|
end
|
118
125
|
end
|
119
126
|
|
120
127
|
context "with invalid params" do
|
128
|
+
<% if Rails.version.to_f < 7.0 %>
|
121
129
|
it "returns a success response (i.e. to display the 'edit' template)" do
|
122
130
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
123
131
|
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
124
132
|
expect(response).to be_successful
|
125
133
|
end
|
134
|
+
<% else %>
|
135
|
+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
136
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
137
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
138
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
139
|
+
end
|
140
|
+
<% end %>
|
126
141
|
end
|
127
142
|
end
|
128
143
|
|