rspec-rails 3.0.2 → 7.1.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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +3 -1
- data/Capybara.md +6 -55
- data/Changelog.md +805 -47
- data/{License.txt → LICENSE.md} +5 -3
- data/README.md +278 -444
- 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 +24 -7
- data/lib/generators/rspec/controller/templates/controller_spec.rb +3 -3
- 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 +1 -1
- data/lib/generators/rspec/feature/feature_generator.rb +15 -2
- data/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
- data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
- data/lib/generators/rspec/generator/generator_generator.rb +24 -0
- data/lib/generators/rspec/generator/templates/generator_spec.rb +5 -0
- data/lib/generators/rspec/helper/helper_generator.rb +2 -2
- data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +41 -7
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +63 -22
- data/lib/generators/rspec/job/job_generator.rb +13 -0
- data/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
- 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 +12 -3
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +13 -0
- data/lib/generators/rspec/model/model_generator.rb +20 -6
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
- data/lib/generators/rspec/request/request_generator.rb +17 -0
- data/lib/generators/rspec/request/templates/request_spec.rb +10 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +90 -113
- 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 +46 -64
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +11 -7
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +4 -3
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +4 -4
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +138 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +18 -11
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +3 -3
- data/lib/generators/rspec/system/system_generator.rb +24 -0
- data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
- data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
- data/lib/generators/rspec/view/view_generator.rb +4 -4
- data/lib/generators/rspec.rb +30 -11
- data/lib/rspec/rails/active_record.rb +25 -0
- data/lib/rspec/rails/adapters.rb +46 -29
- data/lib/rspec/rails/configuration.rb +165 -41
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +185 -149
- data/lib/rspec/rails/example/feature_example_group.rb +43 -23
- data/lib/rspec/rails/example/helper_example_group.rb +28 -25
- 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 +27 -22
- data/lib/rspec/rails/example/model_example_group.rb +9 -6
- data/lib/rspec/rails/example/rails_example_group.rb +9 -2
- data/lib/rspec/rails/example/request_example_group.rb +21 -17
- data/lib/rspec/rails/example/routing_example_group.rb +47 -39
- data/lib/rspec/rails/example/system_example_group.rb +180 -0
- data/lib/rspec/rails/example/view_example_group.rb +179 -134
- data/lib/rspec/rails/example.rb +4 -0
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -11
- data/lib/rspec/rails/feature_check.rb +51 -0
- data/lib/rspec/rails/file_fixture_support.rb +18 -0
- data/lib/rspec/rails/fixture_file_upload_support.rb +45 -0
- data/lib/rspec/rails/fixture_support.rb +70 -14
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +180 -0
- data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
- data/lib/rspec/rails/matchers/action_cable.rb +70 -0
- data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
- data/lib/rspec/rails/matchers/active_job.rb +526 -0
- data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +70 -64
- data/lib/rspec/rails/matchers/be_new_record.rb +25 -20
- data/lib/rspec/rails/matchers/be_valid.rb +39 -34
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +259 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +359 -333
- data/lib/rspec/rails/matchers/have_rendered.rb +55 -32
- data/lib/rspec/rails/matchers/redirect_to.rb +30 -27
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +107 -101
- data/lib/rspec/rails/matchers/send_email.rb +122 -0
- data/lib/rspec/rails/matchers.rb +21 -12
- data/lib/rspec/rails/tasks/rspec.rake +9 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -11
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +1 -20
- data/lib/rspec/rails/view_path_builder.rb +29 -0
- data/lib/rspec/rails/view_rendering.rb +89 -27
- data/lib/rspec/rails/view_spec_methods.rb +56 -0
- data/lib/rspec/rails.rb +9 -1
- data/lib/rspec-rails.rb +83 -3
- data.tar.gz.sig +0 -0
- metadata +108 -78
- metadata.gz.sig +3 -2
- data/lib/generators/rspec/integration/integration_generator.rb +0 -17
- data/lib/generators/rspec/integration/templates/request_spec.rb +0 -10
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -17,9 +17,14 @@ require 'rails_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
|
-
RSpec.describe <%= controller_class_name %>Controller,
|
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
|
@@ -38,123 +43,100 @@ RSpec.describe <%= controller_class_name %>Controller, :type => :controller do
|
|
38
43
|
let(:valid_session) { {} }
|
39
44
|
|
40
45
|
<% unless options[:singleton] -%>
|
41
|
-
describe "GET index" do
|
42
|
-
it "
|
43
|
-
<%=
|
44
|
-
get :index, {}, valid_session
|
45
|
-
expect(
|
46
|
+
describe "GET #index" do
|
47
|
+
it "returns a success response" do
|
48
|
+
<%= class_name %>.create! valid_attributes
|
49
|
+
get :index, params: {}, session: valid_session
|
50
|
+
expect(response).to be_successful
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
49
54
|
<% end -%>
|
50
|
-
describe "GET show" do
|
51
|
-
it "
|
55
|
+
describe "GET #show" do
|
56
|
+
it "returns a success response" do
|
52
57
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
53
|
-
get :show, {:
|
54
|
-
expect(
|
58
|
+
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
59
|
+
expect(response).to be_successful
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
58
|
-
describe "GET new" do
|
59
|
-
it "
|
60
|
-
get :new, {}, valid_session
|
61
|
-
expect(
|
63
|
+
describe "GET #new" do
|
64
|
+
it "returns a success response" do
|
65
|
+
get :new, params: {}, session: valid_session
|
66
|
+
expect(response).to be_successful
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
65
|
-
describe "GET edit" do
|
66
|
-
it "
|
70
|
+
describe "GET #edit" do
|
71
|
+
it "returns a success response" do
|
67
72
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
68
|
-
get :edit, {:
|
69
|
-
expect(
|
73
|
+
get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
|
74
|
+
expect(response).to be_successful
|
70
75
|
end
|
71
76
|
end
|
72
77
|
|
73
|
-
describe "POST create" do
|
74
|
-
|
78
|
+
describe "POST #create" do
|
79
|
+
context "with valid params" do
|
75
80
|
it "creates a new <%= class_name %>" do
|
76
81
|
expect {
|
77
|
-
post :create, {
|
82
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
78
83
|
}.to change(<%= class_name %>, :count).by(1)
|
79
84
|
end
|
80
85
|
|
81
|
-
it "
|
82
|
-
post :create, {
|
83
|
-
expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
|
84
|
-
expect(assigns(:<%= ns_file_name %>)).to be_persisted
|
85
|
-
end
|
86
|
-
|
87
|
-
it "redirects to the created <%= ns_file_name %>" do
|
88
|
-
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
86
|
+
it "redirects to the created <%= singular_table_name %>" do
|
87
|
+
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
|
89
88
|
expect(response).to redirect_to(<%= class_name %>.last)
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
|
-
|
94
|
-
it "
|
95
|
-
post :create, {
|
96
|
-
expect(
|
97
|
-
end
|
98
|
-
|
99
|
-
it "re-renders the 'new' template" do
|
100
|
-
post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
|
101
|
-
expect(response).to render_template("new")
|
92
|
+
context "with invalid params" do
|
93
|
+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
94
|
+
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
|
95
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
102
96
|
end
|
103
97
|
end
|
104
98
|
end
|
105
99
|
|
106
|
-
describe "PUT update" do
|
107
|
-
|
100
|
+
describe "PUT #update" do
|
101
|
+
context "with valid params" do
|
108
102
|
let(:new_attributes) {
|
109
103
|
skip("Add a hash of attributes valid for your model")
|
110
104
|
}
|
111
105
|
|
112
|
-
it "updates the requested <%=
|
106
|
+
it "updates the requested <%= singular_table_name %>" do
|
113
107
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
114
|
-
put :update, {:
|
108
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
115
109
|
<%= file_name %>.reload
|
116
110
|
skip("Add assertions for updated state")
|
117
111
|
end
|
118
112
|
|
119
|
-
it "
|
113
|
+
it "redirects to the <%= singular_table_name %>" do
|
120
114
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
121
|
-
put :update, {:
|
122
|
-
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "redirects to the <%= ns_file_name %>" do
|
126
|
-
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
127
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
115
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
|
128
116
|
expect(response).to redirect_to(<%= file_name %>)
|
129
117
|
end
|
130
118
|
end
|
131
119
|
|
132
|
-
|
133
|
-
it "
|
134
|
-
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
135
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
|
136
|
-
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "re-renders the 'edit' template" do
|
120
|
+
context "with invalid params" do
|
121
|
+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
140
122
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
141
|
-
put :update, {:
|
142
|
-
expect(response).to
|
123
|
+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
|
124
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
143
125
|
end
|
144
126
|
end
|
145
127
|
end
|
146
128
|
|
147
|
-
describe "DELETE destroy" do
|
148
|
-
it "destroys the requested <%=
|
129
|
+
describe "DELETE #destroy" do
|
130
|
+
it "destroys the requested <%= singular_table_name %>" do
|
149
131
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
150
132
|
expect {
|
151
|
-
delete :destroy, {:
|
133
|
+
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
152
134
|
}.to change(<%= class_name %>, :count).by(-1)
|
153
135
|
end
|
154
136
|
|
155
137
|
it "redirects to the <%= table_name %> list" do
|
156
138
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
157
|
-
delete :destroy, {:
|
139
|
+
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
158
140
|
expect(response).to redirect_to(<%= index_helper %>_url)
|
159
141
|
end
|
160
142
|
end
|
@@ -1,22 +1,26 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
RSpec.describe "<%= ns_table_name %>/edit",
|
5
|
-
|
6
|
-
|
4
|
+
RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
5
|
+
let(:<%= singular_table_name %>) {
|
6
|
+
<%= class_name %>.create!(<%= ')' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
|
-
|
8
|
+
<%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
10
|
-
<%=
|
10
|
+
<%= " )\n" unless output_attributes.empty? -%>
|
11
|
+
}
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
assign(:<%= singular_table_name %>, <%= singular_table_name %>)
|
11
15
|
end
|
12
16
|
|
13
17
|
it "renders the edit <%= ns_file_name %> form" do
|
14
18
|
render
|
15
19
|
|
16
|
-
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(
|
20
|
+
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(<%= singular_table_name %>), "post" do
|
17
21
|
<% for attribute in output_attributes -%>
|
18
22
|
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
19
|
-
assert_select "<%= attribute.input_type
|
23
|
+
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
20
24
|
<% end -%>
|
21
25
|
end
|
22
26
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
RSpec.describe "<%= ns_table_name %>/index",
|
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,8 +18,9 @@ RSpec.describe "<%= ns_table_name %>/index", :type => :view do
|
|
18
18
|
|
19
19
|
it "renders a list of <%= ns_table_name %>" do
|
20
20
|
render
|
21
|
+
cell_selector = 'div>p'
|
21
22
|
<% for attribute in output_attributes -%>
|
22
|
-
assert_select
|
23
|
+
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
|
23
24
|
<% end -%>
|
24
25
|
end
|
25
26
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
RSpec.describe "<%= ns_table_name %>/new",
|
4
|
+
RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
assign(:<%=
|
6
|
+
assign(:<%= singular_table_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
|
-
|
8
|
+
<%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
10
10
|
<%= !output_attributes.empty? ? " ))\n end" : " end" %>
|
11
11
|
|
@@ -15,7 +15,7 @@ RSpec.describe "<%= ns_table_name %>/new", :type => :view do
|
|
15
15
|
assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
|
16
16
|
<% for attribute in output_attributes -%>
|
17
17
|
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
|
18
|
-
assert_select "<%= attribute.input_type
|
18
|
+
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
19
19
|
<% end -%>
|
20
20
|
end
|
21
21
|
end
|
@@ -0,0 +1,138 @@
|
|
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
|
+
# This should return the minimal set of attributes required to create a valid
|
22
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
23
|
+
# adjust the attributes here as well.
|
24
|
+
let(:valid_attributes) {
|
25
|
+
skip("Add a hash of attributes valid for your model")
|
26
|
+
}
|
27
|
+
|
28
|
+
let(:invalid_attributes) {
|
29
|
+
skip("Add a hash of attributes invalid for your model")
|
30
|
+
}
|
31
|
+
|
32
|
+
<% unless options[:singleton] -%>
|
33
|
+
describe "GET /index" do
|
34
|
+
it "renders a successful response" do
|
35
|
+
<%= class_name %>.create! valid_attributes
|
36
|
+
get <%= index_helper %>_url
|
37
|
+
expect(response).to be_successful
|
38
|
+
end
|
39
|
+
end
|
40
|
+
<% end -%>
|
41
|
+
|
42
|
+
describe "GET /show" do
|
43
|
+
it "renders a successful response" do
|
44
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
45
|
+
get <%= show_helper %>
|
46
|
+
expect(response).to be_successful
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "GET /new" do
|
51
|
+
it "renders a successful response" do
|
52
|
+
get <%= new_helper %>
|
53
|
+
expect(response).to be_successful
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "GET /edit" do
|
58
|
+
it "renders a successful response" do
|
59
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
60
|
+
get <%= edit_helper %>
|
61
|
+
expect(response).to be_successful
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "POST /create" do
|
66
|
+
context "with valid parameters" do
|
67
|
+
it "creates a new <%= class_name %>" do
|
68
|
+
expect {
|
69
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
|
70
|
+
}.to change(<%= class_name %>, :count).by(1)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "redirects to the created <%= singular_table_name %>" do
|
74
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
|
75
|
+
expect(response).to redirect_to(<%= show_helper(class_name+".last") %>)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with invalid parameters" do
|
80
|
+
it "does not create a new <%= class_name %>" do
|
81
|
+
expect {
|
82
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
83
|
+
}.to change(<%= class_name %>, :count).by(0)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
|
87
|
+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
|
88
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "PATCH /update" do
|
94
|
+
context "with valid parameters" do
|
95
|
+
let(:new_attributes) {
|
96
|
+
skip("Add a hash of attributes valid for your model")
|
97
|
+
}
|
98
|
+
|
99
|
+
it "updates the requested <%= singular_table_name %>" do
|
100
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
101
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
|
102
|
+
<%= file_name %>.reload
|
103
|
+
skip("Add assertions for updated state")
|
104
|
+
end
|
105
|
+
|
106
|
+
it "redirects to the <%= singular_table_name %>" do
|
107
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
108
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
|
109
|
+
<%= file_name %>.reload
|
110
|
+
expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "with invalid parameters" do
|
115
|
+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
|
116
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
117
|
+
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
|
118
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "DELETE /destroy" do
|
124
|
+
it "destroys the requested <%= singular_table_name %>" do
|
125
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
126
|
+
expect {
|
127
|
+
delete <%= show_helper %>
|
128
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "redirects to the <%= table_name %> list" do
|
132
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
133
|
+
delete <%= show_helper %>
|
134
|
+
expect(response).to redirect_to(<%= index_helper %>_url)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
<% end -%>
|
@@ -1,39 +1,46 @@
|
|
1
1
|
require "rails_helper"
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
RSpec.describe <%= controller_class_name %>Controller,
|
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 -%>
|
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
|
+
<% end -%>
|
17
18
|
it "routes to #show" do
|
18
|
-
expect(:
|
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
|
-
expect(:
|
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
|
-
expect(:
|
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
|
-
expect(:
|
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
|
-
expect(:
|
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
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
RSpec.describe "<%= ns_table_name %>/show",
|
4
|
+
RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
|
5
5
|
before(:each) do
|
6
|
-
|
6
|
+
assign(:<%= singular_table_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
|
-
|
8
|
+
<%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
9
|
<% end -%>
|
10
10
|
<% if !output_attributes.empty? -%>
|
11
11
|
))
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
# @private
|
6
|
+
class SystemGenerator < Base
|
7
|
+
class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
|
8
|
+
|
9
|
+
def generate_system_spec
|
10
|
+
return unless options[:system_specs]
|
11
|
+
|
12
|
+
template template_name, target_path('system', class_path, filename)
|
13
|
+
end
|
14
|
+
|
15
|
+
def template_name
|
16
|
+
'system_spec.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
def filename
|
20
|
+
"#{table_name}_spec.rb"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -4,17 +4,17 @@ 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
|
-
empty_directory
|
12
|
+
empty_directory target_path("views", file_path)
|
13
13
|
|
14
14
|
actions.each do |action|
|
15
15
|
@action = action
|
16
16
|
template 'view_spec.rb',
|
17
|
-
|
17
|
+
target_path("views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/generators/rspec.rb
CHANGED
@@ -1,21 +1,40 @@
|
|
1
1
|
require 'rails/generators/named_base'
|
2
|
+
require 'rspec/core'
|
3
|
+
require 'rspec/rails/feature_check'
|
2
4
|
|
3
|
-
#
|
5
|
+
# @private
|
6
|
+
# Weirdly named generators namespace (should be `RSpec`) for compatibility with
|
4
7
|
# rails loading.
|
5
8
|
module Rspec
|
6
9
|
# @private
|
7
10
|
module Generators
|
8
11
|
# @private
|
9
12
|
class Base < ::Rails::Generators::NamedBase
|
10
|
-
|
11
|
-
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
12
|
-
end
|
13
|
+
include RSpec::Rails::FeatureCheck
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def self.source_root(path = nil)
|
16
|
+
if path
|
17
|
+
@_rspec_source_root = path
|
18
|
+
else
|
19
|
+
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
17
20
|
end
|
18
21
|
end
|
22
|
+
|
23
|
+
# @private
|
24
|
+
# Load configuration from RSpec to ensure `--default-path` is set
|
25
|
+
def self.configuration
|
26
|
+
@configuration ||=
|
27
|
+
begin
|
28
|
+
configuration = RSpec.configuration
|
29
|
+
options = RSpec::Core::ConfigurationOptions.new({})
|
30
|
+
options.configure(configuration)
|
31
|
+
configuration
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def target_path(*paths)
|
36
|
+
File.join(self.class.configuration.default_path, *paths)
|
37
|
+
end
|
19
38
|
end
|
20
39
|
end
|
21
40
|
end
|
@@ -27,10 +46,10 @@ module Rails
|
|
27
46
|
class GeneratedAttribute
|
28
47
|
def input_type
|
29
48
|
@input_type ||= if type == :text
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
49
|
+
"textarea"
|
50
|
+
else
|
51
|
+
"input"
|
52
|
+
end
|
34
53
|
end
|
35
54
|
end
|
36
55
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# Fake class to document RSpec ActiveRecord configuration options. In practice,
|
4
|
+
# these are dynamically added to the normal RSpec configuration object.
|
5
|
+
class ActiveRecordConfiguration
|
6
|
+
# @private
|
7
|
+
def self.initialize_activerecord_configuration(config)
|
8
|
+
config.before :suite do
|
9
|
+
# This allows dynamic columns etc to be used on ActiveRecord models when creating instance_doubles
|
10
|
+
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && defined?(::RSpec::Mocks) && (::RSpec::Mocks.respond_to?(:configuration))
|
11
|
+
::RSpec::Mocks.configuration.when_declaring_verifying_double do |possible_model|
|
12
|
+
target = possible_model.target
|
13
|
+
|
14
|
+
if Class === target && ActiveRecord::Base > target && !target.abstract_class?
|
15
|
+
target.define_attribute_methods
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
initialize_activerecord_configuration RSpec.configuration
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|