rspec-rails 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/History.txt +57 -0
  2. data/Manifest.txt +158 -0
  3. data/README.txt +81 -0
  4. data/Rakefile +39 -0
  5. data/UPGRADE +7 -0
  6. data/generators/rspec/CHANGES +1 -0
  7. data/generators/rspec/rspec_generator.rb +40 -0
  8. data/generators/rspec/templates/all_stories.rb +4 -0
  9. data/generators/rspec/templates/previous_failures.txt +0 -0
  10. data/generators/rspec/templates/rcov.opts +2 -0
  11. data/generators/rspec/templates/rspec.rake +132 -0
  12. data/generators/rspec/templates/script/autospec +3 -0
  13. data/generators/rspec/templates/script/spec +4 -0
  14. data/generators/rspec/templates/script/spec_server +116 -0
  15. data/generators/rspec/templates/spec.opts +4 -0
  16. data/generators/rspec/templates/spec_helper.rb +47 -0
  17. data/generators/rspec/templates/stories_helper.rb +3 -0
  18. data/generators/rspec_controller/USAGE +33 -0
  19. data/generators/rspec_controller/rspec_controller_generator.rb +49 -0
  20. data/generators/rspec_controller/templates/controller_spec.rb +25 -0
  21. data/generators/rspec_controller/templates/helper_spec.rb +11 -0
  22. data/generators/rspec_controller/templates/view_spec.rb +12 -0
  23. data/generators/rspec_default_values.rb +19 -0
  24. data/generators/rspec_model/USAGE +18 -0
  25. data/generators/rspec_model/rspec_model_generator.rb +35 -0
  26. data/generators/rspec_model/templates/model_spec.rb +15 -0
  27. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +154 -0
  28. data/generators/rspec_scaffold/templates/controller_spec.rb +173 -0
  29. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +26 -0
  30. data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
  31. data/generators/rspec_scaffold/templates/index_erb_spec.rb +27 -0
  32. data/generators/rspec_scaffold/templates/new_erb_spec.rb +26 -0
  33. data/generators/rspec_scaffold/templates/routing_spec.rb +59 -0
  34. data/generators/rspec_scaffold/templates/show_erb_spec.rb +23 -0
  35. data/init.rb +9 -0
  36. data/lib/autotest/discover.rb +1 -0
  37. data/lib/autotest/rails_rspec.rb +76 -0
  38. data/lib/spec/rails.rb +15 -0
  39. data/lib/spec/rails/example.rb +47 -0
  40. data/lib/spec/rails/example/assigns_hash_proxy.rb +43 -0
  41. data/lib/spec/rails/example/controller_example_group.rb +256 -0
  42. data/lib/spec/rails/example/cookies_proxy.rb +25 -0
  43. data/lib/spec/rails/example/functional_example_group.rb +87 -0
  44. data/lib/spec/rails/example/helper_example_group.rb +166 -0
  45. data/lib/spec/rails/example/model_example_group.rb +14 -0
  46. data/lib/spec/rails/example/rails_example_group.rb +33 -0
  47. data/lib/spec/rails/example/render_observer.rb +93 -0
  48. data/lib/spec/rails/example/view_example_group.rb +183 -0
  49. data/lib/spec/rails/extensions.rb +12 -0
  50. data/lib/spec/rails/extensions/action_controller/base.rb +14 -0
  51. data/lib/spec/rails/extensions/action_controller/rescue.rb +21 -0
  52. data/lib/spec/rails/extensions/action_controller/test_response.rb +11 -0
  53. data/lib/spec/rails/extensions/action_view/base.rb +31 -0
  54. data/lib/spec/rails/extensions/active_record/base.rb +30 -0
  55. data/lib/spec/rails/extensions/object.rb +5 -0
  56. data/lib/spec/rails/extensions/spec/example/configuration.rb +71 -0
  57. data/lib/spec/rails/extensions/spec/matchers/have.rb +21 -0
  58. data/lib/spec/rails/interop/testcase.rb +14 -0
  59. data/lib/spec/rails/matchers.rb +31 -0
  60. data/lib/spec/rails/matchers/assert_select.rb +131 -0
  61. data/lib/spec/rails/matchers/change.rb +11 -0
  62. data/lib/spec/rails/matchers/have_text.rb +57 -0
  63. data/lib/spec/rails/matchers/include_text.rb +54 -0
  64. data/lib/spec/rails/matchers/redirect_to.rb +113 -0
  65. data/lib/spec/rails/matchers/render_template.rb +90 -0
  66. data/lib/spec/rails/mocks.rb +132 -0
  67. data/lib/spec/rails/story_adapter.rb +79 -0
  68. data/lib/spec/rails/version.rb +15 -0
  69. data/spec/rails/autotest/mappings_spec.rb +36 -0
  70. data/spec/rails/example/assigns_hash_proxy_spec.rb +65 -0
  71. data/spec/rails/example/configuration_spec.rb +83 -0
  72. data/spec/rails/example/controller_isolation_spec.rb +62 -0
  73. data/spec/rails/example/controller_spec_spec.rb +272 -0
  74. data/spec/rails/example/cookies_proxy_spec.rb +74 -0
  75. data/spec/rails/example/example_group_factory_spec.rb +112 -0
  76. data/spec/rails/example/helper_spec_spec.rb +161 -0
  77. data/spec/rails/example/model_spec_spec.rb +18 -0
  78. data/spec/rails/example/shared_behaviour_spec.rb +16 -0
  79. data/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
  80. data/spec/rails/example/view_spec_spec.rb +280 -0
  81. data/spec/rails/extensions/action_controller_rescue_action_spec.rb +54 -0
  82. data/spec/rails/extensions/action_view_base_spec.rb +48 -0
  83. data/spec/rails/extensions/active_record_spec.rb +14 -0
  84. data/spec/rails/interop/testcase_spec.rb +66 -0
  85. data/spec/rails/matchers/assert_select_spec.rb +814 -0
  86. data/spec/rails/matchers/description_generation_spec.rb +37 -0
  87. data/spec/rails/matchers/errors_on_spec.rb +13 -0
  88. data/spec/rails/matchers/have_text_spec.rb +62 -0
  89. data/spec/rails/matchers/include_text_spec.rb +64 -0
  90. data/spec/rails/matchers/redirect_to_spec.rb +209 -0
  91. data/spec/rails/matchers/render_template_spec.rb +176 -0
  92. data/spec/rails/matchers/should_change_spec.rb +15 -0
  93. data/spec/rails/mocks/ar_classes.rb +10 -0
  94. data/spec/rails/mocks/mock_model_spec.rb +106 -0
  95. data/spec/rails/mocks/stub_model_spec.rb +80 -0
  96. data/spec/rails/sample_modified_fixture.rb +8 -0
  97. data/spec/rails/sample_spec.rb +8 -0
  98. data/spec/rails/spec_server_spec.rb +96 -0
  99. data/spec/rails/spec_spec.rb +11 -0
  100. data/spec/rails_suite.rb +7 -0
  101. data/spec/spec_helper.rb +57 -0
  102. data/spec_resources/controllers/action_view_base_spec_controller.rb +2 -0
  103. data/spec_resources/controllers/controller_spec_controller.rb +94 -0
  104. data/spec_resources/controllers/redirect_spec_controller.rb +59 -0
  105. data/spec_resources/controllers/render_spec_controller.rb +30 -0
  106. data/spec_resources/controllers/rjs_spec_controller.rb +58 -0
  107. data/spec_resources/helpers/explicit_helper.rb +38 -0
  108. data/spec_resources/helpers/more_explicit_helper.rb +5 -0
  109. data/spec_resources/helpers/plugin_application_helper.rb +6 -0
  110. data/spec_resources/helpers/view_spec_helper.rb +13 -0
  111. data/spec_resources/views/controller_spec/_partial.rhtml +0 -0
  112. data/spec_resources/views/controller_spec/action_setting_flash_after_session_reset.rhtml +1 -0
  113. data/spec_resources/views/controller_spec/action_setting_flash_before_session_reset.rhtml +1 -0
  114. data/spec_resources/views/controller_spec/action_setting_the_assigns_hash.rhtml +0 -0
  115. data/spec_resources/views/controller_spec/action_with_errors_in_template.rhtml +1 -0
  116. data/spec_resources/views/controller_spec/action_with_template.rhtml +1 -0
  117. data/spec_resources/views/layouts/application.rhtml +0 -0
  118. data/spec_resources/views/layouts/simple.rhtml +0 -0
  119. data/spec_resources/views/objects/_object.html.erb +1 -0
  120. data/spec_resources/views/render_spec/_a_partial.rhtml +0 -0
  121. data/spec_resources/views/render_spec/action_with_alternate_layout.rhtml +0 -0
  122. data/spec_resources/views/render_spec/some_action.js.rjs +1 -0
  123. data/spec_resources/views/render_spec/some_action.rhtml +0 -0
  124. data/spec_resources/views/render_spec/some_action.rjs +1 -0
  125. data/spec_resources/views/rjs_spec/_replacement_partial.rhtml +1 -0
  126. data/spec_resources/views/rjs_spec/hide_div.rjs +1 -0
  127. data/spec_resources/views/rjs_spec/hide_page_element.rjs +1 -0
  128. data/spec_resources/views/rjs_spec/insert_html.rjs +1 -0
  129. data/spec_resources/views/rjs_spec/replace.rjs +1 -0
  130. data/spec_resources/views/rjs_spec/replace_html.rjs +1 -0
  131. data/spec_resources/views/rjs_spec/replace_html_with_partial.rjs +1 -0
  132. data/spec_resources/views/rjs_spec/visual_effect.rjs +1 -0
  133. data/spec_resources/views/rjs_spec/visual_toggle_effect.rjs +1 -0
  134. data/spec_resources/views/tag_spec/no_tags.rhtml +1 -0
  135. data/spec_resources/views/tag_spec/single_div_with_no_attributes.rhtml +1 -0
  136. data/spec_resources/views/tag_spec/single_div_with_one_attribute.rhtml +1 -0
  137. data/spec_resources/views/view_spec/_partial.rhtml +2 -0
  138. data/spec_resources/views/view_spec/_partial_used_twice.rhtml +0 -0
  139. data/spec_resources/views/view_spec/_partial_with_local_variable.rhtml +1 -0
  140. data/spec_resources/views/view_spec/_partial_with_sub_partial.rhtml +1 -0
  141. data/spec_resources/views/view_spec/_spacer.rhtml +1 -0
  142. data/spec_resources/views/view_spec/accessor.rhtml +5 -0
  143. data/spec_resources/views/view_spec/block_helper.rhtml +3 -0
  144. data/spec_resources/views/view_spec/entry_form.rhtml +2 -0
  145. data/spec_resources/views/view_spec/explicit_helper.rhtml +2 -0
  146. data/spec_resources/views/view_spec/foo/show.rhtml +1 -0
  147. data/spec_resources/views/view_spec/implicit_helper.rhtml +2 -0
  148. data/spec_resources/views/view_spec/multiple_helpers.rhtml +3 -0
  149. data/spec_resources/views/view_spec/should_not_receive.rhtml +3 -0
  150. data/spec_resources/views/view_spec/template_with_partial.rhtml +5 -0
  151. data/spec_resources/views/view_spec/template_with_partial_using_collection.rhtml +3 -0
  152. data/spec_resources/views/view_spec/template_with_partial_with_array.rhtml +1 -0
  153. data/stories/all.rb +10 -0
  154. data/stories/configuration/stories.rb +5 -0
  155. data/stories/helper.rb +6 -0
  156. data/stories/steps/people.rb +8 -0
  157. data/stories/transactions_should_rollback +15 -0
  158. data/stories/transactions_should_rollback.rb +25 -0
  159. metadata +234 -0
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ class DescriptionGenerationSpecController < ActionController::Base
4
+ def render_action
5
+ end
6
+
7
+ def redirect_action
8
+ redirect_to :action => :render_action
9
+ end
10
+ end
11
+
12
+ describe "Description generation", :type => :controller do
13
+ controller_name :description_generation_spec
14
+
15
+ after(:each) do
16
+ Spec::Matchers.clear_generated_description
17
+ end
18
+
19
+ it "should generate description for render_template" do
20
+ get 'render_action'
21
+ response.should render_template("render_action")
22
+ Spec::Matchers.generated_description.should == "should render template \"render_action\""
23
+ end
24
+
25
+ it "should generate description for render_template with full path" do
26
+ get 'render_action'
27
+ response.should render_template("description_generation_spec/render_action")
28
+ Spec::Matchers.generated_description.should == "should render template \"description_generation_spec/render_action\""
29
+ end
30
+
31
+ it "should generate description for redirect_to" do
32
+ get 'redirect_action'
33
+ response.should redirect_to("http://test.host/description_generation_spec/render_action")
34
+ Spec::Matchers.generated_description.should == "should redirect to \"http://test.host/description_generation_spec/render_action\""
35
+ end
36
+
37
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "error_on" do
4
+ it "should provide a message including the name of what the error is on" do
5
+ have(1).error_on(:whatever).description.should == "should have 1 error on :whatever"
6
+ end
7
+ end
8
+
9
+ describe "errors_on" do
10
+ it "should provide a message including the name of what the error is on" do
11
+ have(2).errors_on(:whatever).description.should == "should have 2 errors on :whatever"
12
+ end
13
+ end
@@ -0,0 +1,62 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "have_text" do
4
+
5
+ describe "where target is a Regexp" do
6
+ it 'should should match submitted text using a regexp' do
7
+ string = 'foo'
8
+ string.should have_text(/fo*/)
9
+ end
10
+ end
11
+
12
+ describe "where target is a String" do
13
+ it 'should match submitted text using a string' do
14
+ string = 'foo'
15
+ string.should have_text('foo')
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ describe "have_text",
22
+ :type => :controller do
23
+ ['isolation','integration'].each do |mode|
24
+ if mode == 'integration'
25
+ integrate_views
26
+ end
27
+
28
+ describe "where target is a response (in #{mode} mode)" do
29
+ controller_name :render_spec
30
+
31
+ it "should pass with exactly matching text" do
32
+ post 'text_action'
33
+ response.should have_text("this is the text for this action")
34
+ end
35
+
36
+ it "should pass with matching text (using Regexp)" do
37
+ post 'text_action'
38
+ response.should have_text(/is the text/)
39
+ end
40
+
41
+ it "should fail with matching text" do
42
+ post 'text_action'
43
+ lambda {
44
+ response.should have_text("this is NOT the text for this action")
45
+ }.should fail_with("expected \"this is NOT the text for this action\", got \"this is the text for this action\"")
46
+ end
47
+
48
+ it "should fail when a template is rendered" do
49
+ post 'some_action'
50
+ lambda {
51
+ response.should have_text("this is the text for this action")
52
+ }.should fail_with(/expected \"this is the text for this action\", got .*/)
53
+ end
54
+
55
+ it "should pass using should_not with incorrect text" do
56
+ post 'text_action'
57
+ response.should_not have_text("the accordian guy")
58
+ end
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "include_text" do
4
+
5
+ describe "where target is a String" do
6
+ it 'should match submitted text using a string' do
7
+ string = 'foo'
8
+ string.should include_text('foo')
9
+ end
10
+
11
+ it 'should match if the text is contained' do
12
+ string = 'I am a big piece of text'
13
+ string.should include_text('big piece')
14
+ end
15
+
16
+ it 'should not match if text is not contained' do
17
+ string = 'I am a big piece of text'
18
+ string.should_not include_text('corey')
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ describe "include_text", :type => :controller do
25
+ ['isolation','integration'].each do |mode|
26
+ if mode == 'integration'
27
+ integrate_views
28
+ end
29
+
30
+ describe "where target is a response (in #{mode} mode)" do
31
+ controller_name :render_spec
32
+
33
+ it "should pass with exactly matching text" do
34
+ post 'text_action'
35
+ response.should include_text("this is the text for this action")
36
+ end
37
+
38
+ it 'should pass with substring matching text' do
39
+ post 'text_action'
40
+ response.should include_text('text for this')
41
+ end
42
+
43
+ it "should fail with incorrect text" do
44
+ post 'text_action'
45
+ lambda {
46
+ response.should include_text("the accordian guy")
47
+ }.should fail_with("expected to find \"the accordian guy\" in \"this is the text for this action\"")
48
+ end
49
+
50
+ it "should pass using should_not with incorrect text" do
51
+ post 'text_action'
52
+ response.should_not include_text("the accordian guy")
53
+ end
54
+
55
+ it "should fail when a template is rendered" do
56
+ get 'some_action'
57
+ lambda {
58
+ response.should include_text("this is the text for this action")
59
+ }.should fail_with(/expected to find \"this is the text for this action\"/)
60
+ end
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,209 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ ['isolation','integration'].each do |mode|
4
+ describe "redirect_to behaviour", :type => :controller do
5
+ if mode == 'integration'
6
+ integrate_views
7
+ end
8
+ controller_name :redirect_spec
9
+
10
+ it "redirected to another action" do
11
+ get 'action_with_redirect_to_somewhere'
12
+ response.should redirect_to(:action => 'somewhere')
13
+ end
14
+
15
+ it "redirected to another controller and action" do
16
+ get 'action_with_redirect_to_other_somewhere'
17
+ response.should redirect_to(:controller => 'render_spec', :action => 'text_action')
18
+ end
19
+
20
+ it "redirected to another action (with 'and return')" do
21
+ get 'action_with_redirect_to_somewhere_and_return'
22
+ response.should redirect_to(:action => 'somewhere')
23
+ end
24
+
25
+ it "redirected from an SSL action to a non-SSL action" do
26
+ request.stub!(:ssl?).and_return true
27
+ get 'action_with_redirect_to_somewhere'
28
+ response.should redirect_to(:action => 'somewhere')
29
+ end
30
+
31
+ it "redirected to correct path with leading /" do
32
+ get 'action_with_redirect_to_somewhere'
33
+ response.should redirect_to('/redirect_spec/somewhere')
34
+ end
35
+
36
+ it "redirected to correct path without leading /" do
37
+ get 'action_with_redirect_to_somewhere'
38
+ response.should redirect_to('redirect_spec/somewhere')
39
+ end
40
+
41
+ it "redirected to correct internal URL" do
42
+ get 'action_with_redirect_to_somewhere'
43
+ response.should redirect_to("http://test.host/redirect_spec/somewhere")
44
+ end
45
+
46
+ it "redirected to correct external URL" do
47
+ get 'action_with_redirect_to_rspec_site'
48
+ response.should redirect_to("http://rspec.rubyforge.org")
49
+ end
50
+
51
+ it "redirected :back" do
52
+ request.env['HTTP_REFERER'] = "http://test.host/previous/page"
53
+ get 'action_with_redirect_back'
54
+ response.should redirect_to(:back)
55
+ end
56
+
57
+ it "redirected :back and should redirect_to URL matches" do
58
+ request.env['HTTP_REFERER'] = "http://test.host/previous/page"
59
+ get 'action_with_redirect_back'
60
+ response.should redirect_to("http://test.host/previous/page")
61
+ end
62
+
63
+ it "redirected from within a respond_to block" do
64
+ get 'action_with_redirect_in_respond_to'
65
+ response.should redirect_to('redirect_spec/somewhere')
66
+ end
67
+
68
+ params_as_hash = {:action => "somewhere", :id => 1111, :param1 => "value1", :param2 => "value2"}
69
+
70
+ it "redirected to an internal URL containing a query string" do
71
+ get "action_with_redirect_which_creates_query_string"
72
+ response.should redirect_to(params_as_hash)
73
+ end
74
+
75
+ it "redirected to an internal URL containing a query string, one way it might be generated" do
76
+ get "action_with_redirect_with_query_string_order1"
77
+ response.should redirect_to(params_as_hash)
78
+ end
79
+
80
+ it "redirected to an internal URL containing a query string, another way it might be generated" do
81
+ get "action_with_redirect_with_query_string_order2"
82
+ response.should redirect_to(params_as_hash)
83
+ end
84
+
85
+ it "redirected to an internal URL which is unroutable but matched via a string" do
86
+ get "action_with_redirect_to_unroutable_url_inside_app"
87
+ response.should redirect_to("http://test.host/nonexistant/none")
88
+ end
89
+
90
+ end
91
+
92
+
93
+ describe "redirect_to with a controller spec in #{mode} mode and a custom request.host", :type => :controller do
94
+ if mode == 'integration'
95
+ integrate_views
96
+ end
97
+ controller_name :redirect_spec
98
+ before do
99
+ request.host = "some.custom.host"
100
+ end
101
+
102
+ it "should pass when redirected to another action" do
103
+ get 'action_with_redirect_to_somewhere'
104
+ response.should redirect_to(:action => 'somewhere')
105
+ end
106
+ end
107
+
108
+ describe "Given a controller spec in #{mode} mode", :type => :controller do
109
+ if mode == 'integration'
110
+ integrate_views
111
+ end
112
+ controller_name :redirect_spec
113
+
114
+ it "an action that redirects should not result in an error if no should redirect_to expectation is called" do
115
+ get 'action_with_redirect_to_somewhere'
116
+ end
117
+
118
+ it "an action that redirects should not result in an error if should_not redirect_to expectation was called, but not to that action" do
119
+ get 'action_with_redirect_to_somewhere'
120
+ response.should_not redirect_to(:action => 'another_destination')
121
+ end
122
+
123
+ it "an action that redirects should result in an error if should_not redirect_to expectation was called to that action" do
124
+ get 'action_with_redirect_to_somewhere'
125
+ lambda {
126
+ response.should_not redirect_to(:action => 'somewhere')
127
+ }.should fail_with("expected not to be redirected to {:action=>\"somewhere\"}, but was")
128
+ end
129
+
130
+ it "an action that does not redirects should not result in an error if should_not redirect_to expectation was called" do
131
+ get 'action_with_no_redirect'
132
+ response.should_not redirect_to(:action => 'any_destination')
133
+ end
134
+
135
+
136
+ end
137
+
138
+ describe "Given a controller spec in #{mode} mode, should redirect_to should fail when", :type => :controller do
139
+ if mode == 'integration'
140
+ integrate_views
141
+ end
142
+ controller_name :redirect_spec
143
+
144
+ it "redirected to wrong action" do
145
+ get 'action_with_redirect_to_somewhere'
146
+ lambda {
147
+ response.should redirect_to(:action => 'somewhere_else')
148
+ }.should fail_with("expected redirect to {:action=>\"somewhere_else\"}, got redirect to \"http://test.host/redirect_spec/somewhere\"")
149
+ end
150
+
151
+ it "redirected to incorrect path with leading /" do
152
+ get 'action_with_redirect_to_somewhere'
153
+ lambda {
154
+ response.should redirect_to('/redirect_spec/somewhere_else')
155
+ }.should fail_with('expected redirect to "/redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
156
+ end
157
+
158
+ it "redirected to incorrect path without leading /" do
159
+ get 'action_with_redirect_to_somewhere'
160
+ lambda {
161
+ response.should redirect_to('redirect_spec/somewhere_else')
162
+ }.should fail_with('expected redirect to "redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
163
+ end
164
+
165
+ it "redirected to incorrect internal URL (based on the action)" do
166
+ get 'action_with_redirect_to_somewhere'
167
+ lambda {
168
+ response.should redirect_to("http://test.host/redirect_spec/somewhere_else")
169
+ }.should fail_with('expected redirect to "http://test.host/redirect_spec/somewhere_else", got redirect to "http://test.host/redirect_spec/somewhere"')
170
+ end
171
+
172
+ it "redirected to wrong external URL" do
173
+ get 'action_with_redirect_to_rspec_site'
174
+ lambda {
175
+ response.should redirect_to("http://test.unit.rubyforge.org")
176
+ }.should fail_with('expected redirect to "http://test.unit.rubyforge.org", got redirect to "http://rspec.rubyforge.org"')
177
+ end
178
+
179
+ it "redirected to incorrect internal URL (based on the directory path)" do
180
+ get 'action_with_redirect_to_somewhere'
181
+ lambda {
182
+ response.should redirect_to("http://test.host/non_existent_controller/somewhere")
183
+ }.should fail_with('expected redirect to "http://test.host/non_existent_controller/somewhere", got redirect to "http://test.host/redirect_spec/somewhere"')
184
+ end
185
+
186
+ it "expected redirect :back, but redirected to a new URL" do
187
+ get 'action_with_no_redirect'
188
+ lambda {
189
+ response.should redirect_to(:back)
190
+ }.should fail_with('expected redirect to :back, got no redirect')
191
+ end
192
+
193
+ it "no redirect at all" do
194
+ get 'action_with_no_redirect'
195
+ lambda {
196
+ response.should redirect_to(:action => 'nowhere')
197
+ }.should fail_with("expected redirect to {:action=>\"nowhere\"}, got no redirect")
198
+ end
199
+
200
+ it "redirected to an internal URL which is unroutable and matched via a hash" do
201
+ get "action_with_redirect_to_unroutable_url_inside_app"
202
+ route = {:controller => "nonexistant", :action => "none"}
203
+ lambda {
204
+ response.should redirect_to(route)
205
+ }.should raise_error(ActionController::RoutingError, /(no route found to match|No route matches) \"\/nonexistant\/none\" with \{\}/)
206
+ end
207
+
208
+ end
209
+ end
@@ -0,0 +1,176 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ ['isolation','integration'].each do |mode|
4
+ describe "response.should render_template (in #{mode} mode)",
5
+ :type => :controller do
6
+ controller_name :render_spec
7
+ if mode == 'integration'
8
+ integrate_views
9
+ end
10
+
11
+ it "should match a simple path" do
12
+ post 'some_action'
13
+ response.should render_template('some_action')
14
+ end
15
+
16
+ it "should match a less simple path" do
17
+ post 'some_action'
18
+ response.should render_template('render_spec/some_action')
19
+ end
20
+
21
+ it "should match a less simple path to another controller" do
22
+ post 'action_which_renders_template_from_other_controller'
23
+ response.should render_template('controller_spec/action_with_template')
24
+ end
25
+
26
+ it "should match a symbol" do
27
+ post 'some_action'
28
+ response.should render_template(:some_action)
29
+ end
30
+
31
+ it "should match an rjs template" do
32
+ xhr :post, 'some_action'
33
+ if Rails::VERSION::STRING < "2.0.0"
34
+ response.should render_template('render_spec/some_action.rjs')
35
+ else
36
+ response.should render_template('render_spec/some_action')
37
+ end
38
+ end
39
+
40
+ it "should match a partial template (simple path)" do
41
+ get 'action_with_partial'
42
+ response.should render_template("_a_partial")
43
+ end
44
+
45
+ it "should match a partial template (complex path)" do
46
+ get 'action_with_partial'
47
+ response.should render_template("render_spec/_a_partial")
48
+ end
49
+
50
+ it "should fail when the wrong template is rendered" do
51
+ post 'some_action'
52
+ lambda do
53
+ response.should render_template('non_existent_template')
54
+ end.should fail_with(/expected \"non_existent_template\", got \"render_spec\/some_action(.rhtml)?\"/)
55
+ end
56
+
57
+ it "should fail without full path when template is associated with a different controller" do
58
+ post 'action_which_renders_template_from_other_controller'
59
+ lambda do
60
+ response.should render_template('action_with_template')
61
+ end.should fail_with(/expected \"action_with_template\", got \"controller_spec\/action_with_template(.rhtml)?\"/)
62
+ end
63
+
64
+ it "should fail with incorrect full path when template is associated with a different controller" do
65
+ post 'action_which_renders_template_from_other_controller'
66
+ lambda do
67
+ response.should render_template('render_spec/action_with_template')
68
+ end.should fail_with(/expected \"render_spec\/action_with_template\", got \"controller_spec\/action_with_template(\.rhtml)?\"/)
69
+ end
70
+
71
+ it "should fail on the wrong extension (given rhtml)" do
72
+ get 'some_action'
73
+ lambda {
74
+ response.should render_template('render_spec/some_action.rjs')
75
+ }.should fail_with(/expected \"render_spec\/some_action\.rjs\", got \"render_spec\/some_action(\.rhtml)?\"/)
76
+ end
77
+
78
+ it "should fail when TEXT is rendered" do
79
+ post 'text_action'
80
+ lambda do
81
+ response.should render_template('some_action')
82
+ end.should fail_with(/expected \"some_action\", got (nil|\"\")/)
83
+ end
84
+
85
+ describe "with an alternate layout" do
86
+ it "should say it rendered the action's template" do
87
+ get 'action_with_alternate_layout'
88
+ response.should render_template('action_with_alternate_layout')
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "response.should_not render_template (in #{mode} mode)",
94
+ :type => :controller do
95
+ controller_name :render_spec
96
+ if mode == 'integration'
97
+ integrate_views
98
+ end
99
+
100
+ it "should pass when the action renders nothing" do
101
+ post 'action_that_renders_nothing'
102
+ response.should_not render_template('action_that_renders_nothing')
103
+ end
104
+
105
+ it "should pass when the action renders nothing (symbol)" do
106
+ post 'action_that_renders_nothing'
107
+ response.should_not render_template(:action_that_renders_nothing)
108
+ end
109
+
110
+ it "should pass when the action does not render the template" do
111
+ post 'some_action'
112
+ response.should_not render_template('some_other_template')
113
+ end
114
+
115
+ it "should pass when the action does not render the template (symbol)" do
116
+ post 'some_action'
117
+ response.should_not render_template(:some_other_template)
118
+ end
119
+
120
+ it "should pass when the action does not render the template (named with controller)" do
121
+ post 'some_action'
122
+ response.should_not render_template('render_spec/some_other_template')
123
+ end
124
+
125
+ it "should pass when the action renders the template with a different controller" do
126
+ post 'action_which_renders_template_from_other_controller'
127
+ response.should_not render_template('action_with_template')
128
+ end
129
+
130
+ it "should pass when the action renders the template (named with controller) with a different controller" do
131
+ post 'action_which_renders_template_from_other_controller'
132
+ response.should_not render_template('render_spec/action_with_template')
133
+ end
134
+
135
+ it "should pass when TEXT is rendered" do
136
+ post 'text_action'
137
+ response.should_not render_template('some_action')
138
+ end
139
+
140
+ it "should fail when the action renders the template" do
141
+ post 'some_action'
142
+ lambda do
143
+ response.should_not render_template('some_action')
144
+ end.should fail_with("expected not to render \"some_action\", but did")
145
+ end
146
+
147
+ it "should fail when the action renders the template (symbol)" do
148
+ post 'some_action'
149
+ lambda do
150
+ response.should_not render_template(:some_action)
151
+ end.should fail_with("expected not to render \"some_action\", but did")
152
+ end
153
+
154
+ it "should fail when the action renders the template (named with controller)" do
155
+ post 'some_action'
156
+ lambda do
157
+ response.should_not render_template('render_spec/some_action')
158
+ end.should fail_with("expected not to render \"render_spec/some_action\", but did")
159
+ end
160
+
161
+ it "should fail when the action renders the partial" do
162
+ post 'action_with_partial'
163
+ lambda do
164
+ response.should_not render_template('_a_partial')
165
+ end.should fail_with("expected not to render \"_a_partial\", but did")
166
+ end
167
+
168
+ it "should fail when the action renders the partial (named with controller)" do
169
+ post 'action_with_partial'
170
+ lambda do
171
+ response.should_not render_template('render_spec/_a_partial')
172
+ end.should fail_with("expected not to render \"render_spec/_a_partial\", but did")
173
+ end
174
+
175
+ end
176
+ end