exception2db 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Rakefile +48 -0
  3. data/app/controllers/exception2db/main_controller.rb +34 -0
  4. data/app/models/e2db.rb +68 -0
  5. data/app/views/exception2db/main/index.html.erb +15 -0
  6. data/app/views/exception2db/main/show.html.erb +77 -0
  7. data/app/views/layouts/exception2db.html.erb +25 -0
  8. data/config/routes.rb +12 -0
  9. data/init.rb +23 -0
  10. data/lib/css/style.css +377 -0
  11. data/lib/exception2db.rb +27 -0
  12. data/lib/exception2db/config.rb +22 -0
  13. data/lib/exception2db/railtie.rb +12 -0
  14. data/lib/exception2db/util.rb +17 -0
  15. data/lib/exception2db/version.rb +3 -0
  16. data/lib/js/app.js +1 -0
  17. data/spec/exception2db_spec.rb +74 -0
  18. data/spec/spec_helper.rb +175 -0
  19. data/test/error_xml.rb +134 -0
  20. data/test/rails_root/Rakefile +10 -0
  21. data/test/rails_root/app/controllers/application_controller.rb +10 -0
  22. data/test/rails_root/app/controllers/articles_controller.rb +7 -0
  23. data/test/rails_root/app/models/article.rb +25 -0
  24. data/test/rails_root/app/models/city.rb +15 -0
  25. data/test/rails_root/app/models/comment.rb +13 -0
  26. data/test/rails_root/app/models/tech_magazine.rb +2 -0
  27. data/test/rails_root/app/models/vehicle/car.rb +4 -0
  28. data/test/rails_root/app/models/vehicle/door.rb +3 -0
  29. data/test/rails_root/app/models/vehicle/engine.rb +3 -0
  30. data/test/rails_root/config/boot.rb +110 -0
  31. data/test/rails_root/config/database.yml +14 -0
  32. data/test/rails_root/config/environment.rb +17 -0
  33. data/test/rails_root/config/environments/cucumber.rb +26 -0
  34. data/test/rails_root/config/environments/development.rb +0 -0
  35. data/test/rails_root/config/environments/test.rb +0 -0
  36. data/test/rails_root/config/initializers/new_rails_defaults.rb +19 -0
  37. data/test/rails_root/config/routes.rb +6 -0
  38. data/test/rails_root/db/migrate/20090809061114_create_tables.rb +15 -0
  39. data/test/rails_root/db/schema.rb +74 -0
  40. data/test/rails_root/db/sqlite3.db +0 -0
  41. data/test/rails_root/log/cucumber.log +3531 -0
  42. data/test/rails_root/log/development.log +445 -0
  43. data/test/rails_root/log/test.log +59223 -0
  44. data/test/rails_root/script/console +3 -0
  45. data/test/rails_root/script/dbconsole +3 -0
  46. data/test/rails_root/script/runner +3 -0
  47. data/test/rails_root/script/server +3 -0
  48. data/test/rspec-rails/Contribute.rdoc +4 -0
  49. data/test/rspec-rails/History.rdoc +283 -0
  50. data/test/rspec-rails/License.txt +33 -0
  51. data/test/rspec-rails/Manifest.txt +165 -0
  52. data/test/rspec-rails/README.rdoc +45 -0
  53. data/test/rspec-rails/Rakefile +72 -0
  54. data/test/rspec-rails/TODO.txt +17 -0
  55. data/test/rspec-rails/Upgrade.rdoc +148 -0
  56. data/test/rspec-rails/generators/integration_spec/integration_spec_generator.rb +10 -0
  57. data/test/rspec-rails/generators/integration_spec/templates/integration_spec.rb +4 -0
  58. data/test/rspec-rails/generators/rspec/CHANGES +1 -0
  59. data/test/rspec-rails/generators/rspec/rspec_generator.rb +53 -0
  60. data/test/rspec-rails/generators/rspec/templates/previous_failures.txt +0 -0
  61. data/test/rspec-rails/generators/rspec/templates/rcov.opts +2 -0
  62. data/test/rspec-rails/generators/rspec/templates/rspec.rake +144 -0
  63. data/test/rspec-rails/generators/rspec/templates/script/autospec +6 -0
  64. data/test/rspec-rails/generators/rspec/templates/script/spec +10 -0
  65. data/test/rspec-rails/generators/rspec/templates/spec.opts +4 -0
  66. data/test/rspec-rails/generators/rspec/templates/spec_helper.rb +54 -0
  67. data/test/rspec-rails/generators/rspec_controller/USAGE +33 -0
  68. data/test/rspec-rails/generators/rspec_controller/rspec_controller_generator.rb +47 -0
  69. data/test/rspec-rails/generators/rspec_controller/templates/controller_spec.rb +25 -0
  70. data/test/rspec-rails/generators/rspec_controller/templates/helper_spec.rb +11 -0
  71. data/test/rspec-rails/generators/rspec_controller/templates/view_spec.rb +12 -0
  72. data/test/rspec-rails/generators/rspec_default_values.rb +28 -0
  73. data/test/rspec-rails/generators/rspec_model/USAGE +18 -0
  74. data/test/rspec-rails/generators/rspec_model/rspec_model_generator.rb +35 -0
  75. data/test/rspec-rails/generators/rspec_model/templates/model_spec.rb +13 -0
  76. data/test/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb +154 -0
  77. data/test/rspec-rails/generators/rspec_scaffold/templates/controller_spec.rb +131 -0
  78. data/test/rspec-rails/generators/rspec_scaffold/templates/edit_erb_spec.rb +25 -0
  79. data/test/rspec-rails/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
  80. data/test/rspec-rails/generators/rspec_scaffold/templates/index_erb_spec.rb +27 -0
  81. data/test/rspec-rails/generators/rspec_scaffold/templates/new_erb_spec.rb +25 -0
  82. data/test/rspec-rails/generators/rspec_scaffold/templates/routing_spec.rb +33 -0
  83. data/test/rspec-rails/generators/rspec_scaffold/templates/show_erb_spec.rb +22 -0
  84. data/test/rspec-rails/init.rb +9 -0
  85. data/test/rspec-rails/lib/autotest/discover.rb +5 -0
  86. data/test/rspec-rails/lib/autotest/rails_rspec.rb +76 -0
  87. data/test/rspec-rails/lib/spec/rails.rb +26 -0
  88. data/test/rspec-rails/lib/spec/rails/example.rb +48 -0
  89. data/test/rspec-rails/lib/spec/rails/example/assigns_hash_proxy.rb +39 -0
  90. data/test/rspec-rails/lib/spec/rails/example/controller_example_group.rb +278 -0
  91. data/test/rspec-rails/lib/spec/rails/example/cookies_proxy.rb +29 -0
  92. data/test/rspec-rails/lib/spec/rails/example/functional_example_group.rb +106 -0
  93. data/test/rspec-rails/lib/spec/rails/example/helper_example_group.rb +153 -0
  94. data/test/rspec-rails/lib/spec/rails/example/integration_example_group.rb +16 -0
  95. data/test/rspec-rails/lib/spec/rails/example/model_example_group.rb +14 -0
  96. data/test/rspec-rails/lib/spec/rails/example/render_observer.rb +80 -0
  97. data/test/rspec-rails/lib/spec/rails/example/routing_example_group.rb +13 -0
  98. data/test/rspec-rails/lib/spec/rails/example/routing_helpers.rb +66 -0
  99. data/test/rspec-rails/lib/spec/rails/example/view_example_group.rb +199 -0
  100. data/test/rspec-rails/lib/spec/rails/extensions.rb +11 -0
  101. data/test/rspec-rails/lib/spec/rails/extensions/action_controller/rescue.rb +42 -0
  102. data/test/rspec-rails/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
  103. data/test/rspec-rails/lib/spec/rails/extensions/action_controller/test_response.rb +21 -0
  104. data/test/rspec-rails/lib/spec/rails/extensions/action_view/base.rb +33 -0
  105. data/test/rspec-rails/lib/spec/rails/extensions/active_record/base.rb +45 -0
  106. data/test/rspec-rails/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
  107. data/test/rspec-rails/lib/spec/rails/extensions/spec/matchers/have.rb +23 -0
  108. data/test/rspec-rails/lib/spec/rails/extensions/spec/runner/configuration.rb +44 -0
  109. data/test/rspec-rails/lib/spec/rails/interop/testcase.rb +14 -0
  110. data/test/rspec-rails/lib/spec/rails/matchers.rb +33 -0
  111. data/test/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb +46 -0
  112. data/test/rspec-rails/lib/spec/rails/matchers/assert_select.rb +180 -0
  113. data/test/rspec-rails/lib/spec/rails/matchers/change.rb +13 -0
  114. data/test/rspec-rails/lib/spec/rails/matchers/have_text.rb +57 -0
  115. data/test/rspec-rails/lib/spec/rails/matchers/include_text.rb +54 -0
  116. data/test/rspec-rails/lib/spec/rails/matchers/redirect_to.rb +126 -0
  117. data/test/rspec-rails/lib/spec/rails/matchers/render_template.rb +129 -0
  118. data/test/rspec-rails/lib/spec/rails/matchers/route_to.rb +149 -0
  119. data/test/rspec-rails/lib/spec/rails/mocks.rb +135 -0
  120. data/test/rspec-rails/lib/spec/rails/version.rb +16 -0
  121. data/test/rspec-rails/spec/autotest/mappings_spec.rb +86 -0
  122. data/test/rspec-rails/spec/rails_suite.rb +7 -0
  123. data/test/rspec-rails/spec/resources/controllers/action_view_base_spec_controller.rb +2 -0
  124. data/test/rspec-rails/spec/resources/controllers/application.rb +9 -0
  125. data/test/rspec-rails/spec/resources/controllers/controller_spec_controller.rb +127 -0
  126. data/test/rspec-rails/spec/resources/controllers/example.txt +1 -0
  127. data/test/rspec-rails/spec/resources/controllers/redirect_spec_controller.rb +70 -0
  128. data/test/rspec-rails/spec/resources/controllers/render_spec_controller.rb +34 -0
  129. data/test/rspec-rails/spec/resources/controllers/rjs_spec_controller.rb +58 -0
  130. data/test/rspec-rails/spec/resources/helpers/addition_helper.rb +5 -0
  131. data/test/rspec-rails/spec/resources/helpers/explicit_helper.rb +46 -0
  132. data/test/rspec-rails/spec/resources/helpers/more_explicit_helper.rb +5 -0
  133. data/test/rspec-rails/spec/resources/helpers/plugin_application_helper.rb +6 -0
  134. data/test/rspec-rails/spec/resources/helpers/view_spec_helper.rb +13 -0
  135. data/test/rspec-rails/spec/resources/models/animal.rb +4 -0
  136. data/test/rspec-rails/spec/resources/models/person.rb +18 -0
  137. data/test/rspec-rails/spec/resources/models/thing.rb +3 -0
  138. data/test/rspec-rails/spec/resources/views/controller_spec/_partial.html.erb +0 -0
  139. data/test/rspec-rails/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.html.erb +1 -0
  140. data/test/rspec-rails/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +1 -0
  141. data/test/rspec-rails/spec/resources/views/controller_spec/action_setting_the_assigns_hash.html.erb +0 -0
  142. data/test/rspec-rails/spec/resources/views/controller_spec/action_with_errors_in_template.html.erb +1 -0
  143. data/test/rspec-rails/spec/resources/views/controller_spec/action_with_template.html.erb +1 -0
  144. data/test/rspec-rails/spec/resources/views/controller_spec/non_existent_action_with_existent_template.html.erb +0 -0
  145. data/test/rspec-rails/spec/resources/views/layouts/application.html.erb +0 -0
  146. data/test/rspec-rails/spec/resources/views/layouts/simple.html.erb +0 -0
  147. data/test/rspec-rails/spec/resources/views/objects/_object.html.erb +1 -0
  148. data/test/rspec-rails/spec/resources/views/render_spec/_a_partial.html.erb +0 -0
  149. data/test/rspec-rails/spec/resources/views/render_spec/action_with_alternate_layout.html.erb +0 -0
  150. data/test/rspec-rails/spec/resources/views/render_spec/some_action.html.erb +0 -0
  151. data/test/rspec-rails/spec/resources/views/render_spec/some_action.js.rjs +1 -0
  152. data/test/rspec-rails/spec/resources/views/rjs_spec/_replacement_partial.html.erb +1 -0
  153. data/test/rspec-rails/spec/resources/views/rjs_spec/hide_div.js.rjs +1 -0
  154. data/test/rspec-rails/spec/resources/views/rjs_spec/hide_page_element.js.rjs +1 -0
  155. data/test/rspec-rails/spec/resources/views/rjs_spec/insert_html.js.rjs +1 -0
  156. data/test/rspec-rails/spec/resources/views/rjs_spec/replace.js.rjs +1 -0
  157. data/test/rspec-rails/spec/resources/views/rjs_spec/replace_html.js.rjs +1 -0
  158. data/test/rspec-rails/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +1 -0
  159. data/test/rspec-rails/spec/resources/views/rjs_spec/visual_effect.js.rjs +1 -0
  160. data/test/rspec-rails/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +1 -0
  161. data/test/rspec-rails/spec/resources/views/tag_spec/no_tags.html.erb +1 -0
  162. data/test/rspec-rails/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +1 -0
  163. data/test/rspec-rails/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +1 -0
  164. data/test/rspec-rails/spec/resources/views/view_spec/_partial.html.erb +2 -0
  165. data/test/rspec-rails/spec/resources/views/view_spec/_partial_used_twice.html.erb +0 -0
  166. data/test/rspec-rails/spec/resources/views/view_spec/_partial_with_local_variable.html.erb +1 -0
  167. data/test/rspec-rails/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +1 -0
  168. data/test/rspec-rails/spec/resources/views/view_spec/_spacer.html.erb +1 -0
  169. data/test/rspec-rails/spec/resources/views/view_spec/accessor.html.erb +5 -0
  170. data/test/rspec-rails/spec/resources/views/view_spec/block_helper.html.erb +3 -0
  171. data/test/rspec-rails/spec/resources/views/view_spec/entry_form.html.erb +2 -0
  172. data/test/rspec-rails/spec/resources/views/view_spec/explicit_helper.html.erb +2 -0
  173. data/test/rspec-rails/spec/resources/views/view_spec/foo/show.html.erb +1 -0
  174. data/test/rspec-rails/spec/resources/views/view_spec/implicit_helper.html.erb +2 -0
  175. data/test/rspec-rails/spec/resources/views/view_spec/multiple_helpers.html.erb +3 -0
  176. data/test/rspec-rails/spec/resources/views/view_spec/path_params.html.erb +1 -0
  177. data/test/rspec-rails/spec/resources/views/view_spec/should_not_receive.html.erb +3 -0
  178. data/test/rspec-rails/spec/resources/views/view_spec/template_with_partial.html.erb +5 -0
  179. data/test/rspec-rails/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +3 -0
  180. data/test/rspec-rails/spec/resources/views/view_spec/template_with_partial_with_array.html.erb +1 -0
  181. data/test/rspec-rails/spec/resources/views/view_spec/view_helpers.html.erb +1 -0
  182. data/test/rspec-rails/spec/spec/rails/example/assigns_hash_proxy_spec.rb +109 -0
  183. data/test/rspec-rails/spec/spec/rails/example/configuration_spec.rb +65 -0
  184. data/test/rspec-rails/spec/spec/rails/example/controller_example_group_spec.rb +307 -0
  185. data/test/rspec-rails/spec/spec/rails/example/controller_isolation_spec.rb +75 -0
  186. data/test/rspec-rails/spec/spec/rails/example/cookies_proxy_spec.rb +87 -0
  187. data/test/rspec-rails/spec/spec/rails/example/error_handling_spec.rb +90 -0
  188. data/test/rspec-rails/spec/spec/rails/example/example_group_factory_spec.rb +112 -0
  189. data/test/rspec-rails/spec/spec/rails/example/helper_example_group_spec.rb +233 -0
  190. data/test/rspec-rails/spec/spec/rails/example/model_example_group_spec.rb +20 -0
  191. data/test/rspec-rails/spec/spec/rails/example/routing_example_group_spec.rb +10 -0
  192. data/test/rspec-rails/spec/spec/rails/example/shared_routing_example_group_examples.rb +237 -0
  193. data/test/rspec-rails/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
  194. data/test/rspec-rails/spec/spec/rails/example/view_example_group_spec.rb +349 -0
  195. data/test/rspec-rails/spec/spec/rails/extensions/action_view_base_spec.rb +74 -0
  196. data/test/rspec-rails/spec/spec/rails/extensions/active_record_spec.rb +14 -0
  197. data/test/rspec-rails/spec/spec/rails/interop/testcase_spec.rb +70 -0
  198. data/test/rspec-rails/spec/spec/rails/matchers/ar_be_valid_spec.rb +19 -0
  199. data/test/rspec-rails/spec/spec/rails/matchers/assert_select_spec.rb +835 -0
  200. data/test/rspec-rails/spec/spec/rails/matchers/errors_on_spec.rb +37 -0
  201. data/test/rspec-rails/spec/spec/rails/matchers/have_text_spec.rb +69 -0
  202. data/test/rspec-rails/spec/spec/rails/matchers/include_text_spec.rb +62 -0
  203. data/test/rspec-rails/spec/spec/rails/matchers/redirect_to_spec.rb +253 -0
  204. data/test/rspec-rails/spec/spec/rails/matchers/render_template_spec.rb +208 -0
  205. data/test/rspec-rails/spec/spec/rails/matchers/should_change_spec.rb +15 -0
  206. data/test/rspec-rails/spec/spec/rails/mocks/ar_classes.rb +10 -0
  207. data/test/rspec-rails/spec/spec/rails/mocks/mock_model_spec.rb +106 -0
  208. data/test/rspec-rails/spec/spec/rails/mocks/stub_model_spec.rb +80 -0
  209. data/test/rspec-rails/spec/spec/rails/sample_modified_fixture.rb +8 -0
  210. data/test/rspec-rails/spec/spec/rails/sample_spec.rb +8 -0
  211. data/test/rspec-rails/spec/spec/rails/spec_spec.rb +11 -0
  212. data/test/rspec-rails/spec/spec_helper.rb +78 -0
  213. metadata +476 -0
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'controller_spec_controller'
3
+ require File.join(File.dirname(__FILE__), "/shared_routing_example_group_examples.rb")
4
+
5
+ describe "Routing Examples", :type => :routing do
6
+
7
+ include RoutingExampleGroupSpec
8
+ include RouteToExampleGroupSpec
9
+ include BeRoutableExampleGroupSpec
10
+ end
@@ -0,0 +1,237 @@
1
+ class CustomRouteSpecController < ActionController::Base; end
2
+ class RspecOnRailsSpecsController < ActionController::Base; end
3
+
4
+ share_as :RoutingExampleGroupSpec do
5
+ describe "using backward compatible route_for()" do
6
+ it "translates GET-only paths to be explicit" do
7
+ self.should_receive(:assert_routing).with(hash_including(:method => :get), anything, {}, anything)
8
+ route_for(:controller => "controller_spec", :action => "some_action").
9
+ should == "/controller_spec/some_action"
10
+ end
11
+
12
+ it "uses assert_routing to specify that the :controller and :action are involved" do
13
+ @route = { :controller => "controller_spec", :action => "some_action" }
14
+ self.should_receive(:assert_routing).with(anything, @route, {}, anything)
15
+ route_for(@route).
16
+ should == "/controller_spec/some_action"
17
+ end
18
+
19
+ it "passes extra args through to assert_routing" do
20
+ @route = { :controller => "controller_spec", :action => "some_action" }
21
+ self.should_receive(:assert_routing).with(anything, anything, {}, { :a => "1", :b => "2" } )
22
+ route_for(@route).
23
+ should == "/controller_spec/some_action?a=1&b=2"
24
+ end
25
+
26
+ it "passes with an existing route" do
27
+ route_for(:controller => "controller_spec", :action => "some_action").
28
+ should == "/controller_spec/some_action"
29
+ end
30
+
31
+ it "passes with an existing route with additional parameters" do
32
+ route_for(:controller => "controller_spec", :action => "some_action", :param => '1').
33
+ should == "/controller_spec/some_action?param=1"
34
+ end
35
+
36
+ it "recognizes routes with methods besides :get" do
37
+ should_receive(:assert_routing).with(hash_including(:method => :put), anything, {}, anything)
38
+
39
+ route_for(:controller => "rspec_on_rails_specs", :action => "update", :id => "37").
40
+ should == {:path => "/rspec_on_rails_specs/37", :method => :put}
41
+ end
42
+
43
+ describe "failing due to bad path:" do
44
+ it "raises routing error and suggests should_not be_routeable()" do
45
+ lambda {
46
+ route_for(:controller => "rspec_on_rails_specs", :action => "nonexistent", :id => "37") ==
47
+ {:path => "/rspec_on_rails_specs/bad_route/37", :method => :put}
48
+ }.should raise_error( ActionController::RoutingError, /suggest.*should_not be_routable/ )
49
+ end
50
+ end
51
+
52
+ describe "failing due to params mismatch:" do
53
+ it "re-raises assertion and suggests should_not be_routeable()" do
54
+ lambda {
55
+ route_for(:controller => "rspec_on_rails_specs", :action => "nonexistent", :id => "37") ==
56
+ {:path => "/rspec_on_rails_specs/37", :method => :put}
57
+ }.should raise_error( ::Test::Unit::AssertionFailedError, /suggest.*should_not be_routable/ )
58
+ end
59
+ end
60
+
61
+ describe "failing due to wrong HTTP method" do
62
+ it "raises method error and suggest should_not be_routable()" do
63
+ lambda {
64
+ route_for(:controller => "rspec_on_rails_specs", :action => "update", :id => "37").
65
+ should == {:path => "/rspec_on_rails_specs/37", :method => :post}
66
+ }.should raise_error(ActionController::MethodNotAllowed) { |error| error.should_not =~ /should_not be_routable/ }
67
+ end
68
+ end
69
+
70
+ it "generates params for custom routes" do
71
+ # redundant, deprecated
72
+ params_from(:get, '/custom_route').
73
+ should == {:controller => "custom_route_spec", :action => "custom_route"}
74
+ end
75
+
76
+ it "generates params for existing routes" do
77
+ # redundant, deprecated
78
+ params_from(:get, '/controller_spec/some_action').
79
+ should == {:controller => "controller_spec", :action => "some_action"}
80
+ end
81
+
82
+ it "generates params for existing routes with a query parameters" do
83
+ # redundant, deprecated
84
+ params_from(:get, '/controller_spec/some_action?param=1').
85
+ should == {:controller => "controller_spec", :action => "some_action", :param => '1'}
86
+ end
87
+
88
+ it "generates params for existing routes with multiple query parameters" do
89
+ # redundant, deprecated
90
+ params_from(:get, '/controller_spec/some_action?param1=1&param2=2').
91
+ should == {:controller => "controller_spec", :action => "some_action", :param1 => '1', :param2 => '2' }
92
+ end
93
+ end
94
+ end
95
+
96
+ share_as :BeRoutableExampleGroupSpec do
97
+ describe "using should_not be_routable()" do
98
+ it "passes for a bad route" do
99
+ { :put => "/rspec_on_rails_specs/bad_route/37" }.
100
+ should_not be_routable
101
+ end
102
+ it "passes for a bad route having an arg" do
103
+ { :put => "/rspec_on_rails_specs/bad_route/37?some_arg=1" }.
104
+ should_not be_routable
105
+ end
106
+ describe "when assert_recognizes throws exceptions:" do
107
+ [ ActionController::RoutingError, ActionController::MethodNotAllowed ].each do |e|
108
+ it "passes on #{e}" do
109
+ self.stub!( :assert_recognizes ).and_return { raise e, "stubbed exception" }
110
+ { :get => "/rspec_on_rails_spec/bad_route/37" }.should_not be_routable
111
+ end
112
+ it "should be_routable on usual Test::Unit::AssertionFailedError" do
113
+ # <{}> is predictable because of the way we call assert_recognizes during be_routable().
114
+ self.stub!( :assert_recognizes ).and_return { raise ::Test::Unit::AssertionFailedError, "<{a}> did not match <{}>" }
115
+ { :get => "/rspec_on_rails_spec/arguably_bad_route" }.should be_routable
116
+ end
117
+ it "should re-raise on unusual Test::Unit::AssertionFailedError" do
118
+ self.stub!( :assert_recognizes ).and_return { raise ::Test::Unit::AssertionFailedError, "some other message" }
119
+ expect { { :get => "/rspec_on_rails_spec/weird_case_route/" }.should be_routable }.
120
+ to raise_error
121
+ end
122
+ end
123
+ end
124
+ it "test should be_routable" do
125
+ { :get => "/custom_route" }.
126
+ should be_routable
127
+ end
128
+
129
+ it "recommends route_to() on failure with should()" do
130
+ lambda {
131
+ { :get => "/nonexisting_route" }.
132
+ should be_routable
133
+ }.should raise_error( /route_to\(/)
134
+ end
135
+
136
+ it "shows actual route that was generated on failure with should_not()" do
137
+ begin
138
+ { :get => "/custom_route" }.should_not be_routable
139
+ rescue Exception => e
140
+ ensure
141
+ # Different versions of ruby order these differently
142
+ e.message.should =~ /"action"=>"custom_route"/
143
+ e.message.should =~ /"controller"=>"custom_route_spec"/
144
+ end
145
+ end
146
+
147
+ it "works with routeable (alternate spelling)" do
148
+ { :put => "/nonexisting_route" }.
149
+ should_not be_routeable
150
+ end
151
+ end
152
+ end
153
+
154
+ share_as :RouteToExampleGroupSpec do
155
+ describe "using should[_not] route_to()" do
156
+ it "supports existing routes" do
157
+ { :get => "/controller_spec/some_action" }.
158
+ should route_to( :controller => "controller_spec", :action => "some_action" )
159
+ end
160
+
161
+ it "translates GET-only paths to be explicit, when matching against a string (for parity with route_for().should == '/path')" do
162
+ self.should_receive(:assert_routing).with(hash_including(:method => :get), anything, {}, anything)
163
+ "/controller_spec/some_action".
164
+ should route_to({})
165
+ end
166
+
167
+ it "asserts, using assert_routing, that the :controller and :action are involved" do
168
+ @route = { :controller => "controller_spec", :action => "some_action" }
169
+ self.should_receive(:assert_routing).with(anything, @route, {}, anything)
170
+ "/controller_spec/some_action".
171
+ should route_to(@route)
172
+ end
173
+
174
+ it "sends extra args through" do
175
+ @route = { :controller => "controller_spec", :action => "some_action" }
176
+ self.should_receive(:assert_routing).with(anything, anything, {}, { :a => "1", :b => "2" } )
177
+ "/controller_spec/some_action?a=1&b=2".
178
+ should route_to( @route )
179
+ end
180
+
181
+ it "supports routes with additional parameters" do
182
+ { :get => "/controller_spec/some_action?param=1" }.
183
+ should route_to( :controller => "controller_spec", :action => "some_action", :param => '1' )
184
+ end
185
+
186
+ it "recognizes routes with methods besides :get" do
187
+ self.should_receive(:assert_routing).with(hash_including(:method => :put), anything, {}, anything)
188
+ { :put => "/rspec_on_rails_specs/37" }.
189
+ should route_to(:controller => "rspec_on_rails_specs", :action => "update", :id => "37")
190
+ end
191
+
192
+ it "allows only one key/value in the path - :method => path" do
193
+ lambda {
194
+ { :a => "b" ,:c => "d" }.
195
+ should route_to("anything")
196
+ }.should raise_error( ArgumentError, /usage/ )
197
+ end
198
+
199
+ describe "failing due to bad path" do
200
+ it "raises routing error, and suggests should_not be_routeable()" do
201
+ lambda {
202
+ { :put => "/rspec_on_rails_specs/nonexistent/37" }.
203
+ should route_to(:controller => "rspec_on_rails_specs", :action => "nonexistent", :id => "37")
204
+ }.should raise_error( ActionController::RoutingError, /suggest.*nonexistent.*should_not be_routable/ )
205
+ end
206
+ end
207
+
208
+ describe "failing due to params mismatch" do
209
+ it "raises assertion, and suggests should_not be_routeable()" do
210
+ lambda {
211
+ { :put => "/rspec_on_rails_specs/37" }.
212
+ should route_to(:controller => "rspec_on_rails_specs", :action => "nonexistent", :id => "37")
213
+ }.should raise_error( ::Test::Unit::AssertionFailedError, /suggest.*rspec_on_rails_specs\/37.*should_not be_routable/ )
214
+ end
215
+ end
216
+
217
+ describe "passing when expected failure" do
218
+ it "suggests should_not be_routable()" do
219
+ self.stub!(:assert_routing).and_return true
220
+ lambda {
221
+ { :put => "/rspec_on_rails_specs/37" }.
222
+ should_not route_to(:controller => "rspec_on_rails_specs", :action => "update", :id => "37")
223
+ }.should raise_error( /expected a routing error.*be_routable/im )
224
+ end
225
+ end
226
+
227
+ describe "failing due to wrong HTTP method" do
228
+ it "raises method error and suggests should_not be_routable()" do
229
+ self.stub!(:assert_routing) { raise ActionController::MethodNotAllowed }
230
+ lambda {
231
+ { :post => "/rspec_on_rails_specs/37" }.
232
+ should route_to(:controller => "rspec_on_rails_specs", :action => "update", :id => "37" )
233
+ }.should raise_error(ActionController::MethodNotAllowed, /rspec_on_rails_specs\/37.*should_not be_routable/ )
234
+ end
235
+ end
236
+ end
237
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe "assert_equal", :shared => true do
4
+ it "like assert_equal" do
5
+ assert_equal 1, 1
6
+ lambda {
7
+ assert_equal 1, 2
8
+ }.should raise_error(::Test::Unit::AssertionFailedError)
9
+ end
10
+ end
11
+
12
+ describe "A model spec should be able to access 'test/unit' assertions", :type => :model do
13
+ it_should_behave_like "assert_equal"
14
+ end
15
+
16
+ describe "A view spec should be able to access 'test/unit' assertions", :type => :view do
17
+ it_should_behave_like "assert_equal"
18
+ end
19
+
20
+ describe "A helper spec should be able to access 'test/unit' assertions", :type => :helper do
21
+ it_should_behave_like "assert_equal"
22
+ end
23
+
24
+ describe "A controller spec with integrated views should be able to access 'test/unit' assertions", :type => :controller do
25
+ controller_name :controller_spec
26
+ integrate_views
27
+ it_should_behave_like "assert_equal"
28
+ end
29
+
30
+ describe "A controller spec should be able to access 'test/unit' assertions", :type => :controller do
31
+ controller_name :controller_spec
32
+ it_should_behave_like "assert_equal"
33
+ end
@@ -0,0 +1,349 @@
1
+ require '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'", :type => :view do
258
+ it "should derive action name using the first part of the template name" do
259
+ render 'view_spec/foo/show'
260
+ request.path_parameters[:action].should == 'show'
261
+ end
262
+ end
263
+
264
+ describe "view_spec/foo/show", :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(Spec::Example::ExampleProxy.new) {}
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
336
+
337
+ describe "bug https://rspec.lighthouseapp.com/projects/5645/tickets/787", :type => :view do
338
+ describe "a view example checking a link" do
339
+ it "should have access to link_to" do
340
+ render "view_spec/view_helpers"
341
+ response.body.should include(link_to("edit", "this_is_the_link"))
342
+ end
343
+
344
+ it "should use link_to within have_tag" do
345
+ render "view_spec/view_helpers"
346
+ response.body.should have_tag("span", :html => link_to("edit", "this_is_the_link"))
347
+ end
348
+ end
349
+ end