rspec-rails 3.7.0 → 4.0.0
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/Capybara.md +5 -54
- data/Changelog.md +259 -70
- data/README.md +265 -496
- 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 +4 -4
- data/lib/generators/rspec/generator/generator_generator.rb +24 -0
- data/lib/generators/rspec/generator/templates/generator_spec.rb +6 -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 +25 -12
- data/lib/generators/rspec/integration/integration_generator.rb +4 -4
- data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
- 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/mailer/templates/preview.rb +1 -1
- data/lib/generators/rspec/model/model_generator.rb +6 -5
- 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 +43 -23
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +2 -38
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +17 -17
- 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 +10 -13
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +26 -0
- data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
- 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 +47 -36
- 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 +1 -1
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/system_example_group.rb +96 -60
- data/lib/rspec/rails/example/view_example_group.rb +47 -28
- data/lib/rspec/rails/example.rb +3 -3
- 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 +40 -0
- 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 +180 -22
- data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +1 -1
- data/lib/rspec/rails/matchers/be_valid.rb +1 -1
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +198 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +34 -13
- data/lib/rspec/rails/matchers/have_rendered.rb +2 -1
- data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +14 -14
- data/lib/rspec/rails/matchers.rb +11 -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 +16 -5
- data/lib/rspec/rails.rb +1 -0
- data/lib/rspec-rails.rb +13 -10
- data.tar.gz.sig +0 -0
- metadata +55 -33
- 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 -%>
|
@@ -45,13 +45,13 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
45
45
|
<% unless options[:singleton] -%>
|
46
46
|
describe "GET #index" do
|
47
47
|
it "returns a success response" do
|
48
|
-
<%=
|
48
|
+
<%= class_name %>.create! valid_attributes
|
49
49
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
50
50
|
get :index, {}, valid_session
|
51
51
|
<% else -%>
|
52
52
|
get :index, params: {}, session: valid_session
|
53
53
|
<% end -%>
|
54
|
-
expect(response).to
|
54
|
+
expect(response).to be_successful
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -60,11 +60,11 @@ 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 -%>
|
67
|
-
expect(response).to
|
67
|
+
expect(response).to be_successful
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -75,7 +75,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
75
75
|
<% else -%>
|
76
76
|
get :new, params: {}, session: valid_session
|
77
77
|
<% end -%>
|
78
|
-
expect(response).to
|
78
|
+
expect(response).to be_successful
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -83,11 +83,11 @@ 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 -%>
|
90
|
-
expect(response).to
|
90
|
+
expect(response).to be_successful
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -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,11 +116,11 @@ 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 -%>
|
123
|
-
expect(response).to
|
123
|
+
expect(response).to be_successful
|
124
124
|
end
|
125
125
|
end
|
126
126
|
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,11 +157,11 @@ 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 -%>
|
164
|
-
expect(response).to
|
164
|
+
expect(response).to be_successful
|
165
165
|
end
|
166
166
|
end
|
167
167
|
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 -%>
|
@@ -3,47 +3,44 @@ require "rails_helper"
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
|
5
5
|
describe "routing" do
|
6
|
-
|
7
6
|
<% unless options[:singleton] -%>
|
8
7
|
it "routes to #index" do
|
9
|
-
expect(:
|
8
|
+
expect(get: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
|
10
9
|
end
|
11
10
|
|
12
11
|
<% end -%>
|
13
12
|
<% unless options[:api] -%>
|
14
13
|
it "routes to #new" do
|
15
|
-
expect(:
|
14
|
+
expect(get: "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
|
16
15
|
end
|
17
|
-
<% end -%>
|
18
16
|
|
17
|
+
<% end -%>
|
19
18
|
it "routes to #show" do
|
20
|
-
expect(:
|
19
|
+
expect(get: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", id: "1")
|
21
20
|
end
|
22
21
|
|
23
22
|
<% unless options[:api] -%>
|
24
23
|
it "routes to #edit" do
|
25
|
-
expect(:
|
24
|
+
expect(get: "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", id: "1")
|
26
25
|
end
|
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
|
-
|
47
44
|
end
|
48
45
|
end
|
49
46
|
<% 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
|
))
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
if ::Rails::VERSION::STRING >= '5.1'
|
4
|
+
module Rspec
|
5
|
+
module Generators
|
6
|
+
# @private
|
7
|
+
class SystemGenerator < Base
|
8
|
+
class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
|
9
|
+
|
10
|
+
def generate_system_spec
|
11
|
+
return unless options[:system_specs]
|
12
|
+
|
13
|
+
template template_name, File.join('spec/system', class_path, filename)
|
14
|
+
end
|
15
|
+
|
16
|
+
def template_name
|
17
|
+
'system_spec.rb'
|
18
|
+
end
|
19
|
+
|
20
|
+
def filename
|
21
|
+
"#{table_name}_spec.rb"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -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
|