rspec-rails 6.1.3 → 8.0.2
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 +296 -198
- data/README.md +31 -33
- data/lib/generators/rspec/authentication/authentication_generator.rb +25 -0
- data/lib/generators/rspec/authentication/templates/user_spec.rb +5 -0
- data/lib/generators/rspec/authentication/templates/users.yml +11 -0
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +23 -16
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +2 -17
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +2 -17
- data/lib/rspec/rails/configuration.rb +3 -67
- data/lib/rspec/rails/example/rails_example_group.rb +5 -9
- data/lib/rspec/rails/example/system_example_group.rb +41 -36
- data/lib/rspec/rails/fixture_file_upload_support.rb +2 -8
- data/lib/rspec/rails/fixture_support.rb +13 -44
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +10 -3
- data/lib/rspec/rails/matchers/action_cable.rb +6 -1
- data/lib/rspec/rails/matchers/active_job.rb +77 -8
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +37 -5
- data/lib/rspec/rails/matchers/have_http_status.rb +2 -2
- data/lib/rspec/rails/tasks/rspec.rake +3 -1
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec-rails.rb +20 -11
- data.tar.gz.sig +0 -0
- metadata +37 -39
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/integration/integration_generator.rb +0 -29
data/README.md
CHANGED
|
@@ -9,7 +9,9 @@ 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` 8.x][]** for Rails 8.0 or 7.2.
|
|
13
|
+
* **[`rspec-rails` 7.x][]** for Rails 7.x.
|
|
14
|
+
* **[`rspec-rails` 6.x][]** for Rails 6.1, 7.0 or 7.1.
|
|
13
15
|
* **[`rspec-rails` 5.x][]** for Rails 5.2 or 6.x.
|
|
14
16
|
* **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x.
|
|
15
17
|
* **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
|
|
@@ -26,13 +28,15 @@ According to [RSpec Rails new versioning strategy][] use:
|
|
|
26
28
|
[`rspec-rails` 4.x]: https://github.com/rspec/rspec-rails/tree/4-1-maintenance
|
|
27
29
|
[`rspec-rails` 5.x]: https://github.com/rspec/rspec-rails/tree/5-1-maintenance
|
|
28
30
|
[`rspec-rails` 6.x]: https://github.com/rspec/rspec-rails/tree/6-1-maintenance
|
|
31
|
+
[`rspec-rails` 7.x]: https://github.com/rspec/rspec-rails/tree/7-1-maintenance
|
|
32
|
+
[`rspec-rails` 8.x]: https://github.com/rspec/rspec-rails/tree/8-0-maintenance
|
|
29
33
|
[RSpec Rails new versioning strategy]: https://github.com/rspec/rspec-rails/blob/main/rfcs/versioning-strategy.md
|
|
30
34
|
|
|
31
35
|
## Installation
|
|
32
36
|
|
|
33
|
-
**IMPORTANT** This README / branch refers to the
|
|
37
|
+
**IMPORTANT** This README / branch refers to the 8.0.x stable release series, only bugfixes from this series will
|
|
34
38
|
be added here. See the [`main` branch on Github](https://github.com/rspec/rspec-rails/tree/main) if you want or
|
|
35
|
-
require the latest unstable features.
|
|
39
|
+
require the latest unstable features.https://github.com/rspec/rspec-rails/tree/8-0-maintenance) if you want or require the latest stable release.
|
|
36
40
|
|
|
37
41
|
1. Add `rspec-rails` to **both** the `:development` and `:test` groups
|
|
38
42
|
of your app’s `Gemfile`:
|
|
@@ -40,15 +44,12 @@ require the latest unstable features.
|
|
|
40
44
|
```ruby
|
|
41
45
|
# Run against this stable release
|
|
42
46
|
group :development, :test do
|
|
43
|
-
gem 'rspec-rails', '~>
|
|
47
|
+
gem 'rspec-rails', '~> 8.0.0'
|
|
44
48
|
end
|
|
45
49
|
|
|
46
50
|
# Or, run against the main branch
|
|
47
|
-
# (requires main-branch versions of all related RSpec libraries)
|
|
48
51
|
group :development, :test do
|
|
49
|
-
|
|
50
|
-
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'main'
|
|
51
|
-
end
|
|
52
|
+
gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails'
|
|
52
53
|
end
|
|
53
54
|
```
|
|
54
55
|
|
|
@@ -87,7 +88,7 @@ read the [`rspec-rails` upgrade notes][] to find out what to watch out for.
|
|
|
87
88
|
|
|
88
89
|
Be sure to check the general [RSpec upgrade notes][] as well.
|
|
89
90
|
|
|
90
|
-
[`rspec-rails` upgrade notes]: https://rspec.info/features/
|
|
91
|
+
[`rspec-rails` upgrade notes]: https://rspec.info/features/8-0/rspec-rails/upgrade
|
|
91
92
|
[RSpec upgrade notes]: https://rspec.info/upgrading-from-rspec-2/
|
|
92
93
|
|
|
93
94
|
## Usage
|
|
@@ -209,22 +210,22 @@ to test the various parts of a Rails system:
|
|
|
209
210
|
Follow the links above for examples of how each matcher is used.
|
|
210
211
|
|
|
211
212
|
[the matchers that come standard in RSpec]: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers
|
|
212
|
-
[`be_a_new`]: https://rspec.info/features/
|
|
213
|
-
[`render_template`]: https://rspec.info/features/
|
|
214
|
-
[`redirect_to`]: https://rspec.info/features/
|
|
215
|
-
[`route_to`]: https://rspec.info/features/
|
|
216
|
-
[`be_routable`]: https://rspec.info/features/
|
|
217
|
-
[`have_http_status`]: https://rspec.info/features/
|
|
218
|
-
[`match_array`]: https://rspec.info/features/
|
|
219
|
-
[`have_been_enqueued`]: https://rspec.info/features/
|
|
220
|
-
[`have_enqueued_job`]: https://rspec.info/features/
|
|
213
|
+
[`be_a_new`]: https://rspec.info/features/8-0/rspec-rails/matchers/new-record-matcher
|
|
214
|
+
[`render_template`]: https://rspec.info/features/8-0/rspec-rails/matchers/render-template-matcher
|
|
215
|
+
[`redirect_to`]: https://rspec.info/features/8-0/rspec-rails/matchers/redirect-to-matcher
|
|
216
|
+
[`route_to`]: https://rspec.info/features/8-0/rspec-rails/routing-specs/route-to-matcher
|
|
217
|
+
[`be_routable`]: https://rspec.info/features/8-0/rspec-rails/routing-specs/be-routable-matcher
|
|
218
|
+
[`have_http_status`]: https://rspec.info/features/8-0/rspec-rails/matchers/have-http-status-matcher
|
|
219
|
+
[`match_array`]: https://rspec.info/features/8-0/rspec-rails/matchers/relation-match-array
|
|
220
|
+
[`have_been_enqueued`]: https://rspec.info/features/8-0/rspec-rails/matchers/have-been-enqueued-matcher
|
|
221
|
+
[`have_enqueued_job`]: https://rspec.info/features/8-0/rspec-rails/matchers/have-enqueued-job-matcher
|
|
221
222
|
|
|
222
223
|
### What else does RSpec Rails add?
|
|
223
224
|
|
|
224
225
|
For a comprehensive look at RSpec Rails’ features,
|
|
225
226
|
read the [official Cucumber documentation][].
|
|
226
227
|
|
|
227
|
-
[official Cucumber documentation]: https://rspec.info/features/
|
|
228
|
+
[official Cucumber documentation]: https://rspec.info/features/8-0/rspec-rails
|
|
228
229
|
|
|
229
230
|
## What tests should I write?
|
|
230
231
|
|
|
@@ -269,20 +270,20 @@ RSpec.describe User, type: :model do
|
|
|
269
270
|
...
|
|
270
271
|
```
|
|
271
272
|
|
|
272
|
-
[request]: https://rspec.info/features/
|
|
273
|
-
[feature]: https://rspec.info/features/
|
|
274
|
-
[system]: https://rspec.info/features/
|
|
275
|
-
[model]: https://rspec.info/features/
|
|
276
|
-
[controller]: https://rspec.info/features/
|
|
277
|
-
[mailer]: https://rspec.info/features/
|
|
278
|
-
[job]: https://rspec.info/features/
|
|
279
|
-
[view]: https://rspec.info/features/
|
|
280
|
-
[routing]: https://rspec.info/features/
|
|
281
|
-
[helper]: https://rspec.info/features/
|
|
273
|
+
[request]: https://rspec.info/features/8-0/rspec-rails/request-specs/request-spec
|
|
274
|
+
[feature]: https://rspec.info/features/8-0/rspec-rails/feature-specs/feature-spec
|
|
275
|
+
[system]: https://rspec.info/features/8-0/rspec-rails/system-specs/system-specs
|
|
276
|
+
[model]: https://rspec.info/features/8-0/rspec-rails/model-specs
|
|
277
|
+
[controller]: https://rspec.info/features/8-0/rspec-rails/controller-specs
|
|
278
|
+
[mailer]: https://rspec.info/features/8-0/rspec-rails/mailer-specs
|
|
279
|
+
[job]: https://rspec.info/features/8-0/rspec-rails/job-specs/job-spec
|
|
280
|
+
[view]: https://rspec.info/features/8-0/rspec-rails/view-specs/view-spec
|
|
281
|
+
[routing]: https://rspec.info/features/8-0/rspec-rails/routing-specs
|
|
282
|
+
[helper]: https://rspec.info/features/8-0/rspec-rails/helper-specs/helper-spec
|
|
282
283
|
[`ActionDispatch::IntegrationTest`]: https://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html
|
|
283
284
|
[`ActionDispatch::SystemTestCase`]: https://api.rubyonrails.org/classes/ActionDispatch/SystemTestCase.html
|
|
284
285
|
[`ActionController::TestCase`]: https://api.rubyonrails.org/classes/ActionController/TestCase.html
|
|
285
|
-
[in the appropriate folder]: https://rspec.info/features/
|
|
286
|
+
[in the appropriate folder]: https://rspec.info/features/8-0/rspec-rails/directory-structure
|
|
286
287
|
|
|
287
288
|
### System specs, feature specs, request specs–what’s the difference?
|
|
288
289
|
|
|
@@ -366,9 +367,6 @@ you can run the specs and Cucumber features, or submit a pull request.
|
|
|
366
367
|
### RSpec base libraries
|
|
367
368
|
|
|
368
369
|
* https://github.com/rspec/rspec
|
|
369
|
-
* https://github.com/rspec/rspec-core
|
|
370
|
-
* https://github.com/rspec/rspec-expectations
|
|
371
|
-
* https://github.com/rspec/rspec-mocks
|
|
372
370
|
|
|
373
371
|
### Recommended third-party extensions
|
|
374
372
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'generators/rspec'
|
|
2
|
+
|
|
3
|
+
module Rspec
|
|
4
|
+
module Generators
|
|
5
|
+
# @private
|
|
6
|
+
class AuthenticationGenerator < Base
|
|
7
|
+
def initialize(args, *options)
|
|
8
|
+
args.replace(['User'])
|
|
9
|
+
super
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create_user_spec
|
|
13
|
+
template 'user_spec.rb', target_path('models', 'user_spec.rb')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
hook_for :fixture_replacement
|
|
17
|
+
|
|
18
|
+
def create_fixture_file
|
|
19
|
+
return if options[:fixture_replacement]
|
|
20
|
+
|
|
21
|
+
template 'users.yml', target_path('fixtures', 'users.yml')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
|
2
|
+
|
|
3
|
+
<%% password_digest = BCrypt::Password.create("password") %>
|
|
4
|
+
|
|
5
|
+
one:
|
|
6
|
+
email_address: one@example.com
|
|
7
|
+
password_digest: <%%= password_digest %>
|
|
8
|
+
|
|
9
|
+
two:
|
|
10
|
+
email_address: two@example.com
|
|
11
|
+
password_digest: <%%= password_digest %>
|
|
@@ -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,10 +25,12 @@ 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
|
-
# Rails.root.glob('spec/support/**/*.rb').
|
|
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
|
+
# Ensures that the test database schema matches the current schema file.
|
|
32
|
+
# If there are pending migrations it will invoke `db:test:prepare` to
|
|
33
|
+
# recreate the test database by loading the schema.
|
|
27
34
|
# If you are not using ActiveRecord, you can remove these lines.
|
|
28
35
|
begin
|
|
29
36
|
ActiveRecord::Migration.maintain_test_schema!
|
|
@@ -34,13 +41,9 @@ end
|
|
|
34
41
|
RSpec.configure do |config|
|
|
35
42
|
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
|
36
43
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
|
37
|
-
<% if ::Rails::VERSION::STRING < "7.1.0" -%>
|
|
38
|
-
config.fixture_path = Rails.root.join('spec/fixtures')
|
|
39
|
-
<% else -%>
|
|
40
44
|
config.fixture_paths = [
|
|
41
45
|
Rails.root.join('spec/fixtures')
|
|
42
46
|
]
|
|
43
|
-
<% end -%>
|
|
44
47
|
|
|
45
48
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
46
49
|
# examples within a transaction, remove the following line or assign false
|
|
@@ -58,24 +61,28 @@ RSpec.configure do |config|
|
|
|
58
61
|
# note if you'd prefer not to run each example within a transaction, you
|
|
59
62
|
# should set use_transactional_fixtures to false.
|
|
60
63
|
#
|
|
61
|
-
# config.
|
|
64
|
+
# config.fixture_paths = [
|
|
65
|
+
# Rails.root.join('spec/fixtures')
|
|
66
|
+
# ]
|
|
62
67
|
# config.use_transactional_fixtures = true
|
|
63
68
|
|
|
64
69
|
<% end -%>
|
|
65
|
-
# RSpec Rails
|
|
66
|
-
#
|
|
67
|
-
# `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.:
|
|
68
72
|
#
|
|
69
|
-
#
|
|
70
|
-
# explicitly tag your specs with their type, e.g.:
|
|
71
|
-
#
|
|
72
|
-
# RSpec.describe UsersController, type: :controller do
|
|
73
|
+
# RSpec.describe UsersController, type: :request do
|
|
73
74
|
# # ...
|
|
74
75
|
# end
|
|
75
76
|
#
|
|
76
77
|
# The different available types are documented in the features, such as in
|
|
77
|
-
# https://rspec.info/features/
|
|
78
|
-
|
|
78
|
+
# https://rspec.info/features/8-0/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!
|
|
79
86
|
|
|
80
87
|
# Filter lines from Rails gems in backtraces.
|
|
81
88
|
config.filter_rails_from_backtrace!
|
|
@@ -79,7 +79,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
|
79
79
|
context "with invalid params" do
|
|
80
80
|
it "renders a JSON response with errors for the new <%= singular_table_name %>" do
|
|
81
81
|
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
|
82
|
-
expect(response).to have_http_status(
|
|
82
|
+
expect(response).to have_http_status(<%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>)
|
|
83
83
|
expect(response.content_type).to eq('application/json')
|
|
84
84
|
end
|
|
85
85
|
end
|
|
@@ -110,7 +110,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
|
110
110
|
it "renders a JSON response with errors for the <%= singular_table_name %>" do
|
|
111
111
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
112
112
|
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
|
113
|
-
expect(response).to have_http_status(
|
|
113
|
+
expect(response).to have_http_status(<%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>)
|
|
114
114
|
expect(response.content_type).to eq('application/json')
|
|
115
115
|
end
|
|
116
116
|
end
|
|
@@ -79,7 +79,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
|
79
79
|
it "renders a JSON response with errors for the new <%= singular_table_name %>" do
|
|
80
80
|
post <%= index_helper %>_url,
|
|
81
81
|
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
|
82
|
-
expect(response).to have_http_status(
|
|
82
|
+
expect(response).to have_http_status(<%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>)
|
|
83
83
|
expect(response.content_type).to match(a_string_including("application/json"))
|
|
84
84
|
end
|
|
85
85
|
end
|
|
@@ -113,7 +113,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
|
113
113
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
114
114
|
patch <%= show_helper %>,
|
|
115
115
|
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
|
116
|
-
expect(response).to have_http_status(
|
|
116
|
+
expect(response).to have_http_status(<%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>)
|
|
117
117
|
expect(response.content_type).to match(a_string_including("application/json"))
|
|
118
118
|
end
|
|
119
119
|
end
|
|
@@ -90,17 +90,10 @@ 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 %>
|
|
94
|
-
it "returns a success response (i.e. to display the 'new' template)" do
|
|
95
|
-
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
|
96
|
-
expect(response).to be_successful
|
|
97
|
-
end
|
|
98
|
-
<% else %>
|
|
99
93
|
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
|
100
94
|
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
|
101
|
-
expect(response).to have_http_status(
|
|
95
|
+
expect(response).to have_http_status(<%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>)
|
|
102
96
|
end
|
|
103
|
-
<% end %>
|
|
104
97
|
end
|
|
105
98
|
end
|
|
106
99
|
|
|
@@ -125,19 +118,11 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
|
125
118
|
end
|
|
126
119
|
|
|
127
120
|
context "with invalid params" do
|
|
128
|
-
<% if Rails.version.to_f < 7.0 %>
|
|
129
|
-
it "returns a success response (i.e. to display the 'edit' template)" do
|
|
130
|
-
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
131
|
-
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
|
132
|
-
expect(response).to be_successful
|
|
133
|
-
end
|
|
134
|
-
<% else %>
|
|
135
121
|
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
|
136
122
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
137
123
|
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
|
138
|
-
expect(response).to have_http_status(
|
|
124
|
+
expect(response).to have_http_status(<%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>)
|
|
139
125
|
end
|
|
140
|
-
<% end %>
|
|
141
126
|
end
|
|
142
127
|
end
|
|
143
128
|
|
|
@@ -18,7 +18,7 @@ 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 =
|
|
21
|
+
cell_selector = 'div>p'
|
|
22
22
|
<% for attribute in output_attributes -%>
|
|
23
23
|
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
|
|
24
24
|
<% end -%>
|
|
@@ -83,17 +83,10 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
|
83
83
|
}.to change(<%= class_name %>, :count).by(0)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
<% if Rails.version.to_f < 7.0 %>
|
|
87
|
-
it "renders a successful response (i.e. to display the 'new' template)" do
|
|
88
|
-
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
|
89
|
-
expect(response).to be_successful
|
|
90
|
-
end
|
|
91
|
-
<% else %>
|
|
92
86
|
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
|
93
87
|
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
|
94
|
-
expect(response).to have_http_status(
|
|
88
|
+
expect(response).to have_http_status(<%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>)
|
|
95
89
|
end
|
|
96
|
-
<% end %>
|
|
97
90
|
end
|
|
98
91
|
end
|
|
99
92
|
|
|
@@ -119,19 +112,11 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
|
119
112
|
end
|
|
120
113
|
|
|
121
114
|
context "with invalid parameters" do
|
|
122
|
-
<% if Rails.version.to_f < 7.0 %>
|
|
123
|
-
it "renders a successful response (i.e. to display the 'edit' template)" do
|
|
124
|
-
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
125
|
-
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
|
|
126
|
-
expect(response).to be_successful
|
|
127
|
-
end
|
|
128
|
-
<% else %>
|
|
129
115
|
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
|
130
116
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
131
117
|
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
|
|
132
|
-
expect(response).to have_http_status(
|
|
118
|
+
expect(response).to have_http_status(<%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>)
|
|
133
119
|
end
|
|
134
|
-
<% end %>
|
|
135
120
|
end
|
|
136
121
|
end
|
|
137
122
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# rubocop: disable Metrics/ModuleLength
|
|
2
1
|
module RSpec
|
|
3
2
|
module Rails
|
|
4
3
|
# Fake class to document RSpec Rails configuration options. In practice,
|
|
@@ -57,7 +56,7 @@ module RSpec
|
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
# @private
|
|
60
|
-
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength
|
|
59
|
+
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength
|
|
61
60
|
config.backtrace_exclusion_patterns << /vendor\//
|
|
62
61
|
config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
|
|
63
62
|
|
|
@@ -69,12 +68,7 @@ module RSpec
|
|
|
69
68
|
config.add_setting :use_transactional_fixtures, alias_with: :use_transactional_examples
|
|
70
69
|
config.add_setting :use_instantiated_fixtures
|
|
71
70
|
config.add_setting :global_fixtures
|
|
72
|
-
|
|
73
|
-
if ::Rails::VERSION::STRING < "7.1.0"
|
|
74
|
-
config.add_setting :fixture_path
|
|
75
|
-
else
|
|
76
|
-
config.add_setting :fixture_paths
|
|
77
|
-
end
|
|
71
|
+
config.add_setting :fixture_paths
|
|
78
72
|
|
|
79
73
|
config.include RSpec::Rails::FixtureSupport, :use_fixtures
|
|
80
74
|
|
|
@@ -90,7 +84,7 @@ module RSpec
|
|
|
90
84
|
config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
|
|
91
85
|
config.include RSpec::Rails::FileFixtureSupport
|
|
92
86
|
|
|
93
|
-
# Add support for
|
|
87
|
+
# Add support for fixture_paths on fixture_file_upload
|
|
94
88
|
config.include RSpec::Rails::FixtureFileUploadSupport
|
|
95
89
|
|
|
96
90
|
# This allows us to expose `render_views` as a config option even though it
|
|
@@ -114,40 +108,6 @@ module RSpec
|
|
|
114
108
|
rendering_views?
|
|
115
109
|
end
|
|
116
110
|
|
|
117
|
-
undef :rendering_views? if respond_to?(:rendering_views?)
|
|
118
|
-
def rendering_views?
|
|
119
|
-
!!rendering_views
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# Define boolean predicates rather than relying on rspec-core due
|
|
123
|
-
# to the bug fix in rspec/rspec-core#2736, note some of these
|
|
124
|
-
# predicates are a bit nonsensical, but they exist for backwards
|
|
125
|
-
# compatibility, we can tidy these up in `rspec-rails` 5.
|
|
126
|
-
undef :fixture_path? if respond_to?(:fixture_path?)
|
|
127
|
-
def fixture_path?
|
|
128
|
-
!!fixture_path
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
undef :global_fixtures? if respond_to?(:global_fixtures?)
|
|
132
|
-
def global_fixtures?
|
|
133
|
-
!!global_fixtures
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
undef :infer_base_class_for_anonymous_controllers? if respond_to?(:infer_base_class_for_anonymous_controllers?)
|
|
137
|
-
def infer_base_class_for_anonymous_controllers?
|
|
138
|
-
!!infer_base_class_for_anonymous_controllers
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
undef :use_instantiated_fixtures? if respond_to?(:use_instantiated_fixtures?)
|
|
142
|
-
def use_instantiated_fixtures?
|
|
143
|
-
!!use_instantiated_fixtures
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
undef :use_transactional_fixtures? if respond_to?(:use_transactional_fixtures?)
|
|
147
|
-
def use_transactional_fixtures?
|
|
148
|
-
!!use_transactional_fixtures
|
|
149
|
-
end
|
|
150
|
-
|
|
151
111
|
def infer_spec_type_from_file_location!
|
|
152
112
|
DIRECTORY_MAPPINGS.each do |type, dir_parts|
|
|
153
113
|
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
|
|
@@ -163,29 +123,6 @@ module RSpec
|
|
|
163
123
|
filter_gems_from_backtrace "activemodel", "activerecord",
|
|
164
124
|
"activesupport", "activejob"
|
|
165
125
|
end
|
|
166
|
-
|
|
167
|
-
# @deprecated TestFixtures#fixture_path is deprecated and will be removed in Rails 7.2
|
|
168
|
-
if ::Rails::VERSION::STRING >= "7.1.0"
|
|
169
|
-
def fixture_path
|
|
170
|
-
RSpec.deprecate(
|
|
171
|
-
"config.fixture_path",
|
|
172
|
-
replacement: "config.fixture_paths",
|
|
173
|
-
message: "Rails 7.1 has deprecated the singular fixture_path in favour of an array." \
|
|
174
|
-
"You should migrate to plural:"
|
|
175
|
-
)
|
|
176
|
-
fixture_paths&.first
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def fixture_path=(path)
|
|
180
|
-
RSpec.deprecate(
|
|
181
|
-
"config.fixture_path = #{path.inspect}",
|
|
182
|
-
replacement: "config.fixture_paths = [#{path.inspect}]",
|
|
183
|
-
message: "Rails 7.1 has deprecated the singular fixture_path in favour of an array." \
|
|
184
|
-
"You should migrate to plural:"
|
|
185
|
-
)
|
|
186
|
-
self.fixture_paths = Array(path)
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
126
|
end
|
|
190
127
|
|
|
191
128
|
add_test_type_configurations(config)
|
|
@@ -219,4 +156,3 @@ module RSpec
|
|
|
219
156
|
initialize_configuration RSpec.configuration
|
|
220
157
|
end
|
|
221
158
|
end
|
|
222
|
-
# rubocop: enable Metrics/ModuleLength
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
# suite and ammeter.
|
|
3
3
|
require 'rspec/rails/matchers'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require 'active_support/execution_context/test_helper'
|
|
8
|
-
end
|
|
5
|
+
require 'active_support/current_attributes/test_helper'
|
|
6
|
+
require 'active_support/execution_context/test_helper'
|
|
9
7
|
|
|
10
8
|
module RSpec
|
|
11
9
|
module Rails
|
|
@@ -17,11 +15,9 @@ module RSpec
|
|
|
17
15
|
include RSpec::Rails::MinitestLifecycleAdapter
|
|
18
16
|
include RSpec::Rails::MinitestAssertionAdapter
|
|
19
17
|
include RSpec::Rails::FixtureSupport
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
include ActiveSupport::ExecutionContext::TestHelper
|
|
24
|
-
end
|
|
18
|
+
include RSpec::Rails::TaggedLoggingAdapter
|
|
19
|
+
include ActiveSupport::CurrentAttributes::TestHelper
|
|
20
|
+
include ActiveSupport::ExecutionContext::TestHelper
|
|
25
21
|
end
|
|
26
22
|
end
|
|
27
23
|
end
|
|
@@ -44,57 +44,58 @@ module RSpec
|
|
|
44
44
|
].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}"
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def [](key)
|
|
56
|
-
if @example_data.key?(key)
|
|
57
|
-
@example_data[key]
|
|
58
|
-
else
|
|
59
|
-
raise_wrong_scope_error
|
|
60
|
-
end
|
|
61
|
-
end
|
|
47
|
+
# @private
|
|
48
|
+
# Allows failure screenshot to work whilst not exposing metadata
|
|
49
|
+
class SuppressRailsScreenshotMetadata
|
|
50
|
+
def initialize
|
|
51
|
+
@example_data = {}
|
|
52
|
+
end
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
end
|
|
54
|
+
def [](key)
|
|
55
|
+
if @example_data.key?(key)
|
|
56
|
+
@example_data[key]
|
|
57
|
+
else
|
|
58
|
+
raise_wrong_scope_error
|
|
69
59
|
end
|
|
60
|
+
end
|
|
70
61
|
|
|
71
|
-
|
|
62
|
+
def []=(key, value)
|
|
63
|
+
if key == :failure_screenshot_path
|
|
64
|
+
@example_data[key] = value
|
|
65
|
+
else
|
|
72
66
|
raise_wrong_scope_error
|
|
73
67
|
end
|
|
68
|
+
end
|
|
74
69
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def raise_wrong_scope_error
|
|
78
|
-
raise RSpec::Core::ExampleGroup::WrongScopeError,
|
|
79
|
-
"`metadata` is not available from within an example " \
|
|
80
|
-
"(e.g. an `it` block) or from constructs that run in the " \
|
|
81
|
-
"scope of an example (e.g. `before`, `let`, etc). It is " \
|
|
82
|
-
"only available on an example group (e.g. a `describe` or "\
|
|
83
|
-
"`context` block)"
|
|
84
|
-
end
|
|
70
|
+
def method_missing(_name, *_args, &_block)
|
|
71
|
+
raise_wrong_scope_error
|
|
85
72
|
end
|
|
86
73
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def raise_wrong_scope_error
|
|
77
|
+
raise RSpec::Core::ExampleGroup::WrongScopeError,
|
|
78
|
+
"`metadata` is not available from within an example " \
|
|
79
|
+
"(e.g. an `it` block) or from constructs that run in the " \
|
|
80
|
+
"scope of an example (e.g. `before`, `let`, etc). It is " \
|
|
81
|
+
"only available on an example group (e.g. a `describe` or "\
|
|
82
|
+
"`context` block)"
|
|
90
83
|
end
|
|
91
84
|
end
|
|
92
85
|
|
|
86
|
+
# @private
|
|
87
|
+
def metadata
|
|
88
|
+
@metadata ||= SuppressRailsScreenshotMetadata.new
|
|
89
|
+
end
|
|
90
|
+
|
|
93
91
|
# Delegates to `Rails.application`.
|
|
94
92
|
def app
|
|
95
93
|
::Rails.application
|
|
96
94
|
end
|
|
97
95
|
|
|
96
|
+
# Default driver to assign if none specified.
|
|
97
|
+
DEFAULT_DRIVER = :selenium_chrome_headless
|
|
98
|
+
|
|
98
99
|
included do |other|
|
|
99
100
|
ActiveSupport.on_load(:action_dispatch_system_test_case) do
|
|
100
101
|
ActionDispatch::SystemTesting::Server.silence_puma = true
|
|
@@ -137,7 +138,7 @@ module RSpec
|
|
|
137
138
|
self.class.before do
|
|
138
139
|
# A user may have already set the driver, so only default if driver
|
|
139
140
|
# is not set
|
|
140
|
-
driven_by(
|
|
141
|
+
driven_by(DEFAULT_DRIVER) unless @driver
|
|
141
142
|
end
|
|
142
143
|
end
|
|
143
144
|
|
|
@@ -145,6 +146,10 @@ module RSpec
|
|
|
145
146
|
@driver = ::ActionDispatch::SystemTestCase.driven_by(driver, **driver_options, &blk).tap(&:use)
|
|
146
147
|
end
|
|
147
148
|
|
|
149
|
+
def served_by(**options)
|
|
150
|
+
::ActionDispatch::SystemTestCase.served_by(**options)
|
|
151
|
+
end
|
|
152
|
+
|
|
148
153
|
before do
|
|
149
154
|
@routes = ::Rails.application.routes
|
|
150
155
|
end
|