rspec-rails 5.1.2 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +355 -173
- data/README.md +40 -40
- 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 +3 -3
- data/lib/generators/rspec/generator/templates/generator_spec.rb +1 -2
- 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 +27 -15
- 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 +5 -3
- data/lib/generators/rspec/mailer/templates/preview.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/controller_spec.rb +4 -4
- 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/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +4 -4
- 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 +43 -14
- data/lib/rspec/rails/example/mailbox_example_group.rb +1 -1
- data/lib/rspec/rails/example/rails_example_group.rb +6 -0
- data/lib/rspec/rails/example/routing_example_group.rb +0 -2
- data/lib/rspec/rails/example/system_example_group.rb +67 -12
- data/lib/rspec/rails/example/view_example_group.rb +6 -5
- 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 +20 -31
- data/lib/rspec/rails/fixture_support.rb +44 -17
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +16 -6
- data/lib/rspec/rails/matchers/action_cable.rb +6 -1
- data/lib/rspec/rails/matchers/active_job.rb +73 -12
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +40 -7
- data/lib/rspec/rails/matchers/have_http_status.rb +4 -8
- data/lib/rspec/rails/matchers/routing_matchers.rb +2 -2
- data/lib/rspec/rails/matchers/send_email.rb +122 -0
- data/lib/rspec/rails/matchers.rb +1 -0
- data/lib/rspec/rails/tasks/rspec.rake +3 -1
- 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 +28 -7
- data.tar.gz.sig +0 -0
- metadata +42 -58
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/integration/integration_generator.rb +0 -22
- /data/lib/generators/rspec/{integration → request}/templates/request_spec.rb +0 -0
data/README.md
CHANGED
@@ -9,13 +9,13 @@ 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` 7.x][]** for Rails 7.x.
|
13
|
+
* **[`rspec-rails` 6.x][]** for Rails 6.1, 7.0 or 7.1.
|
14
|
+
* **[`rspec-rails` 5.x][]** for Rails 5.2 or 6.x.
|
13
15
|
* **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x.
|
14
16
|
* **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
|
15
17
|
* **[`rspec-rails` 1.x][]** for Rails 2.x.
|
16
18
|
|
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
19
|
[Code Climate]: https://codeclimate.com/github/rspec/rspec-rails.svg
|
20
20
|
[code-climate]: https://codeclimate.com/github/rspec/rspec-rails
|
21
21
|
[Gem Version]: https://badge.fury.io/rb/rspec-rails.svg
|
@@ -25,13 +25,16 @@ According to [RSpec Rails new versioning strategy][] use:
|
|
25
25
|
[`rspec-rails` 1.x]: https://github.com/dchelimsky/rspec-rails
|
26
26
|
[`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
|
27
27
|
[`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-
|
28
|
+
[`rspec-rails` 5.x]: https://github.com/rspec/rspec-rails/tree/5-1-maintenance
|
29
|
+
[`rspec-rails` 6.x]: https://github.com/rspec/rspec-rails/tree/6-1-maintenance
|
30
|
+
[`rspec-rails` 7.x]: https://github.com/rspec/rspec-rails/tree/7-1-maintenance
|
29
31
|
[RSpec Rails new versioning strategy]: https://github.com/rspec/rspec-rails/blob/main/rfcs/versioning-strategy.md
|
30
32
|
|
31
33
|
## Installation
|
32
34
|
|
33
|
-
**IMPORTANT** This README / branch refers to the
|
34
|
-
See the [`
|
35
|
+
**IMPORTANT** This README / branch refers to the 7.1.x stable release series, only bugfixes from this series will
|
36
|
+
be added here. See the [`main` branch on Github](https://github.com/rspec/rspec-rails/tree/main) if you want or
|
37
|
+
require the latest unstable features.
|
35
38
|
|
36
39
|
1. Add `rspec-rails` to **both** the `:development` and `:test` groups
|
37
40
|
of your app’s `Gemfile`:
|
@@ -39,15 +42,12 @@ See the [`5-0-maintenance` branch on Github](https://github.com/rspec/rspec-rail
|
|
39
42
|
```ruby
|
40
43
|
# Run against this stable release
|
41
44
|
group :development, :test do
|
42
|
-
gem 'rspec-rails', '~>
|
45
|
+
gem 'rspec-rails', '~> 7.0.0'
|
43
46
|
end
|
44
47
|
|
45
48
|
# Or, run against the main branch
|
46
|
-
# (requires main-branch versions of all related RSpec libraries)
|
47
49
|
group :development, :test do
|
48
|
-
|
49
|
-
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'main'
|
50
|
-
end
|
50
|
+
gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails'
|
51
51
|
end
|
52
52
|
```
|
53
53
|
|
@@ -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/7-1/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/7-1/rspec-rails/matchers/new-record-matcher
|
212
|
+
[`render_template`]: https://rspec.info/features/7-1/rspec-rails/matchers/render-template-matcher
|
213
|
+
[`redirect_to`]: https://rspec.info/features/7-1/rspec-rails/matchers/redirect-to-matcher
|
214
|
+
[`route_to`]: https://rspec.info/features/7-1/rspec-rails/routing-specs/route-to-matcher
|
215
|
+
[`be_routable`]: https://rspec.info/features/7-1/rspec-rails/routing-specs/be-routable-matcher
|
216
|
+
[`have_http_status`]: https://rspec.info/features/7-1/rspec-rails/matchers/have-http-status-matcher
|
217
|
+
[`match_array`]: https://rspec.info/features/7-1/rspec-rails/matchers/relation-match-array
|
218
|
+
[`have_been_enqueued`]: https://rspec.info/features/7-1/rspec-rails/matchers/have-been-enqueued-matcher
|
219
|
+
[`have_enqueued_job`]: https://rspec.info/features/7-1/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/7-1/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/7-1/rspec-rails/request-specs/request-spec
|
272
|
+
[feature]: https://rspec.info/features/7-1/rspec-rails/feature-specs/feature-spec
|
273
|
+
[system]: https://rspec.info/features/7-1/rspec-rails/system-specs/system-specs
|
274
|
+
[model]: https://rspec.info/features/7-1/rspec-rails/model-specs
|
275
|
+
[controller]: https://rspec.info/features/7-1/rspec-rails/controller-specs
|
276
|
+
[mailer]: https://rspec.info/features/7-1/rspec-rails/mailer-specs
|
277
|
+
[job]: https://rspec.info/features/7-1/rspec-rails/job-specs/job-spec
|
278
|
+
[view]: https://rspec.info/features/7-1/rspec-rails/view-specs/view-spec
|
279
|
+
[routing]: https://rspec.info/features/7-1/rspec-rails/routing-specs
|
280
|
+
[helper]: https://rspec.info/features/7-1/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/7-1/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
|
@@ -4,12 +4,12 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class GeneratorGenerator < Base
|
7
|
-
class_option :generator_specs, type: :boolean, default: true,
|
7
|
+
class_option :generator_specs, type: :boolean, default: true, desc: 'Generate generator specs'
|
8
8
|
|
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
|
@@ -17,7 +17,7 @@ module Rspec
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def filename
|
20
|
-
"#{
|
20
|
+
"#{file_name}_generator_spec.rb"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -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
|
@@ -4,6 +4,11 @@ ENV['RAILS_ENV'] ||= 'test'
|
|
4
4
|
require_relative '../config/environment'
|
5
5
|
# Prevent database truncation if the environment is production
|
6
6
|
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
7
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
|
8
|
+
# Uncomment the line below in case you have `--require rails_helper` in the `.rspec` file
|
9
|
+
# that will avoid rails generators crashing because migrations haven't been run yet
|
10
|
+
# return unless Rails.env.test?
|
11
|
+
<% end -%>
|
7
12
|
require 'rspec/rails'
|
8
13
|
# Add additional requires below this line. Rails is not loaded until this point!
|
9
14
|
|
@@ -20,7 +25,7 @@ require 'rspec/rails'
|
|
20
25
|
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
21
26
|
# require only the support files necessary.
|
22
27
|
#
|
23
|
-
#
|
28
|
+
# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
|
24
29
|
|
25
30
|
<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
|
26
31
|
# Checks for pending migrations and applies them before tests are run.
|
@@ -28,14 +33,19 @@ require 'rspec/rails'
|
|
28
33
|
begin
|
29
34
|
ActiveRecord::Migration.maintain_test_schema!
|
30
35
|
rescue ActiveRecord::PendingMigrationError => e
|
31
|
-
|
32
|
-
exit 1
|
36
|
+
abort e.to_s.strip
|
33
37
|
end
|
34
38
|
<% end -%>
|
35
39
|
RSpec.configure do |config|
|
36
40
|
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
37
41
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
38
|
-
|
42
|
+
<% if ::Rails::VERSION::STRING < "7.1.0" -%>
|
43
|
+
config.fixture_path = Rails.root.join('spec/fixtures')
|
44
|
+
<% else -%>
|
45
|
+
config.fixture_paths = [
|
46
|
+
Rails.root.join('spec/fixtures')
|
47
|
+
]
|
48
|
+
<% end -%>
|
39
49
|
|
40
50
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
41
51
|
# examples within a transaction, remove the following line or assign false
|
@@ -49,28 +59,30 @@ RSpec.configure do |config|
|
|
49
59
|
# Remove this line to enable support for ActiveRecord
|
50
60
|
config.use_active_record = false
|
51
61
|
|
52
|
-
# If you enable ActiveRecord support you should
|
62
|
+
# If you enable ActiveRecord support you should uncomment these lines,
|
53
63
|
# note if you'd prefer not to run each example within a transaction, you
|
54
64
|
# should set use_transactional_fixtures to false.
|
55
65
|
#
|
56
|
-
# config.fixture_path =
|
66
|
+
# config.fixture_path = Rails.root.join('spec/fixtures')
|
57
67
|
# config.use_transactional_fixtures = true
|
58
68
|
|
59
69
|
<% end -%>
|
60
|
-
# RSpec Rails
|
61
|
-
#
|
62
|
-
# `post` in specs under `spec/controllers`.
|
70
|
+
# RSpec Rails uses metadata to mix in different behaviours to your tests,
|
71
|
+
# for example enabling you to call `get` and `post` in request specs. e.g.:
|
63
72
|
#
|
64
|
-
#
|
65
|
-
# explicitly tag your specs with their type, e.g.:
|
66
|
-
#
|
67
|
-
# RSpec.describe UsersController, type: :controller do
|
73
|
+
# RSpec.describe UsersController, type: :request do
|
68
74
|
# # ...
|
69
75
|
# end
|
70
76
|
#
|
71
77
|
# The different available types are documented in the features, such as in
|
72
|
-
# https://
|
73
|
-
|
78
|
+
# https://rspec.info/features/7-1/rspec-rails
|
79
|
+
#
|
80
|
+
# You can also this infer these behaviours automatically by location, e.g.
|
81
|
+
# /spec/models would pull in the same behaviour as `type: :model` but this
|
82
|
+
# behaviour is considered legacy and will be removed in a future version.
|
83
|
+
#
|
84
|
+
# To enable this behaviour uncomment the line below.
|
85
|
+
# config.infer_spec_type_from_file_location!
|
74
86
|
|
75
87
|
# Filter lines from Rails gems in backtraces.
|
76
88
|
config.filter_rails_from_backtrace!
|
@@ -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,22 @@ module Rspec
|
|
8
8
|
argument :actions, type: :array, default: [], banner: "method method"
|
9
9
|
|
10
10
|
def generate_mailer_spec
|
11
|
-
|
11
|
+
file_suffix = file_name.end_with?('mailer') ? 'spec.rb' : 'mailer_spec.rb'
|
12
|
+
template "mailer_spec.rb", target_path('mailers', class_path, [file_name, file_suffix].join('_'))
|
12
13
|
end
|
13
14
|
|
14
15
|
def generate_fixtures_files
|
15
16
|
actions.each do |action|
|
16
17
|
@action, @path = action, File.join(file_path, action)
|
17
|
-
template "fixture",
|
18
|
+
template "fixture", target_path("fixtures", @path)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
def generate_preview_files
|
22
23
|
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
|
23
24
|
|
24
|
-
|
25
|
+
file_suffix = file_name.end_with?('mailer') ? 'preview.rb' : 'mailer_preview.rb'
|
26
|
+
template "preview.rb", target_path("mailers/previews", class_path, [file_name, file_suffix].join('_'))
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
|
-
# Preview all emails at http://localhost:3000/rails/mailers/<%= file_path %>
|
3
|
-
class <%= class_name %>Preview < ActionMailer::Preview
|
2
|
+
# Preview all emails at http://localhost:3000/rails/mailers/<%= file_path %>_mailer
|
3
|
+
class <%= class_name %><%= 'Mailer' unless class_name.end_with?('Mailer') %>Preview < ActionMailer::Preview
|
4
4
|
<% actions.each do |action| -%>
|
5
5
|
|
6
|
-
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path
|
6
|
+
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>_mailer/<%= action %>
|
7
7
|
def <%= action %>
|
8
8
|
<%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %>
|
9
9
|
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
|
@@ -90,9 +90,9 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
90
90
|
end
|
91
91
|
|
92
92
|
context "with invalid params" do
|
93
|
-
it "
|
93
|
+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
94
94
|
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
95
|
-
expect(response).to
|
95
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -118,10 +118,10 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
118
118
|
end
|
119
119
|
|
120
120
|
context "with invalid params" do
|
121
|
-
it "
|
121
|
+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
122
122
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
123
123
|
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
124
|
-
expect(response).to
|
124
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
@@ -2,18 +2,22 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
4
|
RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
5
|
-
|
6
|
-
|
5
|
+
let(:<%= singular_table_name %>) {
|
6
|
+
<%= class_name %>.create!(<%= ')' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
<%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
10
|
-
<%=
|
10
|
+
<%= " )\n" unless output_attributes.empty? -%>
|
11
|
+
}
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
assign(:<%= singular_table_name %>, <%= singular_table_name %>)
|
11
15
|
end
|
12
16
|
|
13
17
|
it "renders the edit <%= ns_file_name %> form" do
|
14
18
|
render
|
15
19
|
|
16
|
-
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(
|
20
|
+
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(<%= singular_table_name %>), "post" do
|
17
21
|
<% for attribute in output_attributes -%>
|
18
22
|
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
19
23
|
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
@@ -18,8 +18,9 @@ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
|
|
18
18
|
|
19
19
|
it "renders a list of <%= ns_table_name %>" do
|
20
20
|
render
|
21
|
+
cell_selector = 'div>p'
|
21
22
|
<% for attribute in output_attributes -%>
|
22
|
-
assert_select
|
23
|
+
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
|
23
24
|
<% end -%>
|
24
25
|
end
|
25
26
|
end
|
@@ -3,7 +3,7 @@ require 'rails_helper'
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
4
|
RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
assign(:<%=
|
6
|
+
assign(:<%= singular_table_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
<%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
@@ -83,9 +83,9 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
83
83
|
}.to change(<%= class_name %>, :count).by(0)
|
84
84
|
end
|
85
85
|
|
86
|
-
it "renders a
|
86
|
+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
87
87
|
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
88
|
-
expect(response).to
|
88
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -112,10 +112,10 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
112
112
|
end
|
113
113
|
|
114
114
|
context "with invalid parameters" do
|
115
|
-
it "renders a
|
115
|
+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
116
116
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
117
117
|
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
|
118
|
-
expect(response).to
|
118
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|