rspec-rails 5.0.2 → 5.1.2
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 +34 -1
- data/README.md +21 -17
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +4 -0
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +13 -13
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +17 -17
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +10 -10
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +19 -18
- data/lib/rspec/rails/configuration.rb +1 -0
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +30 -2
- data/lib/rspec/rails/matchers/have_http_status.rb +4 -4
- data/lib/rspec/rails/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +23 -11
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be221e5df3386cb55e14f8047e02628bc11098596dcce06749701ac0b7497782
|
4
|
+
data.tar.gz: 56b12531541ff18599c13618ba2937859bb4cd860cc814b3350046ec4949e870
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1786502c478ab9de29fbd59ce16371178776a7283698ba048b203f62aa614fc6c28e4c72b5064595f4eacd2cf309443de8d0d6803ac604e9d11a641c6f86c4b
|
7
|
+
data.tar.gz: 5860654b1926c2f2cdd998d2b84ac075167f7107bd687b74dae5bb9e17d7e76ef6b0c96dd022ec7a9be5dc0fe008e845808187080e97b400bec18b35d1872e76
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,5 +1,38 @@
|
|
1
1
|
### Development
|
2
|
-
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.
|
2
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.1.1...5-1-maintenance)
|
3
|
+
|
4
|
+
Bug Fixes:
|
5
|
+
|
6
|
+
* Fix controller scaffold templates parameter name. (Taketo Takashima, #2591)
|
7
|
+
* Include generator specs in the inferred list of specs. (Jason Karns, #2597)
|
8
|
+
|
9
|
+
### 5.1.1 / 2022-03-07
|
10
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.1.0...v5.1.1)
|
11
|
+
|
12
|
+
Bug Fixes:
|
13
|
+
|
14
|
+
* Properly handle global id serialised arguments in `have_enqueued_mail`.
|
15
|
+
(Jon Rowe, #2578)
|
16
|
+
|
17
|
+
### 5.1.0 / 2022-01-26
|
18
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.3...v5.1.0)
|
19
|
+
|
20
|
+
Enhancements:
|
21
|
+
|
22
|
+
* Make the API request scaffold template more consistent and compatible with
|
23
|
+
Rails 6.1. (Naoto Hamada, #2484)
|
24
|
+
* Change the scaffold `rails_helper.rb` template to use `require_relative`.
|
25
|
+
(Jon Dufresne, #2528)
|
26
|
+
|
27
|
+
### 5.0.3 / 2022-01-26
|
28
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.2...v5.0.3)
|
29
|
+
|
30
|
+
Bug Fixes:
|
31
|
+
|
32
|
+
* Properly name params in controller and request spec templates when
|
33
|
+
using the `--model-name` parameter. (@kenzo-tanaka, #2534)
|
34
|
+
* Fix support for `have_enqueued_mail` on Ruby 3.1 with Rails 6.1.
|
35
|
+
(Fabio Napoleoni, Mikael Henriksson, Phil Pirozhkov, Jon Rowe, #2566)
|
3
36
|
|
4
37
|
### 5.0.2 / 2021-08-14
|
5
38
|
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v5.0.1...v5.0.2)
|
data/README.md
CHANGED
@@ -8,9 +8,11 @@ They’re also specifications (or _specs,_ for short):
|
|
8
8
|
detailed explanations of how the application is supposed to behave,
|
9
9
|
expressed in plain English.
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
According to [RSpec Rails new versioning strategy][] use:
|
12
|
+
* **[`rspec-rails` 5.x][]** for Rails 6.x.
|
13
|
+
* **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x.
|
14
|
+
* **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
|
15
|
+
* **[`rspec-rails` 1.x][]** for Rails 2.x.
|
14
16
|
|
15
17
|
[Build Status]: https://secure.travis-ci.org/rspec/rspec-rails.svg?branch=main
|
16
18
|
[travis-ci]: https://travis-ci.org/rspec/rspec-rails
|
@@ -23,11 +25,13 @@ Use **[`rspec-rails` 1.x][]** for Rails 2.x.
|
|
23
25
|
[`rspec-rails` 1.x]: https://github.com/dchelimsky/rspec-rails
|
24
26
|
[`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
|
25
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-0-maintenance
|
29
|
+
[RSpec Rails new versioning strategy]: https://github.com/rspec/rspec-rails/blob/main/rfcs/versioning-strategy.md
|
26
30
|
|
27
31
|
## Installation
|
28
32
|
|
29
|
-
**IMPORTANT** This README / branch refers to the
|
30
|
-
See the [`
|
33
|
+
**IMPORTANT** This README / branch refers to the current development build.
|
34
|
+
See the [`5-0-maintenance` branch on Github](https://github.com/rspec/rspec-rails/tree/5-0-maintenance) if you want or require the latest stable release.
|
31
35
|
|
32
36
|
1. Add `rspec-rails` to **both** the `:development` and `:test` groups
|
33
37
|
of your app’s `Gemfile`:
|
@@ -229,18 +233,18 @@ Each one inherits from one of Rails’ built-in `TestCase` classes,
|
|
229
233
|
meaning the helper methods provided by default in Rails tests
|
230
234
|
are available in RSpec, as well.
|
231
235
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
236
|
+
| Spec type | Corresponding Rails test class |
|
237
|
+
| -------------- | -------------------------------- |
|
238
|
+
| [model][] | |
|
239
|
+
| [controller][] | [`ActionController::TestCase`][] |
|
240
|
+
| [mailer][] | `ActionMailer::TestCase` |
|
241
|
+
| [job][] | |
|
242
|
+
| [view][] | `ActionView::TestCase` |
|
243
|
+
| [routing][] | |
|
244
|
+
| [helper][] | `ActionView::TestCase` |
|
245
|
+
| [request][] | [`ActionDispatch::IntegrationTest`][] |
|
246
|
+
| [feature][] | |
|
247
|
+
| [system][] | [`ActionDispatch::SystemTestCase`][] |
|
244
248
|
|
245
249
|
Follow the links above to see examples of each spec type,
|
246
250
|
or for official Rails API documentation on the given `TestCase` class.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
2
|
require 'spec_helper'
|
3
3
|
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
7
|
require 'rspec/rails'
|
@@ -64,21 +64,21 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
64
64
|
context "with valid params" do
|
65
65
|
it "creates a new <%= class_name %>" do
|
66
66
|
expect {
|
67
|
-
post :create, params: {<%=
|
67
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
68
68
|
}.to change(<%= class_name %>, :count).by(1)
|
69
69
|
end
|
70
70
|
|
71
|
-
it "renders a JSON response with the new <%=
|
72
|
-
post :create, params: {<%=
|
71
|
+
it "renders a JSON response with the new <%= singular_table_name %>" do
|
72
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
73
73
|
expect(response).to have_http_status(:created)
|
74
74
|
expect(response.content_type).to eq('application/json')
|
75
|
-
expect(response.location).to eq(<%=
|
75
|
+
expect(response.location).to eq(<%= singular_table_name %>_url(<%= class_name %>.last))
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
context "with invalid params" do
|
80
|
-
it "renders a JSON response with errors for the new <%=
|
81
|
-
post :create, params: {<%=
|
80
|
+
it "renders a JSON response with errors for the new <%= singular_table_name %>" do
|
81
|
+
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
82
82
|
expect(response).to have_http_status(:unprocessable_entity)
|
83
83
|
expect(response.content_type).to eq('application/json')
|
84
84
|
end
|
@@ -91,25 +91,25 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
91
91
|
skip("Add a hash of attributes valid for your model")
|
92
92
|
}
|
93
93
|
|
94
|
-
it "updates the requested <%=
|
94
|
+
it "updates the requested <%= singular_table_name %>" do
|
95
95
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
96
|
-
put :update, params: {id: <%= file_name %>.to_param, <%=
|
96
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
97
97
|
<%= file_name %>.reload
|
98
98
|
skip("Add assertions for updated state")
|
99
99
|
end
|
100
100
|
|
101
|
-
it "renders a JSON response with the <%=
|
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, <%=
|
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
|
107
107
|
end
|
108
108
|
|
109
109
|
context "with invalid params" do
|
110
|
-
it "renders a JSON response with errors for the <%=
|
110
|
+
it "renders a JSON response with errors for the <%= singular_table_name %>" do
|
111
111
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
112
|
-
put :update, params: {id: <%= file_name %>.to_param, <%=
|
112
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
113
113
|
expect(response).to have_http_status(:unprocessable_entity)
|
114
114
|
expect(response.content_type).to eq('application/json')
|
115
115
|
end
|
@@ -117,7 +117,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
117
117
|
end
|
118
118
|
|
119
119
|
describe "DELETE #destroy" do
|
120
|
-
it "destroys the requested <%=
|
120
|
+
it "destroys the requested <%= singular_table_name %>" do
|
121
121
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
122
122
|
expect {
|
123
123
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
@@ -46,7 +46,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
46
46
|
describe "GET /show" do
|
47
47
|
it "renders a successful response" do
|
48
48
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
49
|
-
get <%= show_helper
|
49
|
+
get <%= show_helper %>, as: :json
|
50
50
|
expect(response).to be_successful
|
51
51
|
end
|
52
52
|
end
|
@@ -56,13 +56,13 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
56
56
|
it "creates a new <%= class_name %>" do
|
57
57
|
expect {
|
58
58
|
post <%= index_helper %>_url,
|
59
|
-
params: { <%=
|
59
|
+
params: { <%= singular_table_name %>: valid_attributes }, headers: valid_headers, as: :json
|
60
60
|
}.to change(<%= class_name %>, :count).by(1)
|
61
61
|
end
|
62
62
|
|
63
|
-
it "renders a JSON response with the new <%=
|
63
|
+
it "renders a JSON response with the new <%= singular_table_name %>" do
|
64
64
|
post <%= index_helper %>_url,
|
65
|
-
params: { <%=
|
65
|
+
params: { <%= singular_table_name %>: valid_attributes }, headers: valid_headers, as: :json
|
66
66
|
expect(response).to have_http_status(:created)
|
67
67
|
expect(response.content_type).to match(a_string_including("application/json"))
|
68
68
|
end
|
@@ -72,15 +72,15 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
72
72
|
it "does not create a new <%= class_name %>" do
|
73
73
|
expect {
|
74
74
|
post <%= index_helper %>_url,
|
75
|
-
params: { <%=
|
75
|
+
params: { <%= singular_table_name %>: invalid_attributes }, as: :json
|
76
76
|
}.to change(<%= class_name %>, :count).by(0)
|
77
77
|
end
|
78
78
|
|
79
|
-
it "renders a JSON response with errors for the new <%=
|
79
|
+
it "renders a JSON response with errors for the new <%= singular_table_name %>" do
|
80
80
|
post <%= index_helper %>_url,
|
81
|
-
params: { <%=
|
81
|
+
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
82
82
|
expect(response).to have_http_status(:unprocessable_entity)
|
83
|
-
expect(response.content_type).to
|
83
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -91,17 +91,17 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
91
91
|
skip("Add a hash of attributes valid for your model")
|
92
92
|
}
|
93
93
|
|
94
|
-
it "updates the requested <%=
|
94
|
+
it "updates the requested <%= singular_table_name %>" do
|
95
95
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
96
|
-
patch <%= show_helper
|
96
|
+
patch <%= show_helper %>,
|
97
97
|
params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
|
98
98
|
<%= file_name %>.reload
|
99
99
|
skip("Add assertions for updated state")
|
100
100
|
end
|
101
101
|
|
102
|
-
it "renders a JSON response with the <%=
|
102
|
+
it "renders a JSON response with the <%= singular_table_name %>" do
|
103
103
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
104
|
-
patch <%= show_helper
|
104
|
+
patch <%= show_helper %>,
|
105
105
|
params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
|
106
106
|
expect(response).to have_http_status(:ok)
|
107
107
|
expect(response.content_type).to match(a_string_including("application/json"))
|
@@ -109,21 +109,21 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
109
109
|
end
|
110
110
|
|
111
111
|
context "with invalid parameters" do
|
112
|
-
it "renders a JSON response with errors for the <%=
|
112
|
+
it "renders a JSON response with errors for the <%= singular_table_name %>" do
|
113
113
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
114
|
-
patch <%= show_helper
|
114
|
+
patch <%= show_helper %>,
|
115
115
|
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
116
116
|
expect(response).to have_http_status(:unprocessable_entity)
|
117
|
-
expect(response.content_type).to
|
117
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
describe "DELETE /destroy" do
|
123
|
-
it "destroys the requested <%=
|
123
|
+
it "destroys the requested <%= singular_table_name %>" do
|
124
124
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
125
125
|
expect {
|
126
|
-
delete <%= show_helper
|
126
|
+
delete <%= show_helper %>, headers: valid_headers, as: :json
|
127
127
|
}.to change(<%= class_name %>, :count).by(-1)
|
128
128
|
end
|
129
129
|
end
|
@@ -79,19 +79,19 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
79
79
|
context "with valid params" do
|
80
80
|
it "creates a new <%= class_name %>" do
|
81
81
|
expect {
|
82
|
-
post :create, params: {<%=
|
82
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
83
83
|
}.to change(<%= class_name %>, :count).by(1)
|
84
84
|
end
|
85
85
|
|
86
|
-
it "redirects to the created <%=
|
87
|
-
post :create, params: {<%=
|
86
|
+
it "redirects to the created <%= singular_table_name %>" do
|
87
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
88
88
|
expect(response).to redirect_to(<%= class_name %>.last)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
context "with invalid params" do
|
93
93
|
it "returns a success response (i.e. to display the 'new' template)" do
|
94
|
-
post :create, params: {<%=
|
94
|
+
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
95
95
|
expect(response).to be_successful
|
96
96
|
end
|
97
97
|
end
|
@@ -103,16 +103,16 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
103
103
|
skip("Add a hash of attributes valid for your model")
|
104
104
|
}
|
105
105
|
|
106
|
-
it "updates the requested <%=
|
106
|
+
it "updates the requested <%= singular_table_name %>" do
|
107
107
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
108
|
-
put :update, params: {id: <%= file_name %>.to_param, <%=
|
108
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
109
109
|
<%= file_name %>.reload
|
110
110
|
skip("Add assertions for updated state")
|
111
111
|
end
|
112
112
|
|
113
|
-
it "redirects to the <%=
|
113
|
+
it "redirects to the <%= singular_table_name %>" do
|
114
114
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
115
|
-
put :update, params: {id: <%= file_name %>.to_param, <%=
|
115
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
116
116
|
expect(response).to redirect_to(<%= file_name %>)
|
117
117
|
end
|
118
118
|
end
|
@@ -120,14 +120,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
120
120
|
context "with invalid params" do
|
121
121
|
it "returns a success response (i.e. to display the 'edit' template)" do
|
122
122
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
123
|
-
put :update, params: {id: <%= file_name %>.to_param, <%=
|
123
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
124
124
|
expect(response).to be_successful
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
describe "DELETE #destroy" do
|
130
|
-
it "destroys the requested <%=
|
130
|
+
it "destroys the requested <%= singular_table_name %>" do
|
131
131
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
132
132
|
expect {
|
133
133
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
3
|
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
4
|
# It demonstrates how one might use RSpec to test the controller code that
|
@@ -18,6 +18,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
18
18
|
include Engine.routes.url_helpers
|
19
19
|
<% end -%>
|
20
20
|
|
21
|
+
# This should return the minimal set of attributes required to create a valid
|
21
22
|
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
22
23
|
# adjust the attributes here as well.
|
23
24
|
let(:valid_attributes) {
|
@@ -41,7 +42,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
41
42
|
describe "GET /show" do
|
42
43
|
it "renders a successful response" do
|
43
44
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
44
|
-
get <%= show_helper
|
45
|
+
get <%= show_helper %>
|
45
46
|
expect(response).to be_successful
|
46
47
|
end
|
47
48
|
end
|
@@ -54,9 +55,9 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
54
55
|
end
|
55
56
|
|
56
57
|
describe "GET /edit" do
|
57
|
-
it "
|
58
|
+
it "renders a successful response" do
|
58
59
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
59
|
-
get <%= edit_helper
|
60
|
+
get <%= edit_helper %>
|
60
61
|
expect(response).to be_successful
|
61
62
|
end
|
62
63
|
end
|
@@ -65,25 +66,25 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
65
66
|
context "with valid parameters" do
|
66
67
|
it "creates a new <%= class_name %>" do
|
67
68
|
expect {
|
68
|
-
post <%= index_helper %>_url, params: { <%=
|
69
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
|
69
70
|
}.to change(<%= class_name %>, :count).by(1)
|
70
71
|
end
|
71
72
|
|
72
|
-
it "redirects to the created <%=
|
73
|
-
post <%= index_helper %>_url, params: { <%=
|
74
|
-
expect(response).to redirect_to(<%= show_helper
|
73
|
+
it "redirects to the created <%= singular_table_name %>" do
|
74
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
|
75
|
+
expect(response).to redirect_to(<%= show_helper(class_name+".last") %>)
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
79
|
context "with invalid parameters" do
|
79
80
|
it "does not create a new <%= class_name %>" do
|
80
81
|
expect {
|
81
|
-
post <%= index_helper %>_url, params: { <%=
|
82
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
82
83
|
}.to change(<%= class_name %>, :count).by(0)
|
83
84
|
end
|
84
85
|
|
85
86
|
it "renders a successful response (i.e. to display the 'new' template)" do
|
86
|
-
post <%= index_helper %>_url, params: { <%=
|
87
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
87
88
|
expect(response).to be_successful
|
88
89
|
end
|
89
90
|
end
|
@@ -95,16 +96,16 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
95
96
|
skip("Add a hash of attributes valid for your model")
|
96
97
|
}
|
97
98
|
|
98
|
-
it "updates the requested <%=
|
99
|
+
it "updates the requested <%= singular_table_name %>" do
|
99
100
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
100
|
-
patch <%= show_helper
|
101
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
|
101
102
|
<%= file_name %>.reload
|
102
103
|
skip("Add assertions for updated state")
|
103
104
|
end
|
104
105
|
|
105
|
-
it "redirects to the <%=
|
106
|
+
it "redirects to the <%= singular_table_name %>" do
|
106
107
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
107
|
-
patch <%= show_helper
|
108
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
|
108
109
|
<%= file_name %>.reload
|
109
110
|
expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
|
110
111
|
end
|
@@ -113,23 +114,23 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
113
114
|
context "with invalid parameters" do
|
114
115
|
it "renders a successful response (i.e. to display the 'edit' template)" do
|
115
116
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
116
|
-
patch <%= show_helper
|
117
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
|
117
118
|
expect(response).to be_successful
|
118
119
|
end
|
119
120
|
end
|
120
121
|
end
|
121
122
|
|
122
123
|
describe "DELETE /destroy" do
|
123
|
-
it "destroys the requested <%=
|
124
|
+
it "destroys the requested <%= singular_table_name %>" do
|
124
125
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
125
126
|
expect {
|
126
|
-
delete <%= show_helper
|
127
|
+
delete <%= show_helper %>
|
127
128
|
}.to change(<%= class_name %>, :count).by(-1)
|
128
129
|
end
|
129
130
|
|
130
131
|
it "redirects to the <%= table_name %> list" do
|
131
132
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
132
|
-
delete <%= show_helper
|
133
|
+
delete <%= show_helper %>
|
133
134
|
expect(response).to redirect_to(<%= index_helper %>_url)
|
134
135
|
end
|
135
136
|
end
|
@@ -4,6 +4,7 @@
|
|
4
4
|
require "rspec/mocks/argument_matchers"
|
5
5
|
require "rspec/rails/matchers/active_job"
|
6
6
|
|
7
|
+
# rubocop: disable Metrics/ClassLength
|
7
8
|
module RSpec
|
8
9
|
module Rails
|
9
10
|
module Matchers
|
@@ -119,9 +120,11 @@ module RSpec
|
|
119
120
|
end
|
120
121
|
|
121
122
|
def mail_job_message(job)
|
122
|
-
|
123
|
+
job_args = deserialize_arguments(job)
|
124
|
+
|
125
|
+
mailer_method = job_args[0..1].join('.')
|
126
|
+
mailer_args = job_args[3..-1]
|
123
127
|
|
124
|
-
mailer_args = job[:args][3..-1]
|
125
128
|
msg_parts = []
|
126
129
|
msg_parts << "with #{mailer_args}" if mailer_args.any?
|
127
130
|
msg_parts << "on queue #{job[:queue]}" if job[:queue] && job[:queue] != 'mailers'
|
@@ -130,6 +133,30 @@ module RSpec
|
|
130
133
|
"#{mailer_method} #{msg_parts.join(', ')}".strip
|
131
134
|
end
|
132
135
|
|
136
|
+
# Ruby 3.1 changed how params were serialized on Rails 6.1
|
137
|
+
# so we override the active job implementation and customise it here.
|
138
|
+
def deserialize_arguments(job)
|
139
|
+
args = super
|
140
|
+
|
141
|
+
return args unless Hash === args.last
|
142
|
+
|
143
|
+
hash = args.pop
|
144
|
+
|
145
|
+
if hash.key?("_aj_ruby2_keywords")
|
146
|
+
keywords = hash["_aj_ruby2_keywords"]
|
147
|
+
|
148
|
+
original_hash = keywords.each_with_object({}) { |keyword, new_hash| new_hash[keyword.to_sym] = hash[keyword] }
|
149
|
+
|
150
|
+
args + [original_hash]
|
151
|
+
elsif hash.key?(:args) && hash.key?(:params)
|
152
|
+
args + [hash]
|
153
|
+
elsif hash.key?(:args)
|
154
|
+
args + hash[:args]
|
155
|
+
else
|
156
|
+
args + [hash]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
133
160
|
def legacy_mail?(job)
|
134
161
|
job[:job] <= ActionMailer::DeliveryJob
|
135
162
|
end
|
@@ -196,3 +223,4 @@ module RSpec
|
|
196
223
|
end
|
197
224
|
end
|
198
225
|
end
|
226
|
+
# rubocop: enable Metrics/ClassLength
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# The following code inspired and modified from Rails' `assert_response`:
|
2
2
|
#
|
3
|
-
# https://github.com/rails/rails/blob/
|
3
|
+
# https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/testing/assertions/response.rb#L22-L38
|
4
4
|
#
|
5
5
|
# Thank you to all the Rails devs who did the heavy lifting on this!
|
6
6
|
|
@@ -243,7 +243,7 @@ module RSpec
|
|
243
243
|
|
244
244
|
# @return [Array<Symbol>] of status codes which represent a HTTP status
|
245
245
|
# code "group"
|
246
|
-
# @see https://github.com/rails/rails/blob/
|
246
|
+
# @see https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
|
247
247
|
def self.valid_statuses
|
248
248
|
[
|
249
249
|
:error, :success, :missing,
|
@@ -313,7 +313,7 @@ module RSpec
|
|
313
313
|
|
314
314
|
# @return [String] formatting the associated code(s) for the various
|
315
315
|
# status code "groups"
|
316
|
-
# @see https://github.com/rails/rails/blob/
|
316
|
+
# @see https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
|
317
317
|
# @see https://github.com/rack/rack/blob/master/lib/rack/response.rb `Rack::Response`
|
318
318
|
def type_codes
|
319
319
|
# At the time of this commit the most recent version of
|
@@ -373,7 +373,7 @@ module RSpec
|
|
373
373
|
# expect(response).to have_http_status(404)
|
374
374
|
# expect(page).to have_http_status(:created)
|
375
375
|
#
|
376
|
-
# @see https://github.com/rails/rails/blob/
|
376
|
+
# @see https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
|
377
377
|
# @see https://github.com/rack/rack/blob/master/lib/rack/utils.rb `Rack::Utils::SYMBOL_TO_STATUS_CODE`
|
378
378
|
def have_http_status(target)
|
379
379
|
raise ArgumentError, "Invalid HTTP status: nil" unless target
|
data/lib/rspec/rails/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Chelimsky
|
8
8
|
- Andy Lindeman
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
12
|
- |
|
@@ -44,7 +44,7 @@ cert_chain:
|
|
44
44
|
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
45
45
|
F3MdtaDehhjC
|
46
46
|
-----END CERTIFICATE-----
|
47
|
-
date:
|
47
|
+
date: 2022-04-24 00:00:00.000000000 Z
|
48
48
|
dependencies:
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: actionpack
|
@@ -176,16 +176,28 @@ dependencies:
|
|
176
176
|
name: cucumber
|
177
177
|
requirement: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
|
-
- - "
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '3.2'
|
182
|
+
- - "!="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: 4.0.0
|
185
|
+
- - "<"
|
180
186
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
187
|
+
version: 8.0.0
|
182
188
|
type: :development
|
183
189
|
prerelease: false
|
184
190
|
version_requirements: !ruby/object:Gem::Requirement
|
185
191
|
requirements:
|
186
|
-
- - "
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '3.2'
|
195
|
+
- - "!="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: 4.0.0
|
198
|
+
- - "<"
|
187
199
|
- !ruby/object:Gem::Version
|
188
|
-
version:
|
200
|
+
version: 8.0.0
|
189
201
|
description: rspec-rails is a testing framework for Rails 5+.
|
190
202
|
email: rspec@googlegroups.com
|
191
203
|
executables: []
|
@@ -296,11 +308,11 @@ licenses:
|
|
296
308
|
- MIT
|
297
309
|
metadata:
|
298
310
|
bug_tracker_uri: https://github.com/rspec/rspec-rails/issues
|
299
|
-
changelog_uri: https://github.com/rspec/rspec-rails/blob/v5.
|
311
|
+
changelog_uri: https://github.com/rspec/rspec-rails/blob/v5.1.2/Changelog.md
|
300
312
|
documentation_uri: https://rspec.info/documentation/
|
301
313
|
mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
|
302
314
|
source_code_uri: https://github.com/rspec/rspec-rails
|
303
|
-
post_install_message:
|
315
|
+
post_install_message:
|
304
316
|
rdoc_options:
|
305
317
|
- "--charset=UTF-8"
|
306
318
|
require_paths:
|
@@ -316,8 +328,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
328
|
- !ruby/object:Gem::Version
|
317
329
|
version: '0'
|
318
330
|
requirements: []
|
319
|
-
rubygems_version: 3.
|
320
|
-
signing_key:
|
331
|
+
rubygems_version: 3.1.6
|
332
|
+
signing_key:
|
321
333
|
specification_version: 4
|
322
334
|
summary: RSpec for Rails
|
323
335
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|