mcmire-rspec-rails 1.1.99.9
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/History.txt +174 -0
- data/License.txt +33 -0
- data/Manifest.txt +164 -0
- data/README.txt +45 -0
- data/Rakefile +63 -0
- data/TODO.txt +1 -0
- data/Upgrade.markdown +52 -0
- data/features/step_definitions/people.rb +6 -0
- data/features/support/env.rb +13 -0
- data/features/transactions/transactions_should_rollback.feature +16 -0
- data/generators/rspec/CHANGES +1 -0
- data/generators/rspec/rspec_generator.rb +37 -0
- data/generators/rspec/templates/previous_failures.txt +0 -0
- data/generators/rspec/templates/rcov.opts +2 -0
- data/generators/rspec/templates/rspec.rake +177 -0
- data/generators/rspec/templates/script/autospec +5 -0
- data/generators/rspec/templates/script/spec +4 -0
- data/generators/rspec/templates/script/spec_server +37 -0
- data/generators/rspec/templates/spec.opts +4 -0
- data/generators/rspec/templates/spec_helper.rb +47 -0
- data/generators/rspec_controller/USAGE +33 -0
- data/generators/rspec_controller/rspec_controller_generator.rb +45 -0
- data/generators/rspec_controller/templates/controller_spec.rb +25 -0
- data/generators/rspec_controller/templates/helper_spec.rb +11 -0
- data/generators/rspec_controller/templates/view_spec.rb +12 -0
- data/generators/rspec_default_values.rb +19 -0
- data/generators/rspec_model/USAGE +18 -0
- data/generators/rspec_model/rspec_model_generator.rb +35 -0
- data/generators/rspec_model/templates/model_spec.rb +15 -0
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +150 -0
- data/generators/rspec_scaffold/templates/controller_spec.rb +171 -0
- data/generators/rspec_scaffold/templates/edit_erb_spec.rb +27 -0
- data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
- data/generators/rspec_scaffold/templates/index_erb_spec.rb +28 -0
- data/generators/rspec_scaffold/templates/new_erb_spec.rb +27 -0
- data/generators/rspec_scaffold/templates/routing_spec.rb +63 -0
- data/generators/rspec_scaffold/templates/show_erb_spec.rb +23 -0
- data/init.rb +9 -0
- data/lib/autotest/discover.rb +1 -0
- data/lib/autotest/rails_rspec.rb +76 -0
- data/lib/spec/rails.rb +37 -0
- data/lib/spec/rails/example.rb +53 -0
- data/lib/spec/rails/example/assigns_hash_proxy.rb +39 -0
- data/lib/spec/rails/example/controller_example_group.rb +242 -0
- data/lib/spec/rails/example/cookies_proxy.rb +29 -0
- data/lib/spec/rails/example/functional_example_group.rb +84 -0
- data/lib/spec/rails/example/helper_example_group.rb +167 -0
- data/lib/spec/rails/example/model_example_group.rb +14 -0
- data/lib/spec/rails/example/render_observer.rb +67 -0
- data/lib/spec/rails/example/routing_helpers.rb +68 -0
- data/lib/spec/rails/example/view_example_group.rb +186 -0
- data/lib/spec/rails/extensions.rb +15 -0
- data/lib/spec/rails/extensions/action_controller/rescue.rb +42 -0
- data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
- data/lib/spec/rails/extensions/action_controller/test_response.rb +21 -0
- data/lib/spec/rails/extensions/action_view/base.rb +33 -0
- data/lib/spec/rails/extensions/active_record/base.rb +43 -0
- data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
- data/lib/spec/rails/extensions/spec/matchers/have.rb +23 -0
- data/lib/spec/rails/extensions/spec/runner/configuration.rb +48 -0
- data/lib/spec/rails/interop/testcase.rb +14 -0
- data/lib/spec/rails/matchers.rb +40 -0
- data/lib/spec/rails/matchers/ar_be_valid.rb +44 -0
- data/lib/spec/rails/matchers/assert_select.rb +131 -0
- data/lib/spec/rails/matchers/change.rb +11 -0
- data/lib/spec/rails/matchers/have_text.rb +57 -0
- data/lib/spec/rails/matchers/include_text.rb +54 -0
- data/lib/spec/rails/matchers/redirect_to.rb +126 -0
- data/lib/spec/rails/matchers/render_template.rb +114 -0
- data/lib/spec/rails/mocks.rb +135 -0
- data/lib/spec/rails/spec_server.rb +97 -0
- data/lib/spec/rails/story_adapter.rb +79 -0
- data/lib/spec/rails/version.rb +16 -0
- data/rspec-rails.gemspec +39 -0
- data/spec/autotest/mappings_spec.rb +36 -0
- data/spec/rails_suite.rb +7 -0
- data/spec/resources/controllers/action_view_base_spec_controller.rb +2 -0
- data/spec/resources/controllers/application.rb +9 -0
- data/spec/resources/controllers/controller_spec_controller.rb +116 -0
- data/spec/resources/controllers/redirect_spec_controller.rb +70 -0
- data/spec/resources/controllers/render_spec_controller.rb +30 -0
- data/spec/resources/controllers/rjs_spec_controller.rb +58 -0
- data/spec/resources/helpers/addition_helper.rb +5 -0
- data/spec/resources/helpers/explicit_helper.rb +46 -0
- data/spec/resources/helpers/more_explicit_helper.rb +5 -0
- data/spec/resources/helpers/plugin_application_helper.rb +6 -0
- data/spec/resources/helpers/view_spec_helper.rb +13 -0
- data/spec/resources/models/animal.rb +4 -0
- data/spec/resources/models/person.rb +18 -0
- data/spec/resources/models/thing.rb +3 -0
- data/spec/resources/views/controller_spec/_partial.rhtml +0 -0
- data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.rhtml +1 -0
- data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.rhtml +1 -0
- data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.rhtml +0 -0
- data/spec/resources/views/controller_spec/action_with_errors_in_template.rhtml +1 -0
- data/spec/resources/views/controller_spec/action_with_template.rhtml +1 -0
- data/spec/resources/views/layouts/application.rhtml +0 -0
- data/spec/resources/views/layouts/simple.rhtml +0 -0
- data/spec/resources/views/objects/_object.html.erb +1 -0
- data/spec/resources/views/render_spec/_a_partial.rhtml +0 -0
- data/spec/resources/views/render_spec/action_with_alternate_layout.rhtml +0 -0
- data/spec/resources/views/render_spec/some_action.html.erb +0 -0
- data/spec/resources/views/render_spec/some_action.js.rjs +1 -0
- data/spec/resources/views/render_spec/some_action.rjs +1 -0
- data/spec/resources/views/rjs_spec/_replacement_partial.rhtml +1 -0
- data/spec/resources/views/rjs_spec/hide_div.rjs +1 -0
- data/spec/resources/views/rjs_spec/hide_page_element.rjs +1 -0
- data/spec/resources/views/rjs_spec/insert_html.rjs +1 -0
- data/spec/resources/views/rjs_spec/replace.rjs +1 -0
- data/spec/resources/views/rjs_spec/replace_html.rjs +1 -0
- data/spec/resources/views/rjs_spec/replace_html_with_partial.rjs +1 -0
- data/spec/resources/views/rjs_spec/visual_effect.rjs +1 -0
- data/spec/resources/views/rjs_spec/visual_toggle_effect.rjs +1 -0
- data/spec/resources/views/tag_spec/no_tags.rhtml +1 -0
- data/spec/resources/views/tag_spec/single_div_with_no_attributes.rhtml +1 -0
- data/spec/resources/views/tag_spec/single_div_with_one_attribute.rhtml +1 -0
- data/spec/resources/views/view_spec/_partial.rhtml +2 -0
- data/spec/resources/views/view_spec/_partial_used_twice.rhtml +0 -0
- data/spec/resources/views/view_spec/_partial_with_local_variable.rhtml +1 -0
- data/spec/resources/views/view_spec/_partial_with_sub_partial.rhtml +1 -0
- data/spec/resources/views/view_spec/_spacer.rhtml +1 -0
- data/spec/resources/views/view_spec/accessor.rhtml +5 -0
- data/spec/resources/views/view_spec/block_helper.rhtml +3 -0
- data/spec/resources/views/view_spec/entry_form.rhtml +2 -0
- data/spec/resources/views/view_spec/explicit_helper.rhtml +2 -0
- data/spec/resources/views/view_spec/foo/show.rhtml +1 -0
- data/spec/resources/views/view_spec/implicit_helper.rhtml +2 -0
- data/spec/resources/views/view_spec/multiple_helpers.rhtml +3 -0
- data/spec/resources/views/view_spec/path_params.html.erb +1 -0
- data/spec/resources/views/view_spec/should_not_receive.rhtml +3 -0
- data/spec/resources/views/view_spec/template_with_partial.rhtml +5 -0
- data/spec/resources/views/view_spec/template_with_partial_using_collection.rhtml +3 -0
- data/spec/resources/views/view_spec/template_with_partial_with_array.rhtml +1 -0
- data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +109 -0
- data/spec/spec/rails/example/configuration_spec.rb +65 -0
- data/spec/spec/rails/example/controller_example_group_spec.rb +275 -0
- data/spec/spec/rails/example/controller_isolation_spec.rb +56 -0
- data/spec/spec/rails/example/cookies_proxy_spec.rb +87 -0
- data/spec/spec/rails/example/error_handling_spec.rb +90 -0
- data/spec/spec/rails/example/example_group_factory_spec.rb +112 -0
- data/spec/spec/rails/example/helper_example_group_spec.rb +206 -0
- data/spec/spec/rails/example/model_example_group_spec.rb +20 -0
- data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
- data/spec/spec/rails/example/view_example_group_spec.rb +335 -0
- data/spec/spec/rails/extensions/action_view_base_spec.rb +48 -0
- data/spec/spec/rails/extensions/active_record_spec.rb +14 -0
- data/spec/spec/rails/interop/testcase_spec.rb +70 -0
- data/spec/spec/rails/matchers/ar_be_valid_spec.rb +45 -0
- data/spec/spec/rails/matchers/assert_select_spec.rb +811 -0
- data/spec/spec/rails/matchers/errors_on_spec.rb +25 -0
- data/spec/spec/rails/matchers/have_text_spec.rb +70 -0
- data/spec/spec/rails/matchers/include_text_spec.rb +62 -0
- data/spec/spec/rails/matchers/redirect_to_spec.rb +253 -0
- data/spec/spec/rails/matchers/render_template_spec.rb +183 -0
- data/spec/spec/rails/matchers/should_change_spec.rb +15 -0
- data/spec/spec/rails/mocks/ar_classes.rb +10 -0
- data/spec/spec/rails/mocks/mock_model_spec.rb +106 -0
- data/spec/spec/rails/mocks/stub_model_spec.rb +80 -0
- data/spec/spec/rails/sample_modified_fixture.rb +8 -0
- data/spec/spec/rails/sample_spec.rb +8 -0
- data/spec/spec/rails/spec_server_spec.rb +107 -0
- data/spec/spec/rails/spec_spec.rb +11 -0
- data/spec/spec_helper.rb +78 -0
- metadata +262 -0
@@ -0,0 +1,335 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
+
|
3
|
+
describe "A template with an implicit helper", :type => :view do
|
4
|
+
before(:each) do
|
5
|
+
render "view_spec/implicit_helper"
|
6
|
+
end
|
7
|
+
|
8
|
+
accesses_configured_helper_methods
|
9
|
+
|
10
|
+
it "should include the helper" do
|
11
|
+
response.should have_tag('div', :content => "This is text from a method in the ViewSpecHelper")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should include the application helper" do
|
15
|
+
response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have access to named routes" do
|
19
|
+
rspec_on_rails_specs_url.should == "http://test.host/rspec_on_rails_specs"
|
20
|
+
rspec_on_rails_specs_path.should == "/rspec_on_rails_specs"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "A template requiring an explicit helper", :type => :view do
|
25
|
+
before(:each) do
|
26
|
+
render "view_spec/explicit_helper", :helper => 'explicit'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should include the helper if specified" do
|
30
|
+
response.should have_tag('div', :content => "This is text from a method in the ExplicitHelper")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should include the application helper" do
|
34
|
+
response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "A template requiring multiple explicit helpers", :type => :view do
|
39
|
+
before(:each) do
|
40
|
+
render "view_spec/multiple_helpers", :helpers => ['explicit', 'more_explicit']
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should include all specified helpers" do
|
44
|
+
response.should have_tag('div', :content => "This is text from a method in the ExplicitHelper")
|
45
|
+
response.should have_tag('div', :content => "This is text from a method in the MoreExplicitHelper")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should include the application helper" do
|
49
|
+
response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "Message Expectations on helper methods", :type => :view do
|
54
|
+
it "should work" do
|
55
|
+
template.should_receive(:method_in_plugin_application_helper).and_return('alternate message 1')
|
56
|
+
render "view_spec/implicit_helper"
|
57
|
+
response.body.should =~ /alternate message 1/
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should work twice" do
|
61
|
+
template.should_receive(:method_in_plugin_application_helper).and_return('alternate message 2')
|
62
|
+
render "view_spec/implicit_helper"
|
63
|
+
response.body.should =~ /alternate message 2/
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "A template that includes a partial", :type => :view do
|
68
|
+
def render!
|
69
|
+
render "view_spec/template_with_partial"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should render the enclosing template" do
|
73
|
+
render!
|
74
|
+
response.should have_tag('div', "method_in_partial in ViewSpecHelper")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should render the partial" do
|
78
|
+
render!
|
79
|
+
response.should have_tag('div', "method_in_template_with_partial in ViewSpecHelper")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should include the application helper" do
|
83
|
+
render!
|
84
|
+
response.should have_tag('div', "This is text from a method in the ApplicationHelper")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should pass should_receive(:render) with the right partial" do
|
88
|
+
template.should_receive(:render).with(:partial => 'partial')
|
89
|
+
render!
|
90
|
+
template.verify_rendered
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should fail should_receive(:render) with the wrong partial" do
|
94
|
+
template.should_receive(:render).with(:partial => 'non_existent')
|
95
|
+
render!
|
96
|
+
begin
|
97
|
+
template.verify_rendered
|
98
|
+
rescue Spec::Mocks::MockExpectationError => e
|
99
|
+
ensure
|
100
|
+
e.backtrace.find{|line| line =~ /#{__FILE__}\:#{__LINE__ - 6}/}.should_not be_nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should pass should_receive(:render) when a partial is expected twice and happens twice" do
|
105
|
+
template.should_receive(:render).with(:partial => 'partial_used_twice').twice
|
106
|
+
render!
|
107
|
+
template.verify_rendered
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should pass should_receive(:render) when a partial is expected once and happens twice" do
|
111
|
+
template.should_receive(:render).with(:partial => 'partial_used_twice')
|
112
|
+
render!
|
113
|
+
begin
|
114
|
+
template.verify_rendered
|
115
|
+
rescue Spec::Mocks::MockExpectationError => e
|
116
|
+
ensure
|
117
|
+
e.backtrace.find{|line| line =~ /#{__FILE__}\:#{__LINE__ - 6}/}.should_not be_nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should fail should_receive(:render) with the right partial but wrong options" do
|
122
|
+
template.should_receive(:render).with(:partial => 'partial', :locals => {:thing => Object.new})
|
123
|
+
render!
|
124
|
+
lambda {template.verify_rendered}.should raise_error(Spec::Mocks::MockExpectationError)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "A partial that includes a partial", :type => :view do
|
129
|
+
it "should support should_receive(:render) with nested partial" do
|
130
|
+
obj = Object.new
|
131
|
+
template.should_receive(:render).with(:partial => 'partial', :object => obj)
|
132
|
+
render :partial => "view_spec/partial_with_sub_partial", :locals => { :partial => obj }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "A view that includes a partial using :collection and :spacer_template", :type => :view do
|
137
|
+
it "should render the partial w/ spacer_tamplate" do
|
138
|
+
render "view_spec/template_with_partial_using_collection"
|
139
|
+
response.should have_tag('div',/method_in_partial/)
|
140
|
+
response.should have_tag('div',/ApplicationHelper/)
|
141
|
+
response.should have_tag('div',/ViewSpecHelper/)
|
142
|
+
response.should have_tag('hr#spacer')
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should render the partial" do
|
146
|
+
template.should_receive(:render).with(:partial => 'partial',
|
147
|
+
:collection => ['Alice', 'Bob'],
|
148
|
+
:spacer_template => 'spacer')
|
149
|
+
render "view_spec/template_with_partial_using_collection"
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "A view that includes a partial using an array as partial_path", :type => :view do
|
155
|
+
before(:each) do
|
156
|
+
renderable_object = Object.new
|
157
|
+
renderable_object.stub!(:name).and_return("Renderable Object")
|
158
|
+
assigns[:array] = [renderable_object]
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should render the array passed through to render_partial without modification" do
|
162
|
+
render "view_spec/template_with_partial_with_array"
|
163
|
+
response.body.should match(/^Renderable Object$/)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "Different types of renders (not :template)", :type => :view do
|
168
|
+
it "should render partial with local" do
|
169
|
+
render :partial => "view_spec/partial_with_local_variable", :locals => {:x => "Ender"}
|
170
|
+
response.should have_tag('div', :content => "Ender")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "A view", :type => :view do
|
175
|
+
before(:each) do
|
176
|
+
session[:key] = "session"
|
177
|
+
params[:key] = "params"
|
178
|
+
flash[:key] = "flash"
|
179
|
+
render "view_spec/accessor"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should use the template as the implicit subject" do
|
183
|
+
subject.should == template
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "with a specified subject" do
|
187
|
+
subject { 'specified' }
|
188
|
+
|
189
|
+
it "should use the specified subject" do
|
190
|
+
subject.should == 'specified'
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should have access to session data" do
|
195
|
+
response.should have_tag("div#session", "session")
|
196
|
+
end
|
197
|
+
|
198
|
+
specify "should have access to params data" do
|
199
|
+
response.should have_tag("div#params", "params")
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should have access to flash data" do
|
203
|
+
response.should have_tag("div#flash", "flash")
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should have a controller param" do
|
207
|
+
response.should have_tag("div#controller", "view_spec")
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should have an action param" do
|
211
|
+
response.should have_tag("div#action", "accessor")
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "A view with a form_tag", :type => :view do
|
216
|
+
it "should render the right action" do
|
217
|
+
render "view_spec/entry_form"
|
218
|
+
response.should have_tag("form[action=?]","/view_spec/entry_form")
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "An instantiated ViewExampleGroupController", :type => :view do
|
223
|
+
before do
|
224
|
+
render "view_spec/foo/show"
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should return the name of the real controller that it replaces" do
|
228
|
+
@controller.controller_name.should == 'foo'
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should return the path of the real controller that it replaces" do
|
232
|
+
@controller.controller_path.should == 'view_spec/foo'
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "a block helper", :type => :view do
|
237
|
+
it "should not yield when not told to in the example" do
|
238
|
+
template.should_receive(:if_allowed)
|
239
|
+
render "view_spec/block_helper"
|
240
|
+
response.should_not have_tag("div","block helper was rendered")
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should yield when told to in the example" do
|
244
|
+
template.should_receive(:if_allowed).and_yield
|
245
|
+
render "view_spec/block_helper"
|
246
|
+
response.should have_tag("div","block helper was rendered")
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe "render :inline => ...", :type => :view do
|
251
|
+
it "should render ERB right in the spec" do
|
252
|
+
render :inline => %|<%= text_field_tag('field_name', 'Value') %>|
|
253
|
+
response.should have_tag("input[type=?][name=?][value=?]","text","field_name","Value")
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "render 'view_spec/foo/show.rhtml'", :type => :view do
|
258
|
+
it "should derive action name using the first part of the template name" do
|
259
|
+
render 'view_spec/foo/show.rhtml'
|
260
|
+
request.path_parameters[:action].should == 'show'
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "view_spec/foo/show.rhtml", :type => :view do
|
265
|
+
context "rendered with no args" do
|
266
|
+
it "renders just fine" do
|
267
|
+
render
|
268
|
+
request.path_parameters[:action].should == 'show'
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
describe "setting path parameters", :type => :view do
|
274
|
+
describe "(controller)" do
|
275
|
+
it "should supercede the default path parameters" do
|
276
|
+
render "view_spec/entry_form", :path_parameters => {:controller => 'foo'}
|
277
|
+
request.path_parameters[:controller].should == 'foo'
|
278
|
+
end
|
279
|
+
end
|
280
|
+
describe "(action)" do
|
281
|
+
it "should supercede the default path parameters" do
|
282
|
+
render "view_spec/entry_form", :path_parameters => {:action => 'foo'}
|
283
|
+
request.path_parameters[:action].should == 'foo'
|
284
|
+
end
|
285
|
+
end
|
286
|
+
describe "(something arbitrary)" do
|
287
|
+
it "should supercede the default path parameters" do
|
288
|
+
render "view_spec/entry_form", :path_parameters => {:foo => 'bar'}
|
289
|
+
request.path_parameters[:foo].should == 'bar'
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
describe "route helpers", :type => :view do
|
295
|
+
it "should be available before render is called" do
|
296
|
+
custom_route_path.should == '/custom_route'
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
module Spec
|
301
|
+
module Rails
|
302
|
+
module Example
|
303
|
+
describe ViewExampleGroup do
|
304
|
+
it "should clear its name from the description" do
|
305
|
+
group = describe("foo", :type => :view) do
|
306
|
+
$nested_group = describe("bar") do
|
307
|
+
end
|
308
|
+
end
|
309
|
+
group.description.to_s.should == "foo"
|
310
|
+
$nested_group.description.to_s.should == "foo bar"
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should clear ActionView::Base.base_view_path on teardown" do
|
314
|
+
group = describe("base_view_path_cleared flag", :type => :view) {}
|
315
|
+
example = group.new("example",{}) {}
|
316
|
+
|
317
|
+
ActionView::Base.should_receive(:base_view_path=).with(nil)
|
318
|
+
example.run_after_each
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
describe "bug http://rspec.lighthouseapp.com/projects/5645/tickets/510", :type => :view do
|
326
|
+
describe "a view example with should_not_receive" do
|
327
|
+
it "should render the view" do
|
328
|
+
obj = mock('model')
|
329
|
+
obj.should_receive(:render_partial?).and_return false
|
330
|
+
assigns[:obj] = obj
|
331
|
+
template.should_not_receive(:render).with(:partial => 'some_partial')
|
332
|
+
render "view_spec/should_not_receive"
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
+
require 'spec/mocks/errors'
|
3
|
+
|
4
|
+
describe ActionView::Base, "with RSpec extensions:", :type => :view do
|
5
|
+
|
6
|
+
describe "should_receive(:render)" do
|
7
|
+
it "should not raise when render has been received" do
|
8
|
+
template.should_receive(:render).with(:partial => "name")
|
9
|
+
template.render :partial => "name"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise when render has NOT been received" do
|
13
|
+
template.should_receive(:render).with(:partial => "name")
|
14
|
+
lambda {
|
15
|
+
template.verify_rendered
|
16
|
+
}.should raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return something (like a normal mock)" do
|
20
|
+
template.should_receive(:render).with(:partial => "name").and_return("Little Johnny")
|
21
|
+
result = template.render :partial => "name"
|
22
|
+
result.should == "Little Johnny"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "stub!(:render)" do
|
27
|
+
it "should not raise when stubbing and render has been received" do
|
28
|
+
template.stub!(:render).with(:partial => "name")
|
29
|
+
template.render :partial => "name"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not raise when stubbing and render has NOT been received" do
|
33
|
+
template.stub!(:render).with(:partial => "name")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not raise when stubbing and render has been received with different options" do
|
37
|
+
template.stub!(:render).with(:partial => "name")
|
38
|
+
template.render :partial => "view_spec/spacer"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not raise when stubbing and expecting and render has been received" do
|
42
|
+
template.stub!(:render).with(:partial => "name")
|
43
|
+
template.should_receive(:render).with(:partial => "name")
|
44
|
+
template.render(:partial => "name")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
+
|
3
|
+
describe "A model" do
|
4
|
+
fixtures :things
|
5
|
+
it "should tell you its required fields" do
|
6
|
+
Thing.new.should have(1).error_on(:name)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should tell you how many records it has" do
|
10
|
+
Thing.should have(:no).records
|
11
|
+
Thing.create(:name => "THE THING")
|
12
|
+
Thing.should have(1).record
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
if ActiveSupport.const_defined?(:Callbacks) && Test::Unit::TestCase.include?(ActiveSupport::Callbacks)
|
5
|
+
|
6
|
+
class TestUnitTesting < Test::Unit::TestCase
|
7
|
+
@@setup_callback_count = 0
|
8
|
+
@@setup_method_count = 0
|
9
|
+
@@teardown_callback_count = 0
|
10
|
+
@@teardown_method_count = 0
|
11
|
+
cattr_accessor :setup_callback_count, :setup_method_count, :teardown_callback_count, :teardown_method_count
|
12
|
+
|
13
|
+
setup :do_some_setup
|
14
|
+
teardown :do_some_teardown
|
15
|
+
|
16
|
+
@@has_been_run = false
|
17
|
+
def self.run?
|
18
|
+
@@has_been_run
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.run(options=Spec::Runner.options)
|
22
|
+
super options
|
23
|
+
end
|
24
|
+
|
25
|
+
def do_some_setup
|
26
|
+
@@setup_callback_count += 1
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup
|
30
|
+
@@setup_method_count += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_something
|
34
|
+
assert_equal true, true
|
35
|
+
@@has_been_run = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
@@teardown_method_count += 1
|
40
|
+
end
|
41
|
+
|
42
|
+
def do_some_teardown
|
43
|
+
@@teardown_callback_count += 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Test
|
48
|
+
module Unit
|
49
|
+
describe "Running TestCase tests" do
|
50
|
+
before(:all) do
|
51
|
+
TestUnitTesting.run unless TestUnitTesting.run?
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should call the setup callbacks" do
|
55
|
+
TestUnitTesting.setup_callback_count.should == 1
|
56
|
+
end
|
57
|
+
it "should still only call the normal setup method once" do
|
58
|
+
TestUnitTesting.setup_method_count.should == 1
|
59
|
+
end
|
60
|
+
it "should call the teardown callbacks" do
|
61
|
+
TestUnitTesting.teardown_callback_count.should == 1
|
62
|
+
end
|
63
|
+
it "should still only call the normal teardown method once" do
|
64
|
+
TestUnitTesting.teardown_method_count.should == 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|