rspec-rails 2.0.0.beta.22 → 2.6.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.
- data/.gitignore +10 -4
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/History.md +1 -33
- data/License.txt +23 -0
- data/{README.markdown → README.md} +27 -7
- data/README_DEV.md +43 -0
- data/Rakefile +105 -35
- data/Thorfile +40 -0
- data/Upgrade.md +1 -0
- data/features/.nav +34 -0
- data/features/Autotest.md +24 -0
- data/features/Changelog.md +151 -0
- data/features/Generators.md +8 -0
- data/features/GettingStarted.md +84 -0
- data/features/README.md +58 -0
- data/features/Upgrade.md +117 -0
- data/features/controller_specs/README.md +45 -0
- data/features/controller_specs/anonymous_controller.feature +7 -7
- data/features/controller_specs/controller_spec.feature +18 -0
- data/features/controller_specs/isolation_from_views.feature +55 -8
- data/features/controller_specs/render_views.feature +63 -52
- data/features/helper_specs/helper_spec.feature +40 -6
- data/features/mailer_specs/url_helpers.feature +4 -4
- data/features/matchers/README.md +4 -0
- data/features/matchers/new_record_matcher.feature +6 -48
- data/features/matchers/redirect_to_matcher.feature +5 -6
- data/features/matchers/render_template_matcher.feature +13 -10
- data/features/mocks/mock_model.feature +29 -13
- data/features/mocks/stub_model.feature +4 -4
- data/features/model_specs/README.md +21 -0
- data/features/model_specs/errors_on.feature +2 -2
- data/features/model_specs/transactional_examples.feature +14 -9
- data/features/request_specs/request_spec.feature +49 -0
- data/features/routing_specs/README.md +17 -0
- data/features/{matchers → routing_specs}/be_routable_matcher.feature +25 -25
- data/features/routing_specs/named_routes.feature +18 -0
- data/features/routing_specs/route_to_matcher.feature +58 -0
- data/features/step_definitions/additional_cli_steps.rb +4 -0
- data/features/support/env.rb +14 -6
- data/features/view_specs/inferred_controller_path.feature +6 -6
- data/features/view_specs/stub_template.feature +51 -0
- data/features/view_specs/view_spec.feature +23 -42
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/base.rb +58 -0
- data/gemfiles/rails-3-0-stable +6 -0
- data/gemfiles/rails-3.0.0 +5 -0
- data/gemfiles/rails-3.0.1 +5 -0
- data/gemfiles/rails-3.0.2 +5 -0
- data/gemfiles/rails-3.0.3 +5 -0
- data/gemfiles/rails-3.0.4 +5 -0
- data/gemfiles/rails-3.0.5 +5 -0
- data/gemfiles/rails-3.0.6 +5 -0
- data/gemfiles/rails-3.0.7 +5 -0
- data/gemfiles/rails-3.1.0.beta1 +5 -0
- data/gemfiles/rails-master +7 -0
- data/lib/autotest/rails_rspec2.rb +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +4 -4
- data/lib/generators/rspec/helper/helper_generator.rb +3 -3
- data/lib/generators/rspec/install/install_generator.rb +0 -8
- data/lib/generators/rspec/integration/integration_generator.rb +15 -1
- data/lib/generators/rspec/integration/templates/request_spec.rb +7 -1
- data/lib/generators/rspec/mailer/mailer_generator.rb +2 -2
- data/lib/generators/rspec/model/model_generator.rb +1 -1
- data/lib/generators/rspec/observer/observer_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +40 -11
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +90 -58
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +15 -7
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +7 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +14 -7
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +7 -2
- data/lib/generators/rspec/view/view_generator.rb +1 -1
- data/lib/rspec/rails/example/controller_example_group.rb +25 -34
- data/lib/rspec/rails/example/helper_example_group.rb +5 -11
- data/lib/rspec/rails/example/mailer_example_group.rb +0 -14
- data/lib/rspec/rails/example/model_example_group.rb +0 -4
- data/lib/rspec/rails/example/rails_example_group.rb +0 -2
- data/lib/rspec/rails/example/request_example_group.rb +5 -30
- data/lib/rspec/rails/example/routing_example_group.rb +3 -5
- data/lib/rspec/rails/example/view_example_group.rb +20 -11
- data/lib/rspec/rails/example.rb +31 -1
- data/lib/rspec/rails/extensions/active_record/base.rb +28 -32
- data/lib/rspec/rails/fixture_support.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +5 -0
- data/lib/rspec/rails/matchers/redirect_to.rb +6 -2
- data/lib/rspec/rails/matchers/render_template.rb +5 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +24 -3
- data/lib/rspec/rails/matchers.rb +1 -1
- data/lib/rspec/rails/mocks.rb +118 -79
- data/lib/rspec/rails/module_inclusion.rb +17 -0
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/vendor/capybara.rb +29 -0
- data/lib/rspec/rails/vendor/webrat.rb +33 -0
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +23 -4
- data/lib/rspec/rails/view_rendering.rb +50 -13
- data/lib/rspec/rails.rb +7 -10
- data/lib/rspec-rails.rb +4 -2
- data/rspec-rails.gemspec +11 -39
- data/spec/autotest/rails_rspec2_spec.rb +25 -14
- data/spec/rspec/rails/configuration_spec.rb +26 -0
- data/spec/rspec/rails/deprecations_spec.rb +18 -0
- data/spec/rspec/rails/example/controller_example_group_spec.rb +47 -5
- data/spec/rspec/rails/example/helper_example_group_spec.rb +19 -1
- data/spec/rspec/rails/example/request_example_group_spec.rb +2 -0
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
- data/spec/rspec/rails/extensions/active_record/records_spec.rb +9 -0
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +17 -0
- data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +67 -8
- data/spec/rspec/rails/matchers/render_template_spec.rb +67 -10
- data/spec/rspec/rails/matchers/route_to_spec.rb +77 -31
- data/spec/rspec/rails/mocks/ar_classes.rb +17 -25
- data/spec/rspec/rails/mocks/mock_model_spec.rb +50 -13
- data/spec/rspec/rails/mocks/stub_model_spec.rb +121 -67
- data/spec/rspec/rails/view_rendering_spec.rb +105 -0
- data/spec/spec_helper.rb +0 -22
- data/spec/support/matchers.rb +9 -0
- data/templates/generate_stuff.rb +10 -2
- data/templates/run_specs.rb +2 -2
- metadata +141 -79
- data/Gemfile +0 -24
- data/Gotchas.markdown +0 -14
- data/Upgrade.markdown +0 -31
- data/autotest/discover.rb +0 -1
- data/features/README.markdown +0 -12
- data/features/controller_specs/readers.feature +0 -18
- data/features/routing_specs/access_to_named_routes.feature +0 -15
- data/lib/generators/rspec/install/templates/autotest/discover.rb +0 -2
- data/lib/rspec/rails/browser_simulators.rb +0 -30
- data/spec/rspec/rails/example/view_rendering_spec.rb +0 -110
- data/specs.watchr +0 -59
- data/templates/Gemfile +0 -18
|
@@ -1,126 +1,158 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
|
4
|
+
# It demonstrates how one might use RSpec to specify 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
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
|
16
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
|
17
|
+
# is no simpler way to get a handle on the object needed for the example.
|
|
18
|
+
# Message expectations are only used when there is no simpler way to specify
|
|
19
|
+
# that an instance is receiving a specific message.
|
|
20
|
+
|
|
3
21
|
describe <%= controller_class_name %>Controller do
|
|
4
22
|
|
|
5
|
-
|
|
6
|
-
|
|
23
|
+
# This should return the minimal set of attributes required to create a valid
|
|
24
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
|
25
|
+
# update the return value of this method accordingly.
|
|
26
|
+
def valid_attributes
|
|
27
|
+
{}
|
|
7
28
|
end
|
|
8
29
|
|
|
9
30
|
<% unless options[:singleton] -%>
|
|
10
31
|
describe "GET index" do
|
|
11
32
|
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
|
12
|
-
<%=
|
|
33
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
13
34
|
get :index
|
|
14
|
-
assigns(:<%= table_name %>).should eq([<%=
|
|
35
|
+
assigns(:<%= table_name %>).should eq([<%= file_name %>])
|
|
15
36
|
end
|
|
16
37
|
end
|
|
17
38
|
|
|
18
39
|
<% end -%>
|
|
19
40
|
describe "GET show" do
|
|
20
|
-
it "assigns the requested <%=
|
|
21
|
-
<%=
|
|
22
|
-
get :show, :id =>
|
|
23
|
-
assigns(:<%=
|
|
41
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
42
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
43
|
+
get :show, :id => <%= file_name %>.id.to_s
|
|
44
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
|
24
45
|
end
|
|
25
46
|
end
|
|
26
47
|
|
|
27
48
|
describe "GET new" do
|
|
28
|
-
it "assigns a new <%=
|
|
29
|
-
<%= stub! orm_class.build(class_name) %> { <%= mock_file_name %> }
|
|
49
|
+
it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
30
50
|
get :new
|
|
31
|
-
assigns(:<%=
|
|
51
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
|
32
52
|
end
|
|
33
53
|
end
|
|
34
54
|
|
|
35
55
|
describe "GET edit" do
|
|
36
|
-
it "assigns the requested <%=
|
|
37
|
-
<%=
|
|
38
|
-
get :edit, :id =>
|
|
39
|
-
assigns(:<%=
|
|
56
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
57
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
58
|
+
get :edit, :id => <%= file_name %>.id.to_s
|
|
59
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
|
40
60
|
end
|
|
41
61
|
end
|
|
42
62
|
|
|
43
63
|
describe "POST create" do
|
|
44
|
-
|
|
45
64
|
describe "with valid params" do
|
|
46
|
-
it "
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
it "creates a new <%= class_name %>" do
|
|
66
|
+
expect {
|
|
67
|
+
post :create, :<%= ns_file_name %> => valid_attributes
|
|
68
|
+
}.to change(<%= class_name %>, :count).by(1)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
72
|
+
post :create, :<%= ns_file_name %> => valid_attributes
|
|
73
|
+
assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
|
|
74
|
+
assigns(:<%= ns_file_name %>).should be_persisted
|
|
50
75
|
end
|
|
51
76
|
|
|
52
|
-
it "redirects to the created <%=
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
|
|
77
|
+
it "redirects to the created <%= ns_file_name %>" do
|
|
78
|
+
post :create, :<%= ns_file_name %> => valid_attributes
|
|
79
|
+
response.should redirect_to(<%= class_name %>.last)
|
|
56
80
|
end
|
|
57
81
|
end
|
|
58
82
|
|
|
59
83
|
describe "with invalid params" do
|
|
60
|
-
it "assigns a newly created but unsaved <%=
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
84
|
+
it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
85
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
86
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
|
87
|
+
post :create, :<%= ns_file_name %> => {}
|
|
88
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
|
64
89
|
end
|
|
65
90
|
|
|
66
91
|
it "re-renders the 'new' template" do
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
93
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
|
94
|
+
post :create, :<%= ns_file_name %> => {}
|
|
69
95
|
response.should render_template("new")
|
|
70
96
|
end
|
|
71
97
|
end
|
|
72
|
-
|
|
73
98
|
end
|
|
74
99
|
|
|
75
100
|
describe "PUT update" do
|
|
76
|
-
|
|
77
101
|
describe "with valid params" do
|
|
78
|
-
it "updates the requested <%=
|
|
79
|
-
<%=
|
|
80
|
-
|
|
81
|
-
|
|
102
|
+
it "updates the requested <%= ns_file_name %>" do
|
|
103
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
104
|
+
# Assuming there are no other <%= table_name %> in the database, this
|
|
105
|
+
# specifies that the <%= class_name %> created on the previous line
|
|
106
|
+
# receives the :update_attributes message with whatever params are
|
|
107
|
+
# submitted in the request.
|
|
108
|
+
<%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= params %>)
|
|
109
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => <%= params %>
|
|
82
110
|
end
|
|
83
111
|
|
|
84
|
-
it "assigns the requested <%=
|
|
85
|
-
<%=
|
|
86
|
-
put :update, :id =>
|
|
87
|
-
assigns(:<%=
|
|
112
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
113
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
114
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
|
|
115
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
|
88
116
|
end
|
|
89
117
|
|
|
90
|
-
it "redirects to the <%=
|
|
91
|
-
<%=
|
|
92
|
-
put :update, :id =>
|
|
93
|
-
response.should redirect_to(<%=
|
|
118
|
+
it "redirects to the <%= ns_file_name %>" do
|
|
119
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
120
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
|
|
121
|
+
response.should redirect_to(<%= file_name %>)
|
|
94
122
|
end
|
|
95
123
|
end
|
|
96
124
|
|
|
97
125
|
describe "with invalid params" do
|
|
98
|
-
it "assigns the <%=
|
|
99
|
-
<%=
|
|
100
|
-
|
|
101
|
-
|
|
126
|
+
it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
|
|
127
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
128
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
129
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
|
130
|
+
put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
|
|
131
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
|
102
132
|
end
|
|
103
133
|
|
|
104
134
|
it "re-renders the 'edit' template" do
|
|
105
|
-
<%=
|
|
106
|
-
|
|
135
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
136
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
137
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
|
138
|
+
put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
|
|
107
139
|
response.should render_template("edit")
|
|
108
140
|
end
|
|
109
141
|
end
|
|
110
|
-
|
|
111
142
|
end
|
|
112
143
|
|
|
113
144
|
describe "DELETE destroy" do
|
|
114
|
-
it "destroys the requested <%=
|
|
115
|
-
<%=
|
|
116
|
-
|
|
117
|
-
|
|
145
|
+
it "destroys the requested <%= ns_file_name %>" do
|
|
146
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
147
|
+
expect {
|
|
148
|
+
delete :destroy, :id => <%= file_name %>.id.to_s
|
|
149
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
|
118
150
|
end
|
|
119
151
|
|
|
120
152
|
it "redirects to the <%= table_name %> list" do
|
|
121
|
-
<%=
|
|
122
|
-
delete :destroy, :id =>
|
|
123
|
-
response.should redirect_to(<%=
|
|
153
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
|
154
|
+
delete :destroy, :id => <%= file_name %>.id.to_s
|
|
155
|
+
response.should redirect_to(<%= index_helper %>_url)
|
|
124
156
|
end
|
|
125
157
|
end
|
|
126
158
|
|
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
|
4
|
-
describe "<%=
|
|
4
|
+
describe "<%= ns_table_name %>/edit.html.<%= options[:template_engine] %>" do
|
|
5
5
|
before(:each) do
|
|
6
|
-
@<%=
|
|
7
|
-
:new_record? => false<%= output_attributes.empty? ? '' : ',' %>
|
|
6
|
+
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
|
|
8
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
|
9
8
|
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
|
10
9
|
<% end -%>
|
|
11
|
-
))
|
|
10
|
+
<%= output_attributes.empty? ? "" : " ))\n" -%>
|
|
12
11
|
end
|
|
13
12
|
|
|
14
|
-
it "renders the edit <%=
|
|
13
|
+
it "renders the edit <%= ns_file_name %> form" do
|
|
15
14
|
render
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
<% if webrat? -%>
|
|
17
|
+
rendered.should have_selector("form", :action => <%= ns_file_name %>_path(@<%= ns_file_name %>), :method => "post") do |form|
|
|
18
18
|
<% for attribute in output_attributes -%>
|
|
19
|
-
form.should have_selector("<%= attribute.input_type -%>#<%=
|
|
19
|
+
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
|
20
20
|
<% end -%>
|
|
21
21
|
end
|
|
22
|
+
<% else -%>
|
|
23
|
+
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
|
24
|
+
assert_select "form", :action => <%= index_helper %>_path(@<%= ns_file_name %>), :method => "post" do
|
|
25
|
+
<% for attribute in output_attributes -%>
|
|
26
|
+
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]"
|
|
27
|
+
<% end -%>
|
|
28
|
+
end
|
|
29
|
+
<% end -%>
|
|
22
30
|
end
|
|
23
31
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
|
4
|
-
describe "<%=
|
|
4
|
+
describe "<%= ns_table_name %>/index.html.<%= options[:template_engine] %>" do
|
|
5
5
|
before(:each) do
|
|
6
6
|
assign(:<%= table_name %>, [
|
|
7
7
|
<% [1,2].each_with_index do |id, model_index| -%>
|
|
@@ -16,10 +16,15 @@ describe "<%= table_name %>/index.html.<%= options[:template_engine] %>" do
|
|
|
16
16
|
])
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
it "renders a list of <%=
|
|
19
|
+
it "renders a list of <%= ns_table_name %>" do
|
|
20
20
|
render
|
|
21
21
|
<% for attribute in output_attributes -%>
|
|
22
|
+
<% if webrat? -%>
|
|
22
23
|
rendered.should have_selector("tr>td", :content => <%= value_for(attribute) %>.to_s, :count => 2)
|
|
24
|
+
<% else -%>
|
|
25
|
+
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
|
26
|
+
assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2
|
|
27
|
+
<% end -%>
|
|
23
28
|
<% end -%>
|
|
24
29
|
end
|
|
25
30
|
end
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
|
4
|
-
describe "<%=
|
|
4
|
+
describe "<%= ns_table_name %>/new.html.<%= options[:template_engine] %>" do
|
|
5
5
|
before(:each) do
|
|
6
|
-
assign(:<%=
|
|
7
|
-
:new_record? => true<%= output_attributes.empty? ? '' : ',' %>
|
|
6
|
+
assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? ').as_new_record)' : ',' %>
|
|
8
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
|
9
8
|
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
|
10
9
|
<% end -%>
|
|
11
|
-
))
|
|
12
|
-
end
|
|
10
|
+
<%= !output_attributes.empty? ? " ).as_new_record)\n end" : " end" %>
|
|
13
11
|
|
|
14
|
-
it "renders new <%=
|
|
12
|
+
it "renders new <%= ns_file_name %> form" do
|
|
15
13
|
render
|
|
16
14
|
|
|
15
|
+
<% if webrat? -%>
|
|
17
16
|
rendered.should have_selector("form", :action => <%= table_name %>_path, :method => "post") do |form|
|
|
18
17
|
<% for attribute in output_attributes -%>
|
|
19
|
-
form.should have_selector("<%= attribute.input_type -%>#<%=
|
|
18
|
+
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
|
20
19
|
<% end -%>
|
|
21
20
|
end
|
|
21
|
+
<% else -%>
|
|
22
|
+
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
|
23
|
+
assert_select "form", :action => <%= index_helper %>_path, :method => "post" do
|
|
24
|
+
<% for attribute in output_attributes -%>
|
|
25
|
+
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]"
|
|
26
|
+
<% end -%>
|
|
27
|
+
end
|
|
28
|
+
<% end -%>
|
|
22
29
|
end
|
|
23
30
|
end
|
|
@@ -4,33 +4,33 @@ describe <%= controller_class_name %>Controller do
|
|
|
4
4
|
describe "routing" do
|
|
5
5
|
|
|
6
6
|
<% unless options[:singleton] -%>
|
|
7
|
-
it "
|
|
8
|
-
|
|
7
|
+
it "routes to #index" do
|
|
8
|
+
get("/<%= ns_table_name %>").should route_to("<%= ns_table_name %>#index")
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
<% end -%>
|
|
12
|
-
it "
|
|
13
|
-
|
|
12
|
+
it "routes to #new" do
|
|
13
|
+
get("/<%= ns_table_name %>/new").should route_to("<%= ns_table_name %>#new")
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
it "
|
|
17
|
-
|
|
16
|
+
it "routes to #show" do
|
|
17
|
+
get("/<%= ns_table_name %>/1").should route_to("<%= ns_table_name %>#show", :id => "1")
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
it "
|
|
21
|
-
|
|
20
|
+
it "routes to #edit" do
|
|
21
|
+
get("/<%= ns_table_name %>/1/edit").should route_to("<%= ns_table_name %>#edit", :id => "1")
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
it "
|
|
25
|
-
|
|
24
|
+
it "routes to #create" do
|
|
25
|
+
post("/<%= ns_table_name %>").should route_to("<%= ns_table_name %>#create")
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
it "
|
|
29
|
-
|
|
28
|
+
it "routes to #update" do
|
|
29
|
+
put("/<%= ns_table_name %>/1").should route_to("<%= ns_table_name %>#update", :id => "1")
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
it "
|
|
33
|
-
|
|
32
|
+
it "routes to #destroy" do
|
|
33
|
+
delete("/<%= ns_table_name %>/1").should route_to("<%= ns_table_name %>#destroy", :id => "1")
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
|
4
|
-
describe "<%=
|
|
4
|
+
describe "<%= ns_table_name %>/show.html.<%= options[:template_engine] %>" do
|
|
5
5
|
before(:each) do
|
|
6
|
-
@<%=
|
|
6
|
+
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= 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 -%>
|
|
@@ -15,7 +15,12 @@ describe "<%= table_name %>/show.html.<%= options[:template_engine] %>" do
|
|
|
15
15
|
it "renders attributes in <p>" do
|
|
16
16
|
render
|
|
17
17
|
<% for attribute in output_attributes -%>
|
|
18
|
+
<% if webrat? -%>
|
|
18
19
|
rendered.should contain(<%= value_for(attribute) %>.to_s)
|
|
20
|
+
<% else -%>
|
|
21
|
+
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
|
22
|
+
rendered.should match(/<%= eval(value_for(attribute)) %>/)
|
|
23
|
+
<% end -%>
|
|
19
24
|
<% end -%>
|
|
20
25
|
end
|
|
21
26
|
end
|
|
@@ -56,15 +56,19 @@ module RSpec::Rails
|
|
|
56
56
|
#
|
|
57
57
|
# RSpec's preferred approach to spec'ing controller behaviour is to isolate
|
|
58
58
|
# the controller from its collaborators. By default, therefore, controller
|
|
59
|
-
# example groups do not render views
|
|
60
|
-
#
|
|
61
|
-
#
|
|
59
|
+
# example groups do not render the views in your app. Due to the way Rails
|
|
60
|
+
# searches for view templates, the template still needs to exist, but it
|
|
61
|
+
# won't actually be loaded.
|
|
62
|
+
#
|
|
63
|
+
# NOTE that this is different from rspec-rails-1 with rails-2, which did not
|
|
64
|
+
# require the presence of the file at all. Due to changes in rails-3, this
|
|
65
|
+
# was no longer feasible in rspec-rails-2.
|
|
62
66
|
#
|
|
63
67
|
# == View rendering
|
|
64
68
|
#
|
|
65
|
-
# If you prefer a more integrated approach, similar to that of
|
|
66
|
-
#
|
|
67
|
-
#
|
|
69
|
+
# If you prefer a more integrated approach, similar to that of Rails'
|
|
70
|
+
# functional tests, you can tell controller groups to render the views in the
|
|
71
|
+
# app with the +render_views+ declaration:
|
|
68
72
|
#
|
|
69
73
|
# describe WidgetsController do
|
|
70
74
|
# render_views
|
|
@@ -72,32 +76,12 @@ module RSpec::Rails
|
|
|
72
76
|
#
|
|
73
77
|
module ControllerExampleGroup
|
|
74
78
|
extend ActiveSupport::Concern
|
|
75
|
-
extend RSpec::Rails::ModuleInclusion
|
|
76
|
-
|
|
77
79
|
include RSpec::Rails::RailsExampleGroup
|
|
78
|
-
|
|
79
80
|
include ActionController::TestCase::Behavior
|
|
80
81
|
include RSpec::Rails::ViewRendering
|
|
81
82
|
include RSpec::Rails::Matchers::RedirectTo
|
|
82
83
|
include RSpec::Rails::Matchers::RenderTemplate
|
|
83
84
|
include RSpec::Rails::Matchers::RoutingMatchers
|
|
84
|
-
include RSpec::Rails::BrowserSimulators
|
|
85
|
-
|
|
86
|
-
webrat do
|
|
87
|
-
include Webrat::Methods
|
|
88
|
-
include Webrat::Matchers
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
capybara do
|
|
92
|
-
include Capybara
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
# TODO (DC 7/31/2010) this is already included in RailsExampleGroup, but
|
|
96
|
-
# due to some load order dependency problem between Webrat::Matchers and
|
|
97
|
-
# RSpec::Matchers, combined with the fact that RailsExampleGroup extends
|
|
98
|
-
# ActiveSupport::Concern, while the matcher modules do not, this needs to
|
|
99
|
-
# be here as well. At least for now.
|
|
100
|
-
include RSpec::Matchers
|
|
101
85
|
|
|
102
86
|
module ClassMethods
|
|
103
87
|
def controller_class
|
|
@@ -141,11 +125,9 @@ module RSpec::Rails
|
|
|
141
125
|
# defined in +ApplicationController+, however, are accessible from within
|
|
142
126
|
# the block.
|
|
143
127
|
def controller(base_class = ApplicationController, &body)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
"StubResourcesController"
|
|
148
|
-
end
|
|
128
|
+
base_class.dup.tap do |new_base|
|
|
129
|
+
def new_base.name; "StubResourcesController"; end
|
|
130
|
+
metadata[:example_group][:describes] = Class.new(new_base, &body)
|
|
149
131
|
end
|
|
150
132
|
|
|
151
133
|
before do
|
|
@@ -154,23 +136,32 @@ module RSpec::Rails
|
|
|
154
136
|
end
|
|
155
137
|
|
|
156
138
|
after do
|
|
157
|
-
@routes = @orig_routes
|
|
139
|
+
@routes, @orig_routes = @orig_routes, nil
|
|
158
140
|
end
|
|
159
141
|
end
|
|
160
142
|
end
|
|
161
143
|
|
|
162
144
|
module InstanceMethods
|
|
163
145
|
attr_reader :controller, :routes
|
|
146
|
+
|
|
147
|
+
def method_missing(method, *args, &block)
|
|
148
|
+
if @orig_routes && @orig_routes.named_routes.helpers.include?(method)
|
|
149
|
+
controller.send(method, *args, &block)
|
|
150
|
+
else
|
|
151
|
+
super
|
|
152
|
+
end
|
|
153
|
+
end
|
|
164
154
|
end
|
|
165
155
|
|
|
166
156
|
included do
|
|
157
|
+
subject { controller }
|
|
158
|
+
|
|
167
159
|
metadata[:type] = :controller
|
|
160
|
+
|
|
168
161
|
before do
|
|
169
162
|
@routes = ::Rails.application.routes
|
|
170
163
|
ActionController::Base.allow_forgery_protection = false
|
|
171
164
|
end
|
|
172
165
|
end
|
|
173
|
-
|
|
174
|
-
RSpec.configure &include_self_when_dir_matches('spec','controllers')
|
|
175
166
|
end
|
|
176
167
|
end
|
|
@@ -27,17 +27,9 @@ module RSpec::Rails
|
|
|
27
27
|
#
|
|
28
28
|
module HelperExampleGroup
|
|
29
29
|
extend ActiveSupport::Concern
|
|
30
|
-
extend RSpec::Rails::ModuleInclusion
|
|
31
|
-
|
|
32
30
|
include RSpec::Rails::RailsExampleGroup
|
|
33
|
-
|
|
34
31
|
include ActionView::TestCase::Behavior
|
|
35
32
|
include RSpec::Rails::ViewAssigns
|
|
36
|
-
include RSpec::Rails::BrowserSimulators
|
|
37
|
-
|
|
38
|
-
webrat do
|
|
39
|
-
include Webrat::Matchers
|
|
40
|
-
end
|
|
41
33
|
|
|
42
34
|
module ClassMethods
|
|
43
35
|
def determine_default_helper_class(ignore)
|
|
@@ -49,7 +41,10 @@ module RSpec::Rails
|
|
|
49
41
|
# Returns an instance of ActionView::Base with the helper being specified
|
|
50
42
|
# mixed in, along with any of the built-in rails helpers.
|
|
51
43
|
def helper
|
|
52
|
-
_view.tap
|
|
44
|
+
_view.tap do |v|
|
|
45
|
+
v.extend(ApplicationHelper) if defined?(ApplicationHelper)
|
|
46
|
+
v.assign(view_assigns)
|
|
47
|
+
end
|
|
53
48
|
end
|
|
54
49
|
|
|
55
50
|
private
|
|
@@ -61,11 +56,10 @@ module RSpec::Rails
|
|
|
61
56
|
|
|
62
57
|
included do
|
|
63
58
|
metadata[:type] = :helper
|
|
59
|
+
|
|
64
60
|
before do
|
|
65
61
|
controller.controller_path = _controller_path
|
|
66
62
|
end
|
|
67
63
|
end
|
|
68
|
-
|
|
69
|
-
RSpec.configure &include_self_when_dir_matches('spec','helpers')
|
|
70
64
|
end
|
|
71
65
|
end
|
|
@@ -2,20 +2,8 @@ if defined?(ActionMailer)
|
|
|
2
2
|
module RSpec::Rails
|
|
3
3
|
module MailerExampleGroup
|
|
4
4
|
extend ActiveSupport::Concern
|
|
5
|
-
extend RSpec::Rails::ModuleInclusion
|
|
6
|
-
|
|
7
5
|
include RSpec::Rails::RailsExampleGroup
|
|
8
|
-
|
|
9
6
|
include ActionMailer::TestCase::Behavior
|
|
10
|
-
include RSpec::Rails::BrowserSimulators
|
|
11
|
-
|
|
12
|
-
webrat do
|
|
13
|
-
include Webrat::Matchers
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
capybara do
|
|
17
|
-
include Capybara
|
|
18
|
-
end
|
|
19
7
|
|
|
20
8
|
included do
|
|
21
9
|
metadata[:type] = :mailer
|
|
@@ -29,8 +17,6 @@ if defined?(ActionMailer)
|
|
|
29
17
|
describes
|
|
30
18
|
end
|
|
31
19
|
end
|
|
32
|
-
|
|
33
|
-
RSpec.configure &include_self_when_dir_matches('spec','mailers')
|
|
34
20
|
end
|
|
35
21
|
end
|
|
36
22
|
end
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
module RSpec::Rails
|
|
2
2
|
module ModelExampleGroup
|
|
3
3
|
extend ActiveSupport::Concern
|
|
4
|
-
extend RSpec::Rails::ModuleInclusion
|
|
5
|
-
|
|
6
4
|
include RSpec::Rails::RailsExampleGroup
|
|
7
5
|
|
|
8
6
|
included do
|
|
9
7
|
metadata[:type] = :model
|
|
10
8
|
end
|
|
11
|
-
|
|
12
|
-
RSpec.configure &include_self_when_dir_matches('spec','models')
|
|
13
9
|
end
|
|
14
10
|
end
|