rspec-rails 2.14.2 → 4.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +4 -2
- data/Capybara.md +6 -57
- data/Changelog.md +715 -37
- data/{License.txt → LICENSE.md} +5 -2
- data/README.md +287 -362
- data/lib/generators/rspec/channel/channel_generator.rb +12 -0
- data/lib/generators/rspec/channel/templates/channel_spec.rb.erb +7 -0
- data/lib/generators/rspec/controller/controller_generator.rb +23 -5
- data/lib/generators/rspec/controller/templates/controller_spec.rb +5 -5
- data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
- data/lib/generators/rspec/controller/templates/view_spec.rb +2 -2
- data/lib/generators/rspec/feature/feature_generator.rb +29 -0
- data/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
- data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
- 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 +2 -1
- data/lib/generators/rspec/helper/templates/helper_spec.rb +2 -2
- data/lib/generators/rspec/install/install_generator.rb +44 -5
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +79 -0
- data/lib/generators/rspec/integration/integration_generator.rb +8 -13
- data/lib/generators/rspec/integration/templates/request_spec.rb +4 -9
- data/lib/generators/rspec/job/job_generator.rb +12 -0
- data/lib/generators/rspec/{observer/templates/observer_spec.rb → job/templates/job_spec.rb.erb} +2 -2
- 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 +9 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +7 -7
- data/lib/generators/rspec/mailer/templates/preview.rb +13 -0
- data/lib/generators/rspec/model/model_generator.rb +21 -6
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/model/templates/model_spec.rb +2 -2
- data/lib/generators/rspec/request/request_generator.rb +10 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +88 -148
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +129 -0
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +105 -80
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +10 -14
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +5 -12
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +11 -15
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +137 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +19 -12
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +5 -12
- 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/templates/view_spec.rb +2 -2
- data/lib/generators/rspec/view/view_generator.rb +3 -2
- data/lib/generators/rspec.rb +18 -10
- data/lib/rspec/rails/active_record.rb +25 -0
- data/lib/rspec/rails/adapters.rb +49 -47
- data/lib/rspec/rails/configuration.rb +194 -0
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +188 -138
- data/lib/rspec/rails/example/feature_example_group.rb +43 -20
- data/lib/rspec/rails/example/helper_example_group.rb +28 -26
- data/lib/rspec/rails/example/job_example_group.rb +23 -0
- data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +30 -14
- data/lib/rspec/rails/example/model_example_group.rb +8 -7
- data/lib/rspec/rails/example/rails_example_group.rb +4 -2
- data/lib/rspec/rails/example/request_example_group.rb +23 -16
- data/lib/rspec/rails/example/routing_example_group.rb +49 -40
- data/lib/rspec/rails/example/system_example_group.rb +125 -0
- data/lib/rspec/rails/example/view_example_group.rb +178 -134
- data/lib/rspec/rails/example.rb +4 -33
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -11
- data/lib/rspec/rails/extensions.rb +0 -1
- data/lib/rspec/rails/feature_check.rb +47 -0
- data/lib/rspec/rails/file_fixture_support.rb +17 -0
- data/lib/rspec/rails/fixture_file_upload_support.rb +35 -0
- data/lib/rspec/rails/fixture_support.rb +54 -23
- 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 +465 -0
- data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +69 -62
- data/lib/rspec/rails/matchers/be_new_record.rb +24 -21
- data/lib/rspec/rails/matchers/be_valid.rb +42 -33
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +198 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +385 -0
- data/lib/rspec/rails/matchers/have_rendered.rb +55 -31
- data/lib/rspec/rails/matchers/redirect_to.rb +30 -29
- data/lib/rspec/rails/matchers/relation_match_array.rb +2 -2
- data/lib/rspec/rails/matchers/routing_matchers.rb +107 -93
- data/lib/rspec/rails/matchers.rb +22 -14
- data/lib/rspec/rails/tasks/rspec.rake +8 -18
- data/lib/rspec/rails/vendor/capybara.rb +12 -11
- data/lib/rspec/rails/version.rb +3 -1
- data/lib/rspec/rails/view_assigns.rb +18 -18
- data/lib/rspec/rails/view_path_builder.rb +29 -0
- data/lib/rspec/rails/view_rendering.rb +100 -63
- data/lib/rspec/rails/view_spec_methods.rb +56 -0
- data/lib/rspec/rails.rb +10 -10
- data/lib/rspec-rails.rb +67 -3
- data.tar.gz.sig +0 -0
- metadata +121 -94
- metadata.gz.sig +0 -0
- data/lib/autotest/rails_rspec2.rb +0 -85
- data/lib/generators/rspec/install/templates/.rspec +0 -1
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +0 -49
- data/lib/generators/rspec/observer/observer_generator.rb +0 -12
- data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
- data/lib/rspec/rails/matchers/have_extension.rb +0 -36
- data/lib/rspec/rails/mocks.rb +0 -274
- data/lib/rspec/rails/module_inclusion.rb +0 -19
- data/lib/rspec/rails/vendor/webrat.rb +0 -33
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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 specify the controller code that
|
@@ -17,14 +17,25 @@ require 'spec_helper'
|
|
17
17
|
# is no simpler way to get a handle on the object needed for the example.
|
18
18
|
# Message expectations are only used when there is no simpler way to specify
|
19
19
|
# that an instance is receiving a specific message.
|
20
|
+
#
|
21
|
+
# Also compared to earlier versions of this generator, there are no longer any
|
22
|
+
# expectations of assigns and templates rendered. These features have been
|
23
|
+
# removed from Rails core in Rails 5, but can be added back in via the
|
24
|
+
# `rails-controller-testing` gem.
|
20
25
|
|
21
26
|
<% module_namespacing do -%>
|
22
|
-
describe <%= controller_class_name %>Controller do
|
27
|
+
RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:controller) %> do
|
23
28
|
|
24
29
|
# This should return the minimal set of attributes required to create a valid
|
25
30
|
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
26
31
|
# adjust the attributes here as well.
|
27
|
-
let(:valid_attributes) {
|
32
|
+
let(:valid_attributes) {
|
33
|
+
skip("Add a hash of attributes valid for your model")
|
34
|
+
}
|
35
|
+
|
36
|
+
let(:invalid_attributes) {
|
37
|
+
skip("Add a hash of attributes invalid for your model")
|
38
|
+
}
|
28
39
|
|
29
40
|
# This should return the minimal set of values that should be in the session
|
30
41
|
# in order to pass any filters (e.g. authentication) defined in
|
@@ -32,135 +43,149 @@ describe <%= controller_class_name %>Controller do
|
|
32
43
|
let(:valid_session) { {} }
|
33
44
|
|
34
45
|
<% unless options[:singleton] -%>
|
35
|
-
describe "GET index" do
|
36
|
-
it "
|
37
|
-
<%=
|
46
|
+
describe "GET #index" do
|
47
|
+
it "returns a success response" do
|
48
|
+
<%= class_name %>.create! valid_attributes
|
49
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
38
50
|
get :index, {}, valid_session
|
39
|
-
|
51
|
+
<% else -%>
|
52
|
+
get :index, params: {}, session: valid_session
|
53
|
+
<% end -%>
|
54
|
+
expect(response).to be_successful
|
40
55
|
end
|
41
56
|
end
|
42
57
|
|
43
58
|
<% end -%>
|
44
|
-
describe "GET show" do
|
45
|
-
it "
|
59
|
+
describe "GET #show" do
|
60
|
+
it "returns a success response" do
|
46
61
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
47
|
-
|
48
|
-
|
62
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
63
|
+
get :show, {id: <%= file_name %>.to_param}, valid_session
|
64
|
+
<% else -%>
|
65
|
+
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
66
|
+
<% end -%>
|
67
|
+
expect(response).to be_successful
|
49
68
|
end
|
50
69
|
end
|
51
70
|
|
52
|
-
describe "GET new" do
|
53
|
-
it "
|
71
|
+
describe "GET #new" do
|
72
|
+
it "returns a success response" do
|
73
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
54
74
|
get :new, {}, valid_session
|
55
|
-
|
75
|
+
<% else -%>
|
76
|
+
get :new, params: {}, session: valid_session
|
77
|
+
<% end -%>
|
78
|
+
expect(response).to be_successful
|
56
79
|
end
|
57
80
|
end
|
58
81
|
|
59
|
-
describe "GET edit" do
|
60
|
-
it "
|
82
|
+
describe "GET #edit" do
|
83
|
+
it "returns a success response" do
|
61
84
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
62
|
-
|
63
|
-
|
85
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
86
|
+
get :edit, {id: <%= file_name %>.to_param}, valid_session
|
87
|
+
<% else -%>
|
88
|
+
get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
|
89
|
+
<% end -%>
|
90
|
+
expect(response).to be_successful
|
64
91
|
end
|
65
92
|
end
|
66
93
|
|
67
|
-
describe "POST create" do
|
68
|
-
|
94
|
+
describe "POST #create" do
|
95
|
+
context "with valid params" do
|
69
96
|
it "creates a new <%= class_name %>" do
|
70
97
|
expect {
|
71
|
-
|
98
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
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 -%>
|
72
103
|
}.to change(<%= class_name %>, :count).by(1)
|
73
104
|
end
|
74
105
|
|
75
|
-
it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
|
76
|
-
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
77
|
-
assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
|
78
|
-
assigns(:<%= ns_file_name %>).should be_persisted
|
79
|
-
end
|
80
|
-
|
81
106
|
it "redirects to the created <%= ns_file_name %>" do
|
82
|
-
|
83
|
-
|
107
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
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 -%>
|
112
|
+
expect(response).to redirect_to(<%= class_name %>.last)
|
84
113
|
end
|
85
114
|
end
|
86
115
|
|
87
|
-
|
88
|
-
it "
|
89
|
-
|
90
|
-
<%=
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
it "re-renders the 'new' template" do
|
96
|
-
# Trigger the behavior that occurs when invalid params are submitted
|
97
|
-
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
98
|
-
post :create, {:<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
99
|
-
response.should render_template("new")
|
116
|
+
context "with invalid params" do
|
117
|
+
it "returns a success response (i.e. to display the 'new' template)" do
|
118
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
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 -%>
|
123
|
+
expect(response).to be_successful
|
100
124
|
end
|
101
125
|
end
|
102
126
|
end
|
103
127
|
|
104
|
-
describe "PUT update" do
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# specifies that the <%= class_name %> created on the previous line
|
110
|
-
# receives the :update_attributes message with whatever params are
|
111
|
-
# submitted in the request.
|
112
|
-
<%- if ::Rails::VERSION::STRING >= '4' -%>
|
113
|
-
<%= class_name %>.any_instance.should_receive(:update).with(<%= formatted_hash(example_params_for_update) %>)
|
114
|
-
<%- else -%>
|
115
|
-
<%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= formatted_hash(example_params_for_update) %>)
|
116
|
-
<%- end -%>
|
117
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_params_for_update) %>}, valid_session
|
118
|
-
end
|
128
|
+
describe "PUT #update" do
|
129
|
+
context "with valid params" do
|
130
|
+
let(:new_attributes) {
|
131
|
+
skip("Add a hash of attributes valid for your model")
|
132
|
+
}
|
119
133
|
|
120
|
-
it "
|
134
|
+
it "updates the requested <%= ns_file_name %>" do
|
121
135
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
122
|
-
|
123
|
-
|
136
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
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 -%>
|
141
|
+
<%= file_name %>.reload
|
142
|
+
skip("Add assertions for updated state")
|
124
143
|
end
|
125
144
|
|
126
145
|
it "redirects to the <%= ns_file_name %>" do
|
127
146
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
128
|
-
|
129
|
-
|
147
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
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 -%>
|
152
|
+
expect(response).to redirect_to(<%= file_name %>)
|
130
153
|
end
|
131
154
|
end
|
132
155
|
|
133
|
-
|
134
|
-
it "
|
156
|
+
context "with invalid params" do
|
157
|
+
it "returns a success response (i.e. to display the 'edit' template)" do
|
135
158
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
136
|
-
|
137
|
-
<%=
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
it "re-renders the 'edit' template" do
|
143
|
-
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
144
|
-
# Trigger the behavior that occurs when invalid params are submitted
|
145
|
-
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
146
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
147
|
-
response.should render_template("edit")
|
159
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
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 -%>
|
164
|
+
expect(response).to be_successful
|
148
165
|
end
|
149
166
|
end
|
150
167
|
end
|
151
168
|
|
152
|
-
describe "DELETE destroy" do
|
169
|
+
describe "DELETE #destroy" do
|
153
170
|
it "destroys the requested <%= ns_file_name %>" do
|
154
171
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
155
172
|
expect {
|
156
|
-
|
173
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
174
|
+
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
|
175
|
+
<% else -%>
|
176
|
+
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
177
|
+
<% end -%>
|
157
178
|
}.to change(<%= class_name %>, :count).by(-1)
|
158
179
|
end
|
159
180
|
|
160
181
|
it "redirects to the <%= table_name %> list" do
|
161
182
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
162
|
-
|
163
|
-
|
183
|
+
<% if Rails::VERSION::STRING < '5.0' -%>
|
184
|
+
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
|
185
|
+
<% else -%>
|
186
|
+
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
187
|
+
<% end -%>
|
188
|
+
expect(response).to redirect_to(<%= index_helper %>_url)
|
164
189
|
end
|
165
190
|
end
|
166
191
|
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/edit" do
|
4
|
+
RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
@<%= ns_file_name %> = assign(:<%= ns_file_name %>,
|
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
|
@@ -13,19 +13,15 @@ describe "<%= ns_table_name %>/edit" do
|
|
13
13
|
it "renders the edit <%= ns_file_name %> form" do
|
14
14
|
render
|
15
15
|
|
16
|
-
<% if webrat? -%>
|
17
|
-
rendered.should have_selector("form", :action => <%= ns_file_name %>_path(@<%= ns_file_name %>), :method => "post") do |form|
|
18
|
-
<% for attribute in output_attributes -%>
|
19
|
-
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
20
|
-
<% end -%>
|
21
|
-
end
|
22
|
-
<% else -%>
|
23
|
-
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
24
16
|
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
|
25
17
|
<% for attribute in output_attributes -%>
|
26
|
-
|
18
|
+
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
19
|
+
<% if Rails.version.to_f >= 5.1 -%>
|
20
|
+
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 %>]"
|
27
23
|
<% end -%>
|
28
|
-
end
|
29
24
|
<% end -%>
|
25
|
+
end
|
30
26
|
end
|
31
27
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/index" do
|
4
|
+
RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
6
|
assign(:<%= table_name %>, [
|
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 ? ')' : '),' %>
|
@@ -18,15 +18,8 @@ describe "<%= ns_table_name %>/index" do
|
|
18
18
|
|
19
19
|
it "renders a list of <%= ns_table_name %>" do
|
20
20
|
render
|
21
|
-
<% unless webrat? -%>
|
22
|
-
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
23
|
-
<% end -%>
|
24
21
|
<% for attribute in output_attributes -%>
|
25
|
-
|
26
|
-
rendered.should have_selector("tr>td", :content => <%= value_for(attribute) %>.to_s, :count => 2)
|
27
|
-
<% else -%>
|
28
|
-
assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2
|
29
|
-
<% end -%>
|
22
|
+
assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 2
|
30
23
|
<% end -%>
|
31
24
|
end
|
32
25
|
end
|
@@ -1,30 +1,26 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/new" do
|
4
|
+
RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
assign(:<%= ns_file_name %>,
|
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
|
-
<%= !output_attributes.empty? ? " )
|
10
|
+
<%= !output_attributes.empty? ? " ))\n end" : " end" %>
|
11
11
|
|
12
12
|
it "renders new <%= ns_file_name %> form" do
|
13
13
|
render
|
14
14
|
|
15
|
-
<% if webrat? -%>
|
16
|
-
rendered.should have_selector("form", :action => <%= table_name %>_path, :method => "post") do |form|
|
17
|
-
<% for attribute in output_attributes -%>
|
18
|
-
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
19
|
-
<% end -%>
|
20
|
-
end
|
21
|
-
<% else -%>
|
22
|
-
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
23
15
|
assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
|
24
16
|
<% for attribute in output_attributes -%>
|
25
|
-
|
17
|
+
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
18
|
+
<% if Rails.version.to_f >= 5.1 -%>
|
19
|
+
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 %>]"
|
26
22
|
<% end -%>
|
27
|
-
end
|
28
23
|
<% end -%>
|
24
|
+
end
|
29
25
|
end
|
30
26
|
end
|
@@ -0,0 +1,137 @@
|
|
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
|
+
<% if mountable_engine? -%>
|
18
|
+
include Engine.routes.url_helpers
|
19
|
+
<% end -%>
|
20
|
+
|
21
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
22
|
+
# adjust the attributes here as well.
|
23
|
+
let(:valid_attributes) {
|
24
|
+
skip("Add a hash of attributes valid for your model")
|
25
|
+
}
|
26
|
+
|
27
|
+
let(:invalid_attributes) {
|
28
|
+
skip("Add a hash of attributes invalid for your model")
|
29
|
+
}
|
30
|
+
|
31
|
+
<% unless options[:singleton] -%>
|
32
|
+
describe "GET /index" do
|
33
|
+
it "renders a successful response" do
|
34
|
+
<%= class_name %>.create! valid_attributes
|
35
|
+
get <%= index_helper %>_url
|
36
|
+
expect(response).to be_successful
|
37
|
+
end
|
38
|
+
end
|
39
|
+
<% end -%>
|
40
|
+
|
41
|
+
describe "GET /show" do
|
42
|
+
it "renders a successful response" do
|
43
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
44
|
+
get <%= show_helper.tr('@', '') %>
|
45
|
+
expect(response).to be_successful
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "GET /new" do
|
50
|
+
it "renders a successful response" do
|
51
|
+
get <%= new_helper %>
|
52
|
+
expect(response).to be_successful
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "GET /edit" do
|
57
|
+
it "render a successful response" do
|
58
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
59
|
+
get <%= edit_helper.tr('@','') %>
|
60
|
+
expect(response).to be_successful
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "POST /create" do
|
65
|
+
context "with valid parameters" do
|
66
|
+
it "creates a new <%= class_name %>" do
|
67
|
+
expect {
|
68
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
|
69
|
+
}.to change(<%= class_name %>, :count).by(1)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "redirects to the created <%= ns_file_name %>" do
|
73
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
|
74
|
+
expect(response).to redirect_to(<%= show_helper.gsub("\@#{file_name}", class_name+".last") %>)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "with invalid parameters" do
|
79
|
+
it "does not create a new <%= class_name %>" do
|
80
|
+
expect {
|
81
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
|
82
|
+
}.to change(<%= class_name %>, :count).by(0)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "renders a successful response (i.e. to display the 'new' template)" do
|
86
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
|
87
|
+
expect(response).to be_successful
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "PATCH /update" do
|
93
|
+
context "with valid parameters" do
|
94
|
+
let(:new_attributes) {
|
95
|
+
skip("Add a hash of attributes valid for your model")
|
96
|
+
}
|
97
|
+
|
98
|
+
it "updates the requested <%= ns_file_name %>" do
|
99
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
100
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
|
101
|
+
<%= file_name %>.reload
|
102
|
+
skip("Add assertions for updated state")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "redirects to the <%= ns_file_name %>" do
|
106
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
107
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: new_attributes }
|
108
|
+
<%= file_name %>.reload
|
109
|
+
expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "with invalid parameters" do
|
114
|
+
it "renders a successful response (i.e. to display the 'edit' template)" do
|
115
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
116
|
+
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: invalid_attributes }
|
117
|
+
expect(response).to be_successful
|
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('@', '') %>
|
127
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "redirects to the <%= table_name %> list" do
|
131
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
132
|
+
delete <%= show_helper.tr('@', '') %>
|
133
|
+
expect(response).to redirect_to(<%= index_helper %>_url)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
<% end -%>
|
@@ -1,39 +1,46 @@
|
|
1
|
-
require "
|
1
|
+
require "rails_helper"
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
describe <%= controller_class_name %>Controller do
|
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
|
-
get
|
8
|
+
expect(get: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
|
10
9
|
end
|
11
10
|
|
12
11
|
<% end -%>
|
12
|
+
<% unless options[:api] -%>
|
13
13
|
it "routes to #new" do
|
14
|
-
get
|
14
|
+
expect(get: "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
|
15
15
|
end
|
16
16
|
|
17
|
+
<% end -%>
|
17
18
|
it "routes to #show" do
|
18
|
-
get
|
19
|
+
expect(get: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", id: "1")
|
19
20
|
end
|
20
21
|
|
22
|
+
<% unless options[:api] -%>
|
21
23
|
it "routes to #edit" do
|
22
|
-
get
|
24
|
+
expect(get: "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", id: "1")
|
23
25
|
end
|
24
26
|
|
27
|
+
<% end -%>
|
28
|
+
|
25
29
|
it "routes to #create" do
|
26
|
-
post
|
30
|
+
expect(post: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
|
27
31
|
end
|
28
32
|
|
29
|
-
it "routes to #update" do
|
30
|
-
put
|
33
|
+
it "routes to #update via PUT" do
|
34
|
+
expect(put: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
|
31
35
|
end
|
32
36
|
|
33
|
-
it "routes to #
|
34
|
-
|
37
|
+
it "routes to #update via PATCH" do
|
38
|
+
expect(patch: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
|
35
39
|
end
|
36
40
|
|
41
|
+
it "routes to #destroy" do
|
42
|
+
expect(delete: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", id: "1")
|
43
|
+
end
|
37
44
|
end
|
38
45
|
end
|
39
46
|
<% end -%>
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/show" do
|
4
|
+
RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
@<%= ns_file_name %> = assign(:<%= ns_file_name %>,
|
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
|
))
|
@@ -14,15 +14,8 @@ describe "<%= ns_table_name %>/show" do
|
|
14
14
|
|
15
15
|
it "renders attributes in <p>" do
|
16
16
|
render
|
17
|
-
<% unless webrat? -%>
|
18
|
-
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
19
|
-
<% end -%>
|
20
17
|
<% for attribute in output_attributes -%>
|
21
|
-
|
22
|
-
rendered.should contain(<%= value_for(attribute) %>.to_s)
|
23
|
-
<% else -%>
|
24
|
-
rendered.should match(/<%= eval(value_for(attribute)) %>/)
|
25
|
-
<% end -%>
|
18
|
+
expect(rendered).to match(/<%= raw_value_for(attribute) %>/)
|
26
19
|
<% end -%>
|
27
20
|
end
|
28
21
|
end
|
@@ -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
|