rspec-rails 3.9.0 → 4.0.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/Capybara.md +5 -54
- data/Changelog.md +156 -78
- data/README.md +8 -7
- data/lib/generators/rspec/channel/channel_generator.rb +12 -0
- data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +21 -4
- data/lib/generators/rspec/controller/templates/request_spec.rb +14 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
- data/lib/generators/rspec/feature/feature_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/generator_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/templates/generator_spec.rb +0 -0
- data/lib/generators/rspec/helper/helper_generator.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +4 -4
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +17 -16
- data/lib/generators/rspec/integration/integration_generator.rb +3 -3
- data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
- data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +2 -1
- data/lib/generators/rspec/model/model_generator.rb +5 -4
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/request/request_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +29 -19
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +0 -36
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +10 -10
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +133 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +1 -1
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/generators/rspec.rb +0 -6
- data/lib/rspec/rails/adapters.rb +11 -76
- data/lib/rspec/rails/configuration.rb +43 -33
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +4 -4
- data/lib/rspec/rails/example/feature_example_group.rb +6 -26
- data/lib/rspec/rails/example/helper_example_group.rb +2 -9
- data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/system_example_group.rb +26 -10
- data/lib/rspec/rails/example/view_example_group.rb +38 -27
- data/lib/rspec/rails/example.rb +2 -0
- data/lib/rspec/rails/extensions/active_record/proxy.rb +1 -9
- data/lib/rspec/rails/feature_check.rb +12 -29
- data/lib/rspec/rails/fixture_file_upload_support.rb +1 -1
- data/lib/rspec/rails/fixture_support.rb +37 -31
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -0
- data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
- data/lib/rspec/rails/matchers/action_cable.rb +65 -0
- data/lib/rspec/rails/matchers/action_mailbox.rb +64 -0
- data/lib/rspec/rails/matchers/active_job.rb +148 -22
- data/lib/rspec/rails/matchers/base_matcher.rb +5 -10
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +52 -28
- data/lib/rspec/rails/matchers/have_http_status.rb +11 -7
- data/lib/rspec/rails/matchers/have_rendered.rb +1 -0
- data/lib/rspec/rails/matchers/routing_matchers.rb +12 -12
- data/lib/rspec/rails/matchers.rb +10 -0
- data/lib/rspec/rails/tasks/rspec.rake +7 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -15
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_path_builder.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +15 -4
- data/lib/rspec-rails.rb +8 -9
- data.tar.gz.sig +0 -0
- metadata +46 -34
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
|
+
# It demonstrates how one might use RSpec to test the controller code that
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
|
15
|
+
<% module_namespacing do -%>
|
16
|
+
RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
|
17
|
+
# This should return the minimal set of attributes required to create a valid
|
18
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
19
|
+
# adjust the attributes here as well.
|
20
|
+
let(:valid_attributes) {
|
21
|
+
skip("Add a hash of attributes valid for your model")
|
22
|
+
}
|
23
|
+
|
24
|
+
let(:invalid_attributes) {
|
25
|
+
skip("Add a hash of attributes invalid for your model")
|
26
|
+
}
|
27
|
+
|
28
|
+
# This should return the minimal set of values that should be in the headers
|
29
|
+
# in order to pass any filters (e.g. authentication) defined in
|
30
|
+
# <%= controller_class_name %>Controller, or in your router and rack
|
31
|
+
# middleware. Be sure to keep this updated too.
|
32
|
+
let(:valid_headers) {
|
33
|
+
{}
|
34
|
+
}
|
35
|
+
|
36
|
+
<% unless options[:singleton] -%>
|
37
|
+
describe "GET /index" do
|
38
|
+
it "renders a successful response" do
|
39
|
+
<%= class_name %>.create! valid_attributes
|
40
|
+
get <%= index_helper %>_url, headers: valid_headers, as: :json
|
41
|
+
expect(response).to be_successful
|
42
|
+
end
|
43
|
+
end
|
44
|
+
<% end -%>
|
45
|
+
|
46
|
+
describe "GET /show" do
|
47
|
+
it "renders a successful response" do
|
48
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
49
|
+
get <%= show_helper.tr('@', '') %>, as: :json
|
50
|
+
expect(response).to be_successful
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "POST /create" do
|
55
|
+
context "with valid parameters" do
|
56
|
+
it "creates a new <%= class_name %>" do
|
57
|
+
expect {
|
58
|
+
post <%= index_helper %>_url,
|
59
|
+
params: { <%= ns_file_name %>: valid_attributes }, headers: valid_headers, as: :json
|
60
|
+
}.to change(<%= class_name %>, :count).by(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "renders a JSON response with the new <%= ns_file_name %>" do
|
64
|
+
post <%= index_helper %>_url,
|
65
|
+
params: { <%= ns_file_name %>: valid_attributes }, headers: valid_headers, as: :json
|
66
|
+
expect(response).to have_http_status(:created)
|
67
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with invalid parameters" do
|
72
|
+
it "does not create a new <%= class_name %>" do
|
73
|
+
expect {
|
74
|
+
post <%= index_helper %>_url,
|
75
|
+
params: { <%= ns_file_name %>: invalid_attributes }, as: :json
|
76
|
+
}.to change(<%= class_name %>, :count).by(0)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "renders a JSON response with errors for the new <%= ns_file_name %>" do
|
80
|
+
post <%= index_helper %>_url,
|
81
|
+
params: { <%= ns_file_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
82
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
83
|
+
expect(response.content_type).to eq("application/json")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "PATCH /update" do
|
89
|
+
context "with valid parameters" do
|
90
|
+
let(:new_attributes) {
|
91
|
+
skip("Add a hash of attributes valid for your model")
|
92
|
+
}
|
93
|
+
|
94
|
+
it "updates the requested <%= ns_file_name %>" do
|
95
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
96
|
+
patch <%= show_helper.tr('@', '') %>,
|
97
|
+
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
98
|
+
<%= file_name %>.reload
|
99
|
+
skip("Add assertions for updated state")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "renders a JSON response with the <%= ns_file_name %>" do
|
103
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
104
|
+
patch <%= show_helper.tr('@', '') %>,
|
105
|
+
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
106
|
+
expect(response).to have_http_status(:ok)
|
107
|
+
expect(response.content_type).to eq("application/json")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "with invalid parameters" do
|
112
|
+
it "renders a JSON response with errors for the <%= ns_file_name %>" do
|
113
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
114
|
+
patch <%= show_helper.tr('@', '') %>,
|
115
|
+
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
116
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
117
|
+
expect(response.content_type).to eq("application/json")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "DELETE /destroy" do
|
123
|
+
it "destroys the requested <%= ns_file_name %>" do
|
124
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
125
|
+
expect {
|
126
|
+
delete <%= show_helper.tr('@', '') %>, headers: valid_headers, as: :json
|
127
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
<% end -%>
|
@@ -60,7 +60,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
60
60
|
it "returns a success response" do
|
61
61
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
62
62
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
63
|
-
get :show, {:
|
63
|
+
get :show, {id: <%= file_name %>.to_param}, valid_session
|
64
64
|
<% else -%>
|
65
65
|
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
66
66
|
<% end -%>
|
@@ -83,7 +83,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
83
83
|
it "returns a success response" do
|
84
84
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
85
85
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
86
|
-
get :edit, {:
|
86
|
+
get :edit, {id: <%= file_name %>.to_param}, valid_session
|
87
87
|
<% else -%>
|
88
88
|
get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
|
89
89
|
<% end -%>
|
@@ -96,7 +96,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
96
96
|
it "creates a new <%= class_name %>" do
|
97
97
|
expect {
|
98
98
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
99
|
-
post :create, {
|
99
|
+
post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
|
100
100
|
<% else -%>
|
101
101
|
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
102
102
|
<% end -%>
|
@@ -105,7 +105,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
105
105
|
|
106
106
|
it "redirects to the created <%= ns_file_name %>" do
|
107
107
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
108
|
-
post :create, {
|
108
|
+
post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
|
109
109
|
<% else -%>
|
110
110
|
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
111
111
|
<% end -%>
|
@@ -116,7 +116,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
116
116
|
context "with invalid params" do
|
117
117
|
it "returns a success response (i.e. to display the 'new' template)" do
|
118
118
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
119
|
-
post :create, {
|
119
|
+
post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session
|
120
120
|
<% else -%>
|
121
121
|
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
|
122
122
|
<% end -%>
|
@@ -134,7 +134,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
134
134
|
it "updates the requested <%= ns_file_name %>" do
|
135
135
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
136
136
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
137
|
-
put :update, {:
|
137
|
+
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session
|
138
138
|
<% else -%>
|
139
139
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
|
140
140
|
<% end -%>
|
@@ -145,7 +145,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
145
145
|
it "redirects to the <%= ns_file_name %>" do
|
146
146
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
147
147
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
148
|
-
put :update, {:
|
148
|
+
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session
|
149
149
|
<% else -%>
|
150
150
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
|
151
151
|
<% end -%>
|
@@ -157,7 +157,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
157
157
|
it "returns a success response (i.e. to display the 'edit' template)" do
|
158
158
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
159
159
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
160
|
-
put :update, {:
|
160
|
+
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session
|
161
161
|
<% else -%>
|
162
162
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
|
163
163
|
<% end -%>
|
@@ -171,7 +171,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
171
171
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
172
172
|
expect {
|
173
173
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
174
|
-
delete :destroy, {:
|
174
|
+
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
|
175
175
|
<% else -%>
|
176
176
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
177
177
|
<% end -%>
|
@@ -181,7 +181,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
181
181
|
it "redirects to the <%= table_name %> list" do
|
182
182
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
183
183
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
184
|
-
delete :destroy, {:
|
184
|
+
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
|
185
185
|
<% else -%>
|
186
186
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
187
187
|
<% end -%>
|
@@ -5,7 +5,7 @@ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
|
5
5
|
before(:each) do
|
6
6
|
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= 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
|
<%= output_attributes.empty? ? "" : " ))\n" -%>
|
11
11
|
end
|
@@ -7,7 +7,7 @@ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
|
|
7
7
|
<% [1,2].each_with_index do |id, model_index| -%>
|
8
8
|
<%= class_name %>.create!(<%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : '' %>
|
9
9
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
10
|
-
|
10
|
+
<%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
11
11
|
<% end -%>
|
12
12
|
<% if !output_attributes.empty? -%>
|
13
13
|
<%= model_index == 1 ? ')' : '),' %>
|
@@ -19,7 +19,7 @@ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
|
|
19
19
|
it "renders a list of <%= ns_table_name %>" do
|
20
20
|
render
|
21
21
|
<% for attribute in output_attributes -%>
|
22
|
-
assert_select "tr>td", :
|
22
|
+
assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 2
|
23
23
|
<% end -%>
|
24
24
|
end
|
25
25
|
end
|
@@ -5,7 +5,7 @@ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
|
5
5
|
before(:each) do
|
6
6
|
assign(:<%= ns_file_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 -%>
|
10
10
|
<%= !output_attributes.empty? ? " ))\n end" : " end" %>
|
11
11
|
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
|
+
# It demonstrates how one might use RSpec to test the controller code that
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
|
15
|
+
<% module_namespacing do -%>
|
16
|
+
RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
|
17
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
18
|
+
# adjust the attributes here as well.
|
19
|
+
let(:valid_attributes) {
|
20
|
+
skip("Add a hash of attributes valid for your model")
|
21
|
+
}
|
22
|
+
|
23
|
+
let(:invalid_attributes) {
|
24
|
+
skip("Add a hash of attributes invalid for your model")
|
25
|
+
}
|
26
|
+
|
27
|
+
<% unless options[:singleton] -%>
|
28
|
+
describe "GET /index" do
|
29
|
+
it "renders a successful response" do
|
30
|
+
<%= class_name %>.create! valid_attributes
|
31
|
+
get <%= index_helper %>_url
|
32
|
+
expect(response).to be_successful
|
33
|
+
end
|
34
|
+
end
|
35
|
+
<% end -%>
|
36
|
+
|
37
|
+
describe "GET /show" do
|
38
|
+
it "renders a successful response" do
|
39
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
40
|
+
get <%= show_helper.tr('@', '') %>
|
41
|
+
expect(response).to be_successful
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "GET /new" do
|
46
|
+
it "renders a successful response" do
|
47
|
+
get <%= new_helper %>
|
48
|
+
expect(response).to be_successful
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "GET /edit" do
|
53
|
+
it "render a successful response" do
|
54
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
55
|
+
get <%= edit_helper.tr('@','') %>
|
56
|
+
expect(response).to be_successful
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "POST /create" do
|
61
|
+
context "with valid parameters" do
|
62
|
+
it "creates a new <%= class_name %>" do
|
63
|
+
expect {
|
64
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
|
65
|
+
}.to change(<%= class_name %>, :count).by(1)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "redirects to the created <%= ns_file_name %>" do
|
69
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
|
70
|
+
expect(response).to redirect_to(<%= show_helper.gsub("\@#{file_name}", class_name+".last") %>)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with invalid parameters" do
|
75
|
+
it "does not create a new <%= class_name %>" do
|
76
|
+
expect {
|
77
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
|
78
|
+
}.to change(<%= class_name %>, :count).by(0)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "renders a successful response (i.e. to display the 'new' template)" do
|
82
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
|
83
|
+
expect(response).to be_successful
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "PATCH /update" do
|
89
|
+
context "with valid parameters" do
|
90
|
+
let(:new_attributes) {
|
91
|
+
skip("Add a hash of attributes valid for your model")
|
92
|
+
}
|
93
|
+
|
94
|
+
it "updates the requested <%= ns_file_name %>" do
|
95
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
96
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
|
97
|
+
<%= file_name %>.reload
|
98
|
+
skip("Add assertions for updated state")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "redirects to the <%= ns_file_name %>" do
|
102
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
103
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
|
104
|
+
<%= file_name %>.reload
|
105
|
+
expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "with invalid parameters" do
|
110
|
+
it "renders a successful response (i.e. to display the 'edit' template)" do
|
111
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
112
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: invalid_attributes }
|
113
|
+
expect(response).to be_successful
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "DELETE /destroy" do
|
119
|
+
it "destroys the requested <%= ns_file_name %>" do
|
120
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
121
|
+
expect {
|
122
|
+
delete <%= show_helper.tr('@', '') %>
|
123
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "redirects to the <%= table_name %> list" do
|
127
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
128
|
+
delete <%= show_helper.tr('@', '') %>
|
129
|
+
expect(response).to redirect_to(<%= index_helper %>_url)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
<% end -%>
|
@@ -5,43 +5,41 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing
|
|
5
5
|
describe "routing" do
|
6
6
|
<% unless options[:singleton] -%>
|
7
7
|
it "routes to #index" do
|
8
|
-
expect(:
|
8
|
+
expect(get: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
|
9
9
|
end
|
10
10
|
|
11
11
|
<% end -%>
|
12
12
|
<% unless options[:api] -%>
|
13
13
|
it "routes to #new" do
|
14
|
-
expect(:
|
14
|
+
expect(get: "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
|
15
15
|
end
|
16
16
|
|
17
17
|
<% end -%>
|
18
18
|
it "routes to #show" do
|
19
|
-
expect(:
|
19
|
+
expect(get: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", id: "1")
|
20
20
|
end
|
21
21
|
|
22
22
|
<% unless options[:api] -%>
|
23
23
|
it "routes to #edit" do
|
24
|
-
expect(:
|
24
|
+
expect(get: "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", id: "1")
|
25
25
|
end
|
26
26
|
|
27
27
|
<% end -%>
|
28
28
|
|
29
29
|
it "routes to #create" do
|
30
|
-
expect(:
|
30
|
+
expect(post: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
|
31
31
|
end
|
32
32
|
|
33
33
|
it "routes to #update via PUT" do
|
34
|
-
expect(:
|
34
|
+
expect(put: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
|
35
35
|
end
|
36
36
|
|
37
|
-
<% if Rails::VERSION::STRING > '4' -%>
|
38
37
|
it "routes to #update via PATCH" do
|
39
|
-
expect(:
|
38
|
+
expect(patch: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
|
40
39
|
end
|
41
40
|
|
42
|
-
<% end -%>
|
43
41
|
it "routes to #destroy" do
|
44
|
-
expect(:
|
42
|
+
expect(delete: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", id: "1")
|
45
43
|
end
|
46
44
|
end
|
47
45
|
end
|
@@ -5,7 +5,7 @@ RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
|
|
5
5
|
before(:each) do
|
6
6
|
@<%= ns_file_name %> = assign(:<%= ns_file_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 -%>
|
10
10
|
<% if !output_attributes.empty? -%>
|
11
11
|
))
|
@@ -5,7 +5,7 @@ if ::Rails::VERSION::STRING >= '5.1'
|
|
5
5
|
module Generators
|
6
6
|
# @private
|
7
7
|
class SystemGenerator < Base
|
8
|
-
class_option :system_specs, :
|
8
|
+
class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
|
9
9
|
|
10
10
|
def generate_system_spec
|
11
11
|
return unless options[:system_specs]
|
@@ -4,9 +4,9 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class ViewGenerator < Base
|
7
|
-
argument :actions, :
|
7
|
+
argument :actions, type: :array, default: [], banner: "action action"
|
8
8
|
|
9
|
-
class_option :template_engine, :
|
9
|
+
class_option :template_engine, desc: "Template engine to generate view files"
|
10
10
|
|
11
11
|
def create_view_specs
|
12
12
|
empty_directory File.join("spec", "views", file_path)
|
data/lib/generators/rspec.rb
CHANGED
@@ -18,12 +18,6 @@ module Rspec
|
|
18
18
|
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
if ::Rails::VERSION::STRING < '3.1'
|
23
|
-
def module_namespacing
|
24
|
-
yield if block_given?
|
25
|
-
end
|
26
|
-
end
|
27
21
|
end
|
28
22
|
end
|
29
23
|
end
|
data/lib/rspec/rails/adapters.rb
CHANGED
@@ -19,68 +19,15 @@ module RSpec
|
|
19
19
|
end
|
20
20
|
private_class_method :disable_testunit_autorun
|
21
21
|
|
22
|
-
if
|
23
|
-
|
24
|
-
gem 'minitest'
|
25
|
-
else
|
26
|
-
require 'minitest'
|
27
|
-
end
|
28
|
-
require 'minitest/assertions'
|
29
|
-
# Constant aliased to either Minitest or TestUnit, depending on what is
|
30
|
-
# loaded.
|
31
|
-
Assertions = Minitest::Assertions
|
32
|
-
elsif RUBY_VERSION >= '2.2.0'
|
33
|
-
# Minitest / TestUnit has been removed from ruby core. However, we are
|
34
|
-
# on an old Rails version and must load the appropriate gem
|
35
|
-
if ::Rails::VERSION::STRING >= '4.0.0'
|
36
|
-
# ActiveSupport 4.0.x has the minitest '~> 4.2' gem as a dependency
|
37
|
-
# This gem has no `lib/minitest.rb` file.
|
38
|
-
gem 'minitest' if defined?(Kernel.gem)
|
39
|
-
require 'minitest/unit'
|
40
|
-
Assertions = MiniTest::Assertions
|
41
|
-
elsif ::Rails::VERSION::STRING >= '3.2.21'
|
42
|
-
# TODO: Change the above check to >= '3.2.22' once it's released
|
43
|
-
begin
|
44
|
-
# Test::Unit "helpfully" sets up autoload for its `AutoRunner`.
|
45
|
-
# While we do not reference it directly, when we load the `TestCase`
|
46
|
-
# classes from AS (ActiveSupport), AS kindly references `AutoRunner`
|
47
|
-
# for everyone.
|
48
|
-
#
|
49
|
-
# To handle this we need to pre-emptively load 'test/unit' and make
|
50
|
-
# sure the version installed has `AutoRunner` (the 3.x line does to
|
51
|
-
# date). If so, we turn the auto runner off.
|
52
|
-
require 'test/unit'
|
53
|
-
require 'test/unit/assertions'
|
54
|
-
disable_testunit_autorun
|
55
|
-
rescue LoadError => e
|
56
|
-
raise LoadError, <<-ERR.squish, e.backtrace
|
57
|
-
Ruby 2.2+ has removed test/unit from the core library. Rails
|
58
|
-
requires this as a dependency. Please add test-unit gem to your
|
59
|
-
Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})"
|
60
|
-
ERR
|
61
|
-
end
|
62
|
-
Assertions = Test::Unit::Assertions
|
63
|
-
else
|
64
|
-
abort <<-MSG.squish
|
65
|
-
Ruby 2.2+ is not supported on Rails #{::Rails::VERSION::STRING}.
|
66
|
-
Check the Rails release notes for the appropriate update with
|
67
|
-
support.
|
68
|
-
MSG
|
69
|
-
end
|
22
|
+
if defined?(Kernel.gem)
|
23
|
+
gem 'minitest'
|
70
24
|
else
|
71
|
-
|
72
|
-
require 'test/unit/assertions'
|
73
|
-
rescue LoadError
|
74
|
-
# work around for Rubinius not having a std std-lib
|
75
|
-
require 'rubysl-test-unit' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
76
|
-
require 'test/unit/assertions'
|
77
|
-
end
|
78
|
-
# Turn off test unit's auto runner for those using the gem
|
79
|
-
disable_testunit_autorun
|
80
|
-
# Constant aliased to either Minitest or TestUnit, depending on what is
|
81
|
-
# loaded.
|
82
|
-
Assertions = Test::Unit::Assertions
|
25
|
+
require 'minitest'
|
83
26
|
end
|
27
|
+
require 'minitest/assertions'
|
28
|
+
# Constant aliased to either Minitest or TestUnit, depending on what is
|
29
|
+
# loaded.
|
30
|
+
Assertions = Minitest::Assertions
|
84
31
|
|
85
32
|
# @private
|
86
33
|
class AssertionDelegator < Module
|
@@ -103,6 +50,7 @@ module RSpec
|
|
103
50
|
assertion_modules.each do |mod|
|
104
51
|
mod.public_instance_methods.each do |method|
|
105
52
|
next if method == :method_missing || method == "method_missing"
|
53
|
+
|
106
54
|
define_method(method.to_sym) do |*args, &block|
|
107
55
|
assertion_instance.send(method.to_sym, *args, &block)
|
108
56
|
end
|
@@ -198,12 +146,11 @@ module RSpec
|
|
198
146
|
# examples without exposing non-assertion methods in Test::Unit or
|
199
147
|
# Minitest.
|
200
148
|
def assertion_method_names
|
201
|
-
|
202
|
-
public_instance_methods
|
203
|
-
select do |m|
|
149
|
+
::RSpec::Rails::Assertions
|
150
|
+
.public_instance_methods
|
151
|
+
.select do |m|
|
204
152
|
m.to_s =~ /^(assert|flunk|refute)/
|
205
153
|
end
|
206
|
-
methods + test_unit_specific_methods
|
207
154
|
end
|
208
155
|
|
209
156
|
def define_assertion_delegators
|
@@ -213,18 +160,6 @@ module RSpec
|
|
213
160
|
end
|
214
161
|
end
|
215
162
|
end
|
216
|
-
|
217
|
-
# Starting on Rails 4, Minitest is the default testing framework so no
|
218
|
-
# need to add TestUnit specific methods.
|
219
|
-
if ::Rails::VERSION::STRING >= '4.0.0'
|
220
|
-
def test_unit_specific_methods
|
221
|
-
[]
|
222
|
-
end
|
223
|
-
else
|
224
|
-
def test_unit_specific_methods
|
225
|
-
[:build_message]
|
226
|
-
end
|
227
|
-
end
|
228
163
|
end
|
229
164
|
|
230
165
|
class AssertionDelegator
|