rspec-rails 4.0.0 → 6.1.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 +247 -53
- data/README.md +73 -61
- data/lib/generators/rspec/channel/channel_generator.rb +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +5 -5
- data/lib/generators/rspec/controller/templates/request_spec.rb +6 -1
- 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 +13 -8
- data/lib/generators/rspec/integration/integration_generator.rb +10 -3
- data/lib/generators/rspec/job/job_generator.rb +2 -1
- data/lib/generators/rspec/job/templates/job_spec.rb.erb +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/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +2 -2
- 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 +8 -4
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +13 -13
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +20 -20
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +25 -58
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +8 -8
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -1
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -5
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +38 -18
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +14 -16
- 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 +82 -18
- data/lib/rspec/rails/example/controller_example_group.rb +1 -0
- data/lib/rspec/rails/example/mailbox_example_group.rb +2 -2
- data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +8 -0
- data/lib/rspec/rails/example/request_example_group.rb +1 -4
- data/lib/rspec/rails/example/routing_example_group.rb +0 -2
- data/lib/rspec/rails/example/system_example_group.rb +63 -15
- data/lib/rspec/rails/example/view_example_group.rb +6 -5
- data/lib/rspec/rails/extensions/active_record/proxy.rb +4 -1
- data/lib/rspec/rails/feature_check.rb +6 -2
- data/lib/rspec/rails/file_fixture_support.rb +11 -10
- data/lib/rspec/rails/fixture_file_upload_support.rb +19 -14
- data/lib/rspec/rails/fixture_support.rb +49 -24
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +6 -3
- data/lib/rspec/rails/matchers/action_mailbox.rb +14 -5
- data/lib/rspec/rails/matchers/active_job.rb +32 -6
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +34 -5
- data/lib/rspec/rails/matchers/have_http_status.rb +5 -5
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- 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/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 +13 -11
- data.tar.gz.sig +0 -0
- metadata +28 -27
- metadata.gz.sig +0 -0
- /data/lib/generators/rspec/{integration → request}/templates/request_spec.rb +0 -0
@@ -46,11 +46,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
46
46
|
describe "GET #index" do
|
47
47
|
it "returns a success response" do
|
48
48
|
<%= class_name %>.create! valid_attributes
|
49
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
50
|
-
get :index, {}, valid_session
|
51
|
-
<% else -%>
|
52
49
|
get :index, params: {}, session: valid_session
|
53
|
-
<% end -%>
|
54
50
|
expect(response).to be_successful
|
55
51
|
end
|
56
52
|
end
|
@@ -59,22 +55,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
59
55
|
describe "GET #show" do
|
60
56
|
it "returns a success response" do
|
61
57
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
62
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
63
|
-
get :show, {id: <%= file_name %>.to_param}, valid_session
|
64
|
-
<% else -%>
|
65
58
|
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
66
|
-
<% end -%>
|
67
59
|
expect(response).to be_successful
|
68
60
|
end
|
69
61
|
end
|
70
62
|
|
71
63
|
describe "GET #new" do
|
72
64
|
it "returns a success response" do
|
73
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
74
|
-
get :new, {}, valid_session
|
75
|
-
<% else -%>
|
76
65
|
get :new, params: {}, session: valid_session
|
77
|
-
<% end -%>
|
78
66
|
expect(response).to be_successful
|
79
67
|
end
|
80
68
|
end
|
@@ -82,11 +70,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
82
70
|
describe "GET #edit" do
|
83
71
|
it "returns a success response" do
|
84
72
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
85
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
86
|
-
get :edit, {id: <%= file_name %>.to_param}, valid_session
|
87
|
-
<% else -%>
|
88
73
|
get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
|
89
|
-
<% end -%>
|
90
74
|
expect(response).to be_successful
|
91
75
|
end
|
92
76
|
end
|
@@ -95,33 +79,28 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
95
79
|
context "with valid params" do
|
96
80
|
it "creates a new <%= class_name %>" do
|
97
81
|
expect {
|
98
|
-
|
99
|
-
post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
|
100
|
-
<% else -%>
|
101
|
-
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
102
|
-
<% end -%>
|
82
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
103
83
|
}.to change(<%= class_name %>, :count).by(1)
|
104
84
|
end
|
105
85
|
|
106
|
-
it "redirects to the created <%=
|
107
|
-
|
108
|
-
post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
|
109
|
-
<% else -%>
|
110
|
-
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
111
|
-
<% end -%>
|
86
|
+
it "redirects to the created <%= singular_table_name %>" do
|
87
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
112
88
|
expect(response).to redirect_to(<%= class_name %>.last)
|
113
89
|
end
|
114
90
|
end
|
115
91
|
|
116
92
|
context "with invalid params" do
|
93
|
+
<% if Rails.version.to_f < 7.0 %>
|
117
94
|
it "returns a success response (i.e. to display the 'new' template)" do
|
118
|
-
|
119
|
-
post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session
|
120
|
-
<% else -%>
|
121
|
-
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
|
122
|
-
<% end -%>
|
95
|
+
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
123
96
|
expect(response).to be_successful
|
124
97
|
end
|
98
|
+
<% else %>
|
99
|
+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
100
|
+
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
101
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
102
|
+
end
|
103
|
+
<% end %>
|
125
104
|
end
|
126
105
|
end
|
127
106
|
|
@@ -131,60 +110,48 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
131
110
|
skip("Add a hash of attributes valid for your model")
|
132
111
|
}
|
133
112
|
|
134
|
-
it "updates the requested <%=
|
113
|
+
it "updates the requested <%= singular_table_name %>" do
|
135
114
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
136
|
-
|
137
|
-
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session
|
138
|
-
<% else -%>
|
139
|
-
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
|
140
|
-
<% end -%>
|
115
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
141
116
|
<%= file_name %>.reload
|
142
117
|
skip("Add assertions for updated state")
|
143
118
|
end
|
144
119
|
|
145
|
-
it "redirects to the <%=
|
120
|
+
it "redirects to the <%= singular_table_name %>" do
|
146
121
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
147
|
-
|
148
|
-
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session
|
149
|
-
<% else -%>
|
150
|
-
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
|
151
|
-
<% end -%>
|
122
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
152
123
|
expect(response).to redirect_to(<%= file_name %>)
|
153
124
|
end
|
154
125
|
end
|
155
126
|
|
156
127
|
context "with invalid params" do
|
128
|
+
<% if Rails.version.to_f < 7.0 %>
|
157
129
|
it "returns a success response (i.e. to display the 'edit' template)" do
|
158
130
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
159
|
-
|
160
|
-
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session
|
161
|
-
<% else -%>
|
162
|
-
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
|
163
|
-
<% end -%>
|
131
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
164
132
|
expect(response).to be_successful
|
165
133
|
end
|
134
|
+
<% else %>
|
135
|
+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
136
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
137
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
138
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
139
|
+
end
|
140
|
+
<% end %>
|
166
141
|
end
|
167
142
|
end
|
168
143
|
|
169
144
|
describe "DELETE #destroy" do
|
170
|
-
it "destroys the requested <%=
|
145
|
+
it "destroys the requested <%= singular_table_name %>" do
|
171
146
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
172
147
|
expect {
|
173
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
174
|
-
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
|
175
|
-
<% else -%>
|
176
148
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
177
|
-
<% end -%>
|
178
149
|
}.to change(<%= class_name %>, :count).by(-1)
|
179
150
|
end
|
180
151
|
|
181
152
|
it "redirects to the <%= table_name %> list" do
|
182
153
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
183
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
184
|
-
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
|
185
|
-
<% else -%>
|
186
154
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
187
|
-
<% end -%>
|
188
155
|
expect(response).to redirect_to(<%= index_helper %>_url)
|
189
156
|
end
|
190
157
|
end
|
@@ -2,25 +2,25 @@ 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
|
-
<% if Rails.version.to_f >= 5.1 -%>
|
20
23
|
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
21
|
-
<% else -%>
|
22
|
-
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
23
|
-
<% end -%>
|
24
24
|
<% end -%>
|
25
25
|
end
|
26
26
|
end
|
@@ -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 = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td'
|
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 -%>
|
@@ -15,11 +15,7 @@ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
|
15
15
|
assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
|
16
16
|
<% for attribute in output_attributes -%>
|
17
17
|
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
18
|
-
<% if Rails.version.to_f >= 5.1 -%>
|
19
18
|
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
20
|
-
<% else -%>
|
21
|
-
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
22
|
-
<% end -%>
|
23
19
|
<% end -%>
|
24
20
|
end
|
25
21
|
end
|
@@ -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
|
@@ -14,6 +14,11 @@
|
|
14
14
|
|
15
15
|
<% module_namespacing do -%>
|
16
16
|
RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
|
17
|
+
<% if mountable_engine? -%>
|
18
|
+
include Engine.routes.url_helpers
|
19
|
+
<% end -%>
|
20
|
+
|
21
|
+
# This should return the minimal set of attributes required to create a valid
|
17
22
|
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
18
23
|
# adjust the attributes here as well.
|
19
24
|
let(:valid_attributes) {
|
@@ -37,7 +42,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
37
42
|
describe "GET /show" do
|
38
43
|
it "renders a successful response" do
|
39
44
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
40
|
-
get <%= show_helper
|
45
|
+
get <%= show_helper %>
|
41
46
|
expect(response).to be_successful
|
42
47
|
end
|
43
48
|
end
|
@@ -50,9 +55,9 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
50
55
|
end
|
51
56
|
|
52
57
|
describe "GET /edit" do
|
53
|
-
it "
|
58
|
+
it "renders a successful response" do
|
54
59
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
55
|
-
get <%= edit_helper
|
60
|
+
get <%= edit_helper %>
|
56
61
|
expect(response).to be_successful
|
57
62
|
end
|
58
63
|
end
|
@@ -61,27 +66,34 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
61
66
|
context "with valid parameters" do
|
62
67
|
it "creates a new <%= class_name %>" do
|
63
68
|
expect {
|
64
|
-
post <%= index_helper %>_url, params: { <%=
|
69
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
|
65
70
|
}.to change(<%= class_name %>, :count).by(1)
|
66
71
|
end
|
67
72
|
|
68
|
-
it "redirects to the created <%=
|
69
|
-
post <%= index_helper %>_url, params: { <%=
|
70
|
-
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") %>)
|
71
76
|
end
|
72
77
|
end
|
73
78
|
|
74
79
|
context "with invalid parameters" do
|
75
80
|
it "does not create a new <%= class_name %>" do
|
76
81
|
expect {
|
77
|
-
post <%= index_helper %>_url, params: { <%=
|
82
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
78
83
|
}.to change(<%= class_name %>, :count).by(0)
|
79
84
|
end
|
80
85
|
|
86
|
+
<% if Rails.version.to_f < 7.0 %>
|
81
87
|
it "renders a successful response (i.e. to display the 'new' template)" do
|
82
|
-
post <%= index_helper %>_url, params: { <%=
|
88
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
83
89
|
expect(response).to be_successful
|
84
90
|
end
|
91
|
+
<% else %>
|
92
|
+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
93
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
94
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
95
|
+
end
|
96
|
+
<% end %>
|
85
97
|
end
|
86
98
|
end
|
87
99
|
|
@@ -91,41 +103,49 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
|
|
91
103
|
skip("Add a hash of attributes valid for your model")
|
92
104
|
}
|
93
105
|
|
94
|
-
it "updates the requested <%=
|
106
|
+
it "updates the requested <%= singular_table_name %>" do
|
95
107
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
96
|
-
patch <%= show_helper
|
108
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
|
97
109
|
<%= file_name %>.reload
|
98
110
|
skip("Add assertions for updated state")
|
99
111
|
end
|
100
112
|
|
101
|
-
it "redirects to the <%=
|
113
|
+
it "redirects to the <%= singular_table_name %>" do
|
102
114
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
103
|
-
patch <%= show_helper
|
115
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
|
104
116
|
<%= file_name %>.reload
|
105
117
|
expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
|
106
118
|
end
|
107
119
|
end
|
108
120
|
|
109
121
|
context "with invalid parameters" do
|
122
|
+
<% if Rails.version.to_f < 7.0 %>
|
110
123
|
it "renders a successful response (i.e. to display the 'edit' template)" do
|
111
124
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
112
|
-
patch <%= show_helper
|
125
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
|
113
126
|
expect(response).to be_successful
|
114
127
|
end
|
128
|
+
<% else %>
|
129
|
+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
130
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
131
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
|
132
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
133
|
+
end
|
134
|
+
<% end %>
|
115
135
|
end
|
116
136
|
end
|
117
137
|
|
118
138
|
describe "DELETE /destroy" do
|
119
|
-
it "destroys the requested <%=
|
139
|
+
it "destroys the requested <%= singular_table_name %>" do
|
120
140
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
121
141
|
expect {
|
122
|
-
delete <%= show_helper
|
142
|
+
delete <%= show_helper %>
|
123
143
|
}.to change(<%= class_name %>, :count).by(-1)
|
124
144
|
end
|
125
145
|
|
126
146
|
it "redirects to the <%= table_name %> list" do
|
127
147
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
128
|
-
delete <%= show_helper
|
148
|
+
delete <%= show_helper %>
|
129
149
|
expect(response).to redirect_to(<%= index_helper %>_url)
|
130
150
|
end
|
131
151
|
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 %>/show", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
|
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 -%>
|
@@ -1,25 +1,23 @@
|
|
1
1
|
require 'generators/rspec'
|
2
2
|
|
3
|
-
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
# @private
|
6
|
+
class SystemGenerator < Base
|
7
|
+
class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
def generate_system_spec
|
10
|
+
return unless options[:system_specs]
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
template template_name, target_path('system', class_path, filename)
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def template_name
|
16
|
+
'system_spec.rb'
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
19
|
+
def filename
|
20
|
+
"#{table_name}_spec.rb"
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
@@ -9,12 +9,12 @@ module Rspec
|
|
9
9
|
class_option :template_engine, desc: "Template engine to generate view files"
|
10
10
|
|
11
11
|
def create_view_specs
|
12
|
-
empty_directory
|
12
|
+
empty_directory target_path("views", file_path)
|
13
13
|
|
14
14
|
actions.each do |action|
|
15
15
|
@action = action
|
16
16
|
template 'view_spec.rb',
|
17
|
-
|
17
|
+
target_path("views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/generators/rspec.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'rails/generators/named_base'
|
2
|
+
require 'rspec/core'
|
2
3
|
require 'rspec/rails/feature_check'
|
3
4
|
|
4
5
|
# @private
|
5
|
-
# Weirdly named generators namespace (should be `RSpec`) for
|
6
|
+
# Weirdly named generators namespace (should be `RSpec`) for compatibility with
|
6
7
|
# rails loading.
|
7
8
|
module Rspec
|
8
9
|
# @private
|
@@ -18,6 +19,22 @@ module Rspec
|
|
18
19
|
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
19
20
|
end
|
20
21
|
end
|
22
|
+
|
23
|
+
# @private
|
24
|
+
# Load configuration from RSpec to ensure `--default-path` is set
|
25
|
+
def self.configuration
|
26
|
+
@configuration ||=
|
27
|
+
begin
|
28
|
+
configuration = RSpec.configuration
|
29
|
+
options = RSpec::Core::ConfigurationOptions.new({})
|
30
|
+
options.configure(configuration)
|
31
|
+
configuration
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def target_path(*paths)
|
36
|
+
File.join(self.class.configuration.default_path, *paths)
|
37
|
+
end
|
21
38
|
end
|
22
39
|
end
|
23
40
|
end
|
data/lib/rspec/rails/adapters.rb
CHANGED
@@ -181,5 +181,16 @@ module RSpec
|
|
181
181
|
#
|
182
182
|
# @private
|
183
183
|
TestUnitAssertionAdapter = MinitestAssertionAdapter
|
184
|
+
|
185
|
+
# @private
|
186
|
+
module TaggedLoggingAdapter
|
187
|
+
private
|
188
|
+
# Vendored from activesupport/lib/active_support/testing/tagged_logging.rb
|
189
|
+
# This implements the tagged_logger method where it is expected, but
|
190
|
+
# doesn't call `name` or set it up like Rails does.
|
191
|
+
def tagged_logger
|
192
|
+
@tagged_logger ||= (defined?(Rails.logger) && Rails.logger)
|
193
|
+
end
|
194
|
+
end
|
184
195
|
end
|
185
196
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop: disable Metrics/ModuleLength
|
1
2
|
module RSpec
|
2
3
|
module Rails
|
3
4
|
# Fake class to document RSpec Rails configuration options. In practice,
|
@@ -25,18 +26,19 @@ module RSpec
|
|
25
26
|
#
|
26
27
|
# @api private
|
27
28
|
DIRECTORY_MAPPINGS = {
|
28
|
-
channel:
|
29
|
+
channel: %w[spec channels],
|
29
30
|
controller: %w[spec controllers],
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
generator: %w[spec generator],
|
32
|
+
helper: %w[spec helpers],
|
33
|
+
job: %w[spec jobs],
|
34
|
+
mailer: %w[spec mailers],
|
35
|
+
model: %w[spec models],
|
36
|
+
request: %w[spec (requests|integration|api)],
|
37
|
+
routing: %w[spec routing],
|
38
|
+
view: %w[spec views],
|
39
|
+
feature: %w[spec features],
|
40
|
+
system: %w[spec system],
|
41
|
+
mailbox: %w[spec mailboxes]
|
40
42
|
}
|
41
43
|
|
42
44
|
# Sets up the different example group modules for the different spec types
|
@@ -55,7 +57,7 @@ module RSpec
|
|
55
57
|
end
|
56
58
|
|
57
59
|
# @private
|
58
|
-
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength
|
60
|
+
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
|
59
61
|
config.backtrace_exclusion_patterns << /vendor\//
|
60
62
|
config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
|
61
63
|
|
@@ -67,7 +69,13 @@ module RSpec
|
|
67
69
|
config.add_setting :use_transactional_fixtures, alias_with: :use_transactional_examples
|
68
70
|
config.add_setting :use_instantiated_fixtures
|
69
71
|
config.add_setting :global_fixtures
|
70
|
-
|
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
|
+
|
71
79
|
config.include RSpec::Rails::FixtureSupport, :use_fixtures
|
72
80
|
|
73
81
|
# We'll need to create a deprecated module in order to properly report to
|
@@ -79,10 +87,8 @@ module RSpec
|
|
79
87
|
# `RSpec::Rails::FixtureSupport` directly instead
|
80
88
|
config.include RSpec::Rails::FixtureSupport
|
81
89
|
|
82
|
-
|
83
|
-
|
84
|
-
config.include RSpec::Rails::FileFixtureSupport
|
85
|
-
end
|
90
|
+
config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
|
91
|
+
config.include RSpec::Rails::FileFixtureSupport
|
86
92
|
|
87
93
|
# Add support for fixture_path on fixture_file_upload
|
88
94
|
config.include RSpec::Rails::FixtureFileUploadSupport
|
@@ -105,7 +111,41 @@ module RSpec
|
|
105
111
|
end
|
106
112
|
|
107
113
|
def render_views?
|
108
|
-
rendering_views
|
114
|
+
rendering_views?
|
115
|
+
end
|
116
|
+
|
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
|
109
149
|
end
|
110
150
|
|
111
151
|
def infer_spec_type_from_file_location!
|
@@ -123,6 +163,29 @@ module RSpec
|
|
123
163
|
filter_gems_from_backtrace "activemodel", "activerecord",
|
124
164
|
"activesupport", "activejob"
|
125
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
|
126
189
|
end
|
127
190
|
|
128
191
|
add_test_type_configurations(config)
|
@@ -156,3 +219,4 @@ module RSpec
|
|
156
219
|
initialize_configuration RSpec.configuration
|
157
220
|
end
|
158
221
|
end
|
222
|
+
# rubocop: enable Metrics/ModuleLength
|