rspec-rails 2.99.0 → 3.1.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 +6 -14
- checksums.yaml.gz.sig +1 -0
- data/.yardopts +1 -1
- data/Capybara.md +1 -3
- data/Changelog.md +148 -11
- data/License.txt +1 -0
- data/README.md +202 -105
- data/lib/generators/rspec/controller/controller_generator.rb +1 -0
- data/lib/generators/rspec/controller/templates/controller_spec.rb +5 -5
- data/lib/generators/rspec/controller/templates/view_spec.rb +2 -2
- data/lib/generators/rspec/feature/feature_generator.rb +16 -0
- data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
- data/lib/generators/rspec/helper/helper_generator.rb +1 -0
- 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/{spec_helper.rb.tt → rails_helper.rb} +19 -28
- data/lib/generators/rspec/integration/integration_generator.rb +1 -12
- data/lib/generators/rspec/integration/templates/request_spec.rb +3 -8
- data/lib/generators/rspec/job/job_generator.rb +12 -0
- data/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +1 -0
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +6 -6
- data/lib/generators/rspec/model/model_generator.rb +19 -5
- 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/observer/observer_generator.rb +1 -0
- data/lib/generators/rspec/observer/templates/observer_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +108 -135
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +34 -39
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +5 -13
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -10
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +6 -14
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +9 -9
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +4 -11
- data/lib/generators/rspec/view/templates/view_spec.rb +2 -2
- data/lib/generators/rspec/view/view_generator.rb +1 -0
- data/lib/generators/rspec.rb +16 -6
- data/lib/rspec/rails/adapters.rb +33 -35
- data/lib/rspec/rails/configuration.rb +97 -0
- data/lib/rspec/rails/example/controller_example_group.rb +173 -159
- data/lib/rspec/rails/example/feature_example_group.rb +25 -20
- data/lib/rspec/rails/example/helper_example_group.rb +27 -26
- data/lib/rspec/rails/example/mailer_example_group.rb +29 -14
- data/lib/rspec/rails/example/model_example_group.rb +7 -7
- data/lib/rspec/rails/example/rails_example_group.rb +1 -0
- data/lib/rspec/rails/example/request_example_group.rb +19 -17
- data/lib/rspec/rails/example/routing_example_group.rb +40 -39
- data/lib/rspec/rails/example/view_example_group.rb +140 -137
- data/lib/rspec/rails/example.rb +0 -33
- data/lib/rspec/rails/extensions/active_record/proxy.rb +0 -1
- data/lib/rspec/rails/extensions.rb +0 -1
- data/lib/rspec/rails/feature_check.rb +35 -0
- data/lib/rspec/rails/fixture_support.rb +5 -12
- data/lib/rspec/rails/matchers/be_a_new.rb +67 -62
- data/lib/rspec/rails/matchers/be_new_record.rb +23 -21
- data/lib/rspec/rails/matchers/be_valid.rb +41 -33
- data/lib/rspec/rails/matchers/have_http_status.rb +361 -0
- data/lib/rspec/rails/matchers/have_rendered.rb +35 -31
- data/lib/rspec/rails/matchers/redirect_to.rb +30 -29
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +104 -94
- data/lib/rspec/rails/matchers.rb +7 -4
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/vendor/capybara.rb +2 -33
- data/lib/rspec/rails/version.rb +3 -1
- data/lib/rspec/rails/view_assigns.rb +18 -18
- data/lib/rspec/rails/view_rendering.rb +20 -45
- data/lib/rspec/rails.rb +2 -13
- data/lib/rspec-rails.rb +4 -1
- data.tar.gz.sig +0 -0
- metadata +80 -99
- metadata.gz.sig +3 -0
- data/lib/autotest/rails_rspec2.rb +0 -91
- data/lib/generators/rspec/install/templates/.rspec +0 -1
- data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
- data/lib/rspec/rails/infer_type_configuration.rb +0 -26
- data/lib/rspec/rails/matchers/have_extension.rb +0 -36
- data/lib/rspec/rails/mocks.rb +0 -284
- 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
|
|
@@ -19,12 +19,18 @@ require 'spec_helper'
|
|
|
19
19
|
# that an instance is receiving a specific message.
|
|
20
20
|
|
|
21
21
|
<% module_namespacing do -%>
|
|
22
|
-
describe <%= controller_class_name %>Controller do
|
|
22
|
+
RSpec.describe <%= controller_class_name %>Controller, :type => :controller do
|
|
23
23
|
|
|
24
24
|
# This should return the minimal set of attributes required to create a valid
|
|
25
25
|
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
|
26
26
|
# adjust the attributes here as well.
|
|
27
|
-
let(:valid_attributes) {
|
|
27
|
+
let(:valid_attributes) {
|
|
28
|
+
skip("Add a hash of attributes valid for your model")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let(:invalid_attributes) {
|
|
32
|
+
skip("Add a hash of attributes invalid for your model")
|
|
33
|
+
}
|
|
28
34
|
|
|
29
35
|
# This should return the minimal set of values that should be in the session
|
|
30
36
|
# in order to pass any filters (e.g. authentication) defined in
|
|
@@ -36,7 +42,7 @@ describe <%= controller_class_name %>Controller do
|
|
|
36
42
|
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
|
37
43
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
38
44
|
get :index, {}, valid_session
|
|
39
|
-
assigns(:<%= table_name %>).
|
|
45
|
+
expect(assigns(:<%= table_name %>)).to eq([<%= file_name %>])
|
|
40
46
|
end
|
|
41
47
|
end
|
|
42
48
|
|
|
@@ -45,14 +51,14 @@ describe <%= controller_class_name %>Controller do
|
|
|
45
51
|
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
46
52
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
47
53
|
get :show, {:id => <%= file_name %>.to_param}, valid_session
|
|
48
|
-
assigns(:<%= ns_file_name %>).
|
|
54
|
+
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
|
49
55
|
end
|
|
50
56
|
end
|
|
51
57
|
|
|
52
58
|
describe "GET new" do
|
|
53
59
|
it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
54
60
|
get :new, {}, valid_session
|
|
55
|
-
assigns(:<%= ns_file_name %>).
|
|
61
|
+
expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
|
|
56
62
|
end
|
|
57
63
|
end
|
|
58
64
|
|
|
@@ -60,7 +66,7 @@ describe <%= controller_class_name %>Controller do
|
|
|
60
66
|
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
61
67
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
62
68
|
get :edit, {:id => <%= file_name %>.to_param}, valid_session
|
|
63
|
-
assigns(:<%= ns_file_name %>).
|
|
69
|
+
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
|
64
70
|
end
|
|
65
71
|
end
|
|
66
72
|
|
|
@@ -74,77 +80,66 @@ describe <%= controller_class_name %>Controller do
|
|
|
74
80
|
|
|
75
81
|
it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
76
82
|
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
|
77
|
-
assigns(:<%= ns_file_name %>).
|
|
78
|
-
assigns(:<%= ns_file_name %>).
|
|
83
|
+
expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
|
|
84
|
+
expect(assigns(:<%= ns_file_name %>)).to be_persisted
|
|
79
85
|
end
|
|
80
86
|
|
|
81
87
|
it "redirects to the created <%= ns_file_name %>" do
|
|
82
88
|
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
|
83
|
-
response.
|
|
89
|
+
expect(response).to redirect_to(<%= class_name %>.last)
|
|
84
90
|
end
|
|
85
91
|
end
|
|
86
92
|
|
|
87
93
|
describe "with invalid params" do
|
|
88
94
|
it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
post :create, {:<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
|
92
|
-
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
|
95
|
+
post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
|
|
96
|
+
expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
|
|
93
97
|
end
|
|
94
98
|
|
|
95
99
|
it "re-renders the 'new' template" do
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
post :create, {:<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
|
99
|
-
response.should render_template("new")
|
|
100
|
+
post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
|
|
101
|
+
expect(response).to render_template("new")
|
|
100
102
|
end
|
|
101
103
|
end
|
|
102
104
|
end
|
|
103
105
|
|
|
104
106
|
describe "PUT update" do
|
|
105
107
|
describe "with valid params" do
|
|
108
|
+
let(:new_attributes) {
|
|
109
|
+
skip("Add a hash of attributes valid for your model")
|
|
110
|
+
}
|
|
111
|
+
|
|
106
112
|
it "updates the requested <%= ns_file_name %>" do
|
|
107
113
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
|
114
|
+
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session
|
|
115
|
+
<%= file_name %>.reload
|
|
116
|
+
skip("Add assertions for updated state")
|
|
118
117
|
end
|
|
119
118
|
|
|
120
119
|
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
121
120
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
122
121
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
|
123
|
-
assigns(:<%= ns_file_name %>).
|
|
122
|
+
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
|
124
123
|
end
|
|
125
124
|
|
|
126
125
|
it "redirects to the <%= ns_file_name %>" do
|
|
127
126
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
128
127
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
|
129
|
-
response.
|
|
128
|
+
expect(response).to redirect_to(<%= file_name %>)
|
|
130
129
|
end
|
|
131
130
|
end
|
|
132
131
|
|
|
133
132
|
describe "with invalid params" do
|
|
134
133
|
it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
135
134
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
|
139
|
-
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
|
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 %>)
|
|
140
137
|
end
|
|
141
138
|
|
|
142
139
|
it "re-renders the 'edit' template" do
|
|
143
140
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
|
147
|
-
response.should render_template("edit")
|
|
141
|
+
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
|
|
142
|
+
expect(response).to render_template("edit")
|
|
148
143
|
end
|
|
149
144
|
end
|
|
150
145
|
end
|
|
@@ -160,7 +155,7 @@ describe <%= controller_class_name %>Controller do
|
|
|
160
155
|
it "redirects to the <%= table_name %> list" do
|
|
161
156
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
162
157
|
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
|
|
163
|
-
response.
|
|
158
|
+
expect(response).to redirect_to(<%= index_helper %>_url)
|
|
164
159
|
end
|
|
165
160
|
end
|
|
166
161
|
|
|
@@ -1,9 +1,9 @@
|
|
|
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 => :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 -%>
|
|
@@ -13,19 +13,11 @@ 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
|
+
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
|
27
20
|
<% end -%>
|
|
28
21
|
end
|
|
29
|
-
<% end -%>
|
|
30
22
|
end
|
|
31
23
|
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 %>/index" do
|
|
4
|
+
RSpec.describe "<%= ns_table_name %>/index", :type => :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 -%>
|
|
@@ -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
|
-
<% if webrat? -%>
|
|
26
|
-
rendered.should have_selector("tr>td", :content => <%= value_for(attribute) %>.to_s, :count => 2)
|
|
27
|
-
<% else -%>
|
|
28
22
|
assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2
|
|
29
|
-
<% end -%>
|
|
30
23
|
<% end -%>
|
|
31
24
|
end
|
|
32
25
|
end
|
|
@@ -1,30 +1,22 @@
|
|
|
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 => :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
|
+
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
|
|
26
19
|
<% end -%>
|
|
27
20
|
end
|
|
28
|
-
<% end -%>
|
|
29
21
|
end
|
|
30
22
|
end
|
|
@@ -1,37 +1,37 @@
|
|
|
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 => :routing do
|
|
5
5
|
describe "routing" do
|
|
6
6
|
|
|
7
7
|
<% unless options[:singleton] -%>
|
|
8
8
|
it "routes to #index" do
|
|
9
|
-
get
|
|
9
|
+
expect(:get => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
<% end -%>
|
|
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
17
|
it "routes to #show" do
|
|
18
|
-
get
|
|
18
|
+
expect(:get => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", :id => "1")
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "routes to #edit" do
|
|
22
|
-
get
|
|
22
|
+
expect(:get => "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", :id => "1")
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "routes to #create" do
|
|
26
|
-
post
|
|
26
|
+
expect(:post => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "routes to #update" do
|
|
30
|
-
put
|
|
30
|
+
expect(:put => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "routes to #destroy" do
|
|
34
|
-
delete
|
|
34
|
+
expect(:delete => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", :id => "1")
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
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 => :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 -%>
|
|
@@ -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
|
data/lib/generators/rspec.rb
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
require 'rails/generators/named_base'
|
|
2
2
|
|
|
3
|
+
# Weirdly named generators namespace (should be `RSpec`) for compatability with
|
|
4
|
+
# rails loading.
|
|
3
5
|
module Rspec
|
|
6
|
+
# @private
|
|
4
7
|
module Generators
|
|
8
|
+
# @private
|
|
5
9
|
class Base < ::Rails::Generators::NamedBase
|
|
6
|
-
def self.source_root
|
|
7
|
-
|
|
10
|
+
def self.source_root(path = nil)
|
|
11
|
+
if path
|
|
12
|
+
@_rspec_source_root = path
|
|
13
|
+
else
|
|
14
|
+
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
|
15
|
+
end
|
|
8
16
|
end
|
|
9
17
|
|
|
10
18
|
if ::Rails::VERSION::STRING < '3.1'
|
|
@@ -16,15 +24,17 @@ module Rspec
|
|
|
16
24
|
end
|
|
17
25
|
end
|
|
18
26
|
|
|
27
|
+
# @private
|
|
19
28
|
module Rails
|
|
20
29
|
module Generators
|
|
30
|
+
# @private
|
|
21
31
|
class GeneratedAttribute
|
|
22
32
|
def input_type
|
|
23
33
|
@input_type ||= if type == :text
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
"textarea"
|
|
35
|
+
else
|
|
36
|
+
"input"
|
|
37
|
+
end
|
|
28
38
|
end
|
|
29
39
|
end
|
|
30
40
|
end
|
data/lib/rspec/rails/adapters.rb
CHANGED
|
@@ -5,8 +5,14 @@ require 'active_support/concern'
|
|
|
5
5
|
module RSpec
|
|
6
6
|
module Rails
|
|
7
7
|
if ::Rails::VERSION::STRING >= '4.1.0'
|
|
8
|
-
gem
|
|
8
|
+
if defined?(Kernel.gem)
|
|
9
|
+
gem 'minitest'
|
|
10
|
+
else
|
|
11
|
+
require 'minitest'
|
|
12
|
+
end
|
|
9
13
|
require 'minitest/assertions'
|
|
14
|
+
# Constant aliased to either Minitest or TestUnit, depending on what is
|
|
15
|
+
# loaded.
|
|
10
16
|
Assertions = Minitest::Assertions
|
|
11
17
|
else
|
|
12
18
|
begin
|
|
@@ -16,12 +22,13 @@ module RSpec
|
|
|
16
22
|
require 'rubysl-test-unit' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
|
17
23
|
require 'test/unit/assertions'
|
|
18
24
|
end
|
|
25
|
+
# Constant aliased to either Minitest or TestUnit, depending on what is
|
|
26
|
+
# loaded.
|
|
19
27
|
Assertions = Test::Unit::Assertions
|
|
20
28
|
end
|
|
21
29
|
|
|
22
|
-
# @
|
|
30
|
+
# @private
|
|
23
31
|
class AssertionDelegator < Module
|
|
24
|
-
# @api private
|
|
25
32
|
def initialize(*assertion_modules)
|
|
26
33
|
assertion_class = Class.new(SimpleDelegator) do
|
|
27
34
|
include ::RSpec::Rails::Assertions
|
|
@@ -30,12 +37,10 @@ module RSpec
|
|
|
30
37
|
end
|
|
31
38
|
|
|
32
39
|
super() do
|
|
33
|
-
# @api private
|
|
34
40
|
define_method :build_assertion_instance do
|
|
35
41
|
assertion_class.new(self)
|
|
36
42
|
end
|
|
37
43
|
|
|
38
|
-
# @api private
|
|
39
44
|
def assertion_instance
|
|
40
45
|
@assertion_instance ||= build_assertion_instance
|
|
41
46
|
end
|
|
@@ -43,11 +48,9 @@ module RSpec
|
|
|
43
48
|
assertion_modules.each do |mod|
|
|
44
49
|
mod.public_instance_methods.each do |method|
|
|
45
50
|
next if method == :method_missing || method == "method_missing"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
end
|
|
50
|
-
EOM
|
|
51
|
+
define_method(method.to_sym) do |*args, &block|
|
|
52
|
+
assertion_instance.send(method.to_sym, *args, &block)
|
|
53
|
+
end
|
|
51
54
|
end
|
|
52
55
|
end
|
|
53
56
|
end
|
|
@@ -56,7 +59,7 @@ module RSpec
|
|
|
56
59
|
|
|
57
60
|
# Adapts example groups for `Minitest::Test::LifecycleHooks`
|
|
58
61
|
#
|
|
59
|
-
# @
|
|
62
|
+
# @private
|
|
60
63
|
module MinitestLifecycleAdapter
|
|
61
64
|
extend ActiveSupport::Concern
|
|
62
65
|
|
|
@@ -84,26 +87,19 @@ module RSpec
|
|
|
84
87
|
end
|
|
85
88
|
end
|
|
86
89
|
|
|
87
|
-
# @
|
|
90
|
+
# @private
|
|
88
91
|
module MinitestCounters
|
|
89
|
-
|
|
92
|
+
attr_writer :assertions
|
|
90
93
|
def assertions
|
|
91
94
|
@assertions ||= 0
|
|
92
95
|
end
|
|
93
|
-
|
|
94
|
-
# @api private
|
|
95
|
-
def assertions=(assertions)
|
|
96
|
-
@assertions = assertions
|
|
97
|
-
end
|
|
98
96
|
end
|
|
99
97
|
|
|
100
|
-
# @
|
|
98
|
+
# @private
|
|
101
99
|
module SetupAndTeardownAdapter
|
|
102
100
|
extend ActiveSupport::Concern
|
|
103
101
|
|
|
104
102
|
module ClassMethods
|
|
105
|
-
# @api private
|
|
106
|
-
#
|
|
107
103
|
# Wraps `setup` calls from within Rails' testing framework in `before`
|
|
108
104
|
# hooks.
|
|
109
105
|
def setup(*methods)
|
|
@@ -125,7 +121,11 @@ module RSpec
|
|
|
125
121
|
end
|
|
126
122
|
end
|
|
127
123
|
|
|
128
|
-
|
|
124
|
+
def initialize(*args)
|
|
125
|
+
super
|
|
126
|
+
@example = nil
|
|
127
|
+
end
|
|
128
|
+
|
|
129
129
|
def method_name
|
|
130
130
|
@example
|
|
131
131
|
end
|
|
@@ -135,36 +135,34 @@ module RSpec
|
|
|
135
135
|
module MinitestAssertionAdapter
|
|
136
136
|
extend ActiveSupport::Concern
|
|
137
137
|
|
|
138
|
+
# @private
|
|
138
139
|
module ClassMethods
|
|
139
|
-
# @api private
|
|
140
|
-
#
|
|
141
140
|
# Returns the names of assertion methods that we want to expose to
|
|
142
141
|
# examples without exposing non-assertion methods in Test::Unit or
|
|
143
142
|
# Minitest.
|
|
144
143
|
def assertion_method_names
|
|
145
|
-
::RSpec::Rails::Assertions.
|
|
146
|
-
|
|
144
|
+
methods = ::RSpec::Rails::Assertions.
|
|
145
|
+
public_instance_methods.
|
|
146
|
+
select do |m|
|
|
147
|
+
m.to_s =~ /^(assert|flunk|refute)/
|
|
148
|
+
end
|
|
149
|
+
methods + [:build_message]
|
|
147
150
|
end
|
|
148
151
|
|
|
149
|
-
# @api private
|
|
150
152
|
def define_assertion_delegators
|
|
151
153
|
assertion_method_names.each do |m|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
end
|
|
156
|
-
CODE
|
|
154
|
+
define_method(m.to_sym) do |*args, &block|
|
|
155
|
+
assertion_delegator.send(m.to_sym, *args, &block)
|
|
156
|
+
end
|
|
157
157
|
end
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
-
# @api private
|
|
162
161
|
class AssertionDelegator
|
|
163
162
|
include ::RSpec::Rails::Assertions
|
|
164
163
|
include ::RSpec::Rails::MinitestCounters
|
|
165
164
|
end
|
|
166
165
|
|
|
167
|
-
# @api private
|
|
168
166
|
def assertion_delegator
|
|
169
167
|
@assertion_delegator ||= AssertionDelegator.new
|
|
170
168
|
end
|
|
@@ -177,7 +175,7 @@ module RSpec
|
|
|
177
175
|
# Backwards compatibility. It's unlikely that anyone is using this
|
|
178
176
|
# constant, but we had forgotten to mark it as `@private` earlier
|
|
179
177
|
#
|
|
180
|
-
# @
|
|
178
|
+
# @private
|
|
181
179
|
TestUnitAssertionAdapter = MinitestAssertionAdapter
|
|
182
180
|
end
|
|
183
181
|
end
|