rspec-rails 6.0.3 → 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 +309 -181
- data/README.md +31 -31
- data/lib/generators/rspec/generator/generator_generator.rb +2 -2
- data/lib/generators/rspec/generator/templates/generator_spec.rb +1 -2
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +25 -12
- data/lib/generators/rspec/mailer/mailer_generator.rb +4 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +3 -3
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +0 -15
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +3 -3
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +0 -15
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/rspec/rails/configuration.rb +31 -2
- data/lib/rspec/rails/example/mailbox_example_group.rb +1 -1
- data/lib/rspec/rails/example/rails_example_group.rb +6 -1
- data/lib/rspec/rails/example/routing_example_group.rb +0 -2
- data/lib/rspec/rails/example/system_example_group.rb +55 -1
- data/lib/rspec/rails/example/view_example_group.rb +2 -1
- data/lib/rspec/rails/fixture_file_upload_support.rb +7 -1
- data/lib/rspec/rails/fixture_support.rb +39 -17
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +11 -4
- data/lib/rspec/rails/matchers/action_cable.rb +6 -1
- data/lib/rspec/rails/matchers/active_job.rb +69 -8
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +37 -5
- data/lib/rspec/rails/matchers/have_http_status.rb +3 -7
- 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/version.rb +1 -1
- data/lib/rspec-rails.rb +28 -3
- data.tar.gz.sig +0 -0
- metadata +39 -43
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/integration/integration_generator.rb +0 -29
data/README.md
CHANGED
@@ -9,7 +9,8 @@ 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.
|
13
14
|
* **[`rspec-rails` 5.x][]** for Rails 5.2 or 6.x.
|
14
15
|
* **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x.
|
15
16
|
* **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
|
@@ -25,13 +26,15 @@ According to [RSpec Rails new versioning strategy][] use:
|
|
25
26
|
[`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
|
26
27
|
[`rspec-rails` 4.x]: https://github.com/rspec/rspec-rails/tree/4-1-maintenance
|
27
28
|
[`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-
|
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 [`6-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,7 +86,7 @@ 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://rspec.info/features/
|
89
|
+
[`rspec-rails` upgrade notes]: https://rspec.info/features/7-1/rspec-rails/upgrade
|
90
90
|
[RSpec upgrade notes]: https://rspec.info/upgrading-from-rspec-2/
|
91
91
|
|
92
92
|
## Usage
|
@@ -208,22 +208,22 @@ to test the various parts of a Rails system:
|
|
208
208
|
Follow the links above for examples of how each matcher is used.
|
209
209
|
|
210
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/
|
212
|
-
[`render_template`]: https://rspec.info/features/
|
213
|
-
[`redirect_to`]: https://rspec.info/features/
|
214
|
-
[`route_to`]: https://rspec.info/features/
|
215
|
-
[`be_routable`]: https://rspec.info/features/
|
216
|
-
[`have_http_status`]: https://rspec.info/features/
|
217
|
-
[`match_array`]: https://rspec.info/features/
|
218
|
-
[`have_been_enqueued`]: https://rspec.info/features/
|
219
|
-
[`have_enqueued_job`]: https://rspec.info/features/
|
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://rspec.info/features/
|
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://rspec.info/features/
|
272
|
-
[feature]: https://rspec.info/features/
|
273
|
-
[system]: https://rspec.info/features/
|
274
|
-
[model]: https://rspec.info/features/
|
275
|
-
[controller]: https://rspec.info/features/
|
276
|
-
[mailer]: https://rspec.info/features/
|
277
|
-
[job]: https://rspec.info/features/
|
278
|
-
[view]: https://rspec.info/features/
|
279
|
-
[routing]: https://rspec.info/features/
|
280
|
-
[helper]: https://rspec.info/features/
|
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://rspec.info/features/
|
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
|
|
@@ -4,7 +4,7 @@ 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]
|
@@ -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
|
@@ -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.
|
@@ -34,7 +39,13 @@ end
|
|
34
39
|
RSpec.configure do |config|
|
35
40
|
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
36
41
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
37
|
-
|
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 -%>
|
38
49
|
|
39
50
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
40
51
|
# examples within a transaction, remove the following line or assign false
|
@@ -52,24 +63,26 @@ RSpec.configure do |config|
|
|
52
63
|
# note if you'd prefer not to run each example within a transaction, you
|
53
64
|
# should set use_transactional_fixtures to false.
|
54
65
|
#
|
55
|
-
# config.fixture_path =
|
66
|
+
# config.fixture_path = Rails.root.join('spec/fixtures')
|
56
67
|
# config.use_transactional_fixtures = true
|
57
68
|
|
58
69
|
<% end -%>
|
59
|
-
# RSpec Rails
|
60
|
-
#
|
61
|
-
# `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.:
|
62
72
|
#
|
63
|
-
#
|
64
|
-
# explicitly tag your specs with their type, e.g.:
|
65
|
-
#
|
66
|
-
# RSpec.describe UsersController, type: :controller do
|
73
|
+
# RSpec.describe UsersController, type: :request do
|
67
74
|
# # ...
|
68
75
|
# end
|
69
76
|
#
|
70
77
|
# The different available types are documented in the features, such as in
|
71
|
-
# https://rspec.info/features/
|
72
|
-
|
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!
|
73
86
|
|
74
87
|
# Filter lines from Rails gems in backtraces.
|
75
88
|
config.filter_rails_from_backtrace!
|
@@ -8,7 +8,8 @@ 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
|
@@ -21,7 +22,8 @@ module Rspec
|
|
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
|
@@ -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
95
|
expect(response).to have_http_status(:unprocessable_entity)
|
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
124
|
expect(response).to have_http_status(:unprocessable_entity)
|
139
125
|
end
|
140
|
-
<% end %>
|
141
126
|
end
|
142
127
|
end
|
143
128
|
|
@@ -2,7 +2,7 @@ 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
|
-
let(:<%=
|
5
|
+
let(:<%= singular_table_name %>) {
|
6
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 ? '' : ','%>
|
@@ -11,13 +11,13 @@ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
|
11
11
|
}
|
12
12
|
|
13
13
|
before(:each) do
|
14
|
-
assign(:<%=
|
14
|
+
assign(:<%= singular_table_name %>, <%= singular_table_name %>)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "renders the edit <%= ns_file_name %> form" do
|
18
18
|
render
|
19
19
|
|
20
|
-
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(<%=
|
20
|
+
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(<%= singular_table_name %>), "post" do
|
21
21
|
<% for attribute in output_attributes -%>
|
22
22
|
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
23
23
|
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
@@ -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 -%>
|
@@ -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,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
88
|
expect(response).to have_http_status(:unprocessable_entity)
|
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
118
|
expect(response).to have_http_status(:unprocessable_entity)
|
133
119
|
end
|
134
|
-
<% end %>
|
135
120
|
end
|
136
121
|
end
|
137
122
|
|
@@ -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 %>/show", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
assign(:<%=
|
6
|
+
assign(:<%= singular_table_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
8
|
<%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
@@ -57,7 +57,7 @@ module RSpec
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# @private
|
60
|
-
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
|
60
|
+
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
|
61
61
|
config.backtrace_exclusion_patterns << /vendor\//
|
62
62
|
config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
|
63
63
|
|
@@ -69,7 +69,13 @@ module RSpec
|
|
69
69
|
config.add_setting :use_transactional_fixtures, alias_with: :use_transactional_examples
|
70
70
|
config.add_setting :use_instantiated_fixtures
|
71
71
|
config.add_setting :global_fixtures
|
72
|
-
|
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
|
78
|
+
|
73
79
|
config.include RSpec::Rails::FixtureSupport, :use_fixtures
|
74
80
|
|
75
81
|
# We'll need to create a deprecated module in order to properly report to
|
@@ -157,6 +163,29 @@ module RSpec
|
|
157
163
|
filter_gems_from_backtrace "activemodel", "activerecord",
|
158
164
|
"activesupport", "activejob"
|
159
165
|
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
|
160
189
|
end
|
161
190
|
|
162
191
|
add_test_type_configurations(config)
|
@@ -69,7 +69,7 @@ module RSpec
|
|
69
69
|
#
|
70
70
|
# @param message [Hash, Mail::Message] a mail message or hash of
|
71
71
|
# attributes used to build one
|
72
|
-
# @return [
|
72
|
+
# @return [ActionMailbox::InboundMessage]
|
73
73
|
def process(message)
|
74
74
|
MailboxExampleGroup.create_inbound_email(message).tap do |mail|
|
75
75
|
self.class.mailbox_class.receive(mail)
|
@@ -2,6 +2,9 @@
|
|
2
2
|
# suite and ammeter.
|
3
3
|
require 'rspec/rails/matchers'
|
4
4
|
|
5
|
+
require 'active_support/current_attributes/test_helper'
|
6
|
+
require 'active_support/execution_context/test_helper'
|
7
|
+
|
5
8
|
module RSpec
|
6
9
|
module Rails
|
7
10
|
# @api public
|
@@ -12,7 +15,9 @@ module RSpec
|
|
12
15
|
include RSpec::Rails::MinitestLifecycleAdapter
|
13
16
|
include RSpec::Rails::MinitestAssertionAdapter
|
14
17
|
include RSpec::Rails::FixtureSupport
|
15
|
-
include RSpec::Rails::TaggedLoggingAdapter
|
18
|
+
include RSpec::Rails::TaggedLoggingAdapter
|
19
|
+
include ActiveSupport::CurrentAttributes::TestHelper
|
20
|
+
include ActiveSupport::ExecutionContext::TestHelper
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
@@ -44,11 +44,65 @@ module RSpec
|
|
44
44
|
].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}"
|
45
45
|
end
|
46
46
|
|
47
|
+
if ::Rails::VERSION::STRING.to_f >= 7.1
|
48
|
+
# @private
|
49
|
+
# Allows failure screenshot to work whilst not exposing metadata
|
50
|
+
class SuppressRailsScreenshotMetadata
|
51
|
+
def initialize
|
52
|
+
@example_data = {}
|
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
|
62
|
+
|
63
|
+
def []=(key, value)
|
64
|
+
if key == :failure_screenshot_path
|
65
|
+
@example_data[key] = value
|
66
|
+
else
|
67
|
+
raise_wrong_scope_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def method_missing(_name, *_args, &_block)
|
72
|
+
raise_wrong_scope_error
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
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
|
85
|
+
end
|
86
|
+
|
87
|
+
# @private
|
88
|
+
def metadata
|
89
|
+
@metadata ||= SuppressRailsScreenshotMetadata.new
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
47
93
|
# Delegates to `Rails.application`.
|
48
94
|
def app
|
49
95
|
::Rails.application
|
50
96
|
end
|
51
97
|
|
98
|
+
# Default driver to assign if none specified.
|
99
|
+
DEFAULT_DRIVER =
|
100
|
+
if ::Rails::VERSION::STRING.to_f >= 7.2
|
101
|
+
:selenium_chrome_headless
|
102
|
+
else
|
103
|
+
:selenium
|
104
|
+
end
|
105
|
+
|
52
106
|
included do |other|
|
53
107
|
ActiveSupport.on_load(:action_dispatch_system_test_case) do
|
54
108
|
ActionDispatch::SystemTesting::Server.silence_puma = true
|
@@ -91,7 +145,7 @@ module RSpec
|
|
91
145
|
self.class.before do
|
92
146
|
# A user may have already set the driver, so only default if driver
|
93
147
|
# is not set
|
94
|
-
driven_by(
|
148
|
+
driven_by(DEFAULT_DRIVER) unless @driver
|
95
149
|
end
|
96
150
|
end
|
97
151
|
|
@@ -65,6 +65,7 @@ module RSpec
|
|
65
65
|
# end
|
66
66
|
def render(options = {}, local_assigns = {}, &block)
|
67
67
|
options = _default_render_options if Hash === options && options.empty?
|
68
|
+
options = options.merge(_default_render_options) if Hash === options && options.keys == [:locals]
|
68
69
|
super(options, local_assigns, &block)
|
69
70
|
end
|
70
71
|
|
@@ -89,7 +90,7 @@ module RSpec
|
|
89
90
|
#
|
90
91
|
# stub_template("widgets/_widget.html.erb" => "This content.")
|
91
92
|
def stub_template(hash)
|
92
|
-
|
93
|
+
controller.prepend_view_path(StubResolverCache.resolver_for(hash))
|
93
94
|
end
|
94
95
|
|
95
96
|
# Provides access to the params hash that will be available within the
|
@@ -14,6 +14,8 @@ module RSpec
|
|
14
14
|
resolved_fixture_path =
|
15
15
|
if respond_to?(:file_fixture_path) && !file_fixture_path.nil?
|
16
16
|
file_fixture_path.to_s
|
17
|
+
elsif respond_to?(:fixture_paths)
|
18
|
+
(RSpec.configuration.fixture_paths&.first || '').to_s
|
17
19
|
else
|
18
20
|
(RSpec.configuration.fixture_path || '').to_s
|
19
21
|
end
|
@@ -26,7 +28,11 @@ module RSpec
|
|
26
28
|
include ActiveSupport::Testing::FileFixtures
|
27
29
|
|
28
30
|
class << self
|
29
|
-
|
31
|
+
if ::Rails::VERSION::STRING < "7.1.0"
|
32
|
+
attr_accessor :fixture_path
|
33
|
+
else
|
34
|
+
attr_accessor :fixture_paths
|
35
|
+
end
|
30
36
|
|
31
37
|
# Get instance of wrapper
|
32
38
|
def instance
|