exception2db 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,135 @@
1
+ module Spec
2
+ module Rails
3
+
4
+ class IllegalDataAccessException < StandardError; end
5
+
6
+ module Mocks
7
+
8
+ # Creates a mock object instance for a +model_class+ with common
9
+ # methods stubbed out. Additional methods may be easily stubbed (via
10
+ # add_stubs) if +stubs+ is passed.
11
+ def mock_model(model_class, options_and_stubs = {})
12
+ id = options_and_stubs[:id] || next_id
13
+ options_and_stubs = options_and_stubs.reverse_merge({
14
+ :id => id,
15
+ :to_param => id.to_s,
16
+ :new_record? => false,
17
+ :errors => stub("errors", :count => 0)
18
+ })
19
+ m = mock("#{model_class.name}_#{id}", options_and_stubs)
20
+ m.__send__(:__mock_proxy).instance_eval <<-CODE
21
+ def @target.as_new_record
22
+ self.stub!(:id).and_return nil
23
+ self.stub!(:to_param).and_return nil
24
+ self.stub!(:new_record?).and_return true
25
+ self
26
+ end
27
+ def @target.is_a?(other)
28
+ #{model_class}.ancestors.include?(other)
29
+ end
30
+ def @target.kind_of?(other)
31
+ #{model_class}.ancestors.include?(other)
32
+ end
33
+ def @target.instance_of?(other)
34
+ other == #{model_class}
35
+ end
36
+ def @target.class
37
+ #{model_class}
38
+ end
39
+ CODE
40
+ yield m if block_given?
41
+ m
42
+ end
43
+
44
+ module ModelStubber
45
+ def connection
46
+ raise Spec::Rails::IllegalDataAccessException.new("stubbed models are not allowed to access the database")
47
+ end
48
+ def new_record?
49
+ id.nil?
50
+ end
51
+ def as_new_record
52
+ self.id = nil
53
+ self
54
+ end
55
+ end
56
+
57
+ # :call-seq:
58
+ # stub_model(Model)
59
+ # stub_model(Model).as_new_record
60
+ # stub_model(Model, hash_of_stubs)
61
+ # stub_model(Model, instance_variable_name, hash_of_stubs)
62
+ #
63
+ # Creates an instance of +Model+ that is prohibited from accessing the
64
+ # database*. For each key in +hash_of_stubs+, if the model has a
65
+ # matching attribute (determined by asking it) are simply assigned the
66
+ # submitted values. If the model does not have a matching attribute, the
67
+ # key/value pair is assigned as a stub return value using RSpec's
68
+ # mocking/stubbing framework.
69
+ #
70
+ # <tt>new_record?</tt> is overridden to return the result of id.nil?
71
+ # This means that by default new_record? will return false. If you want
72
+ # the object to behave as a new record, sending it +as_new_record+ will
73
+ # set the id to nil. You can also explicitly set :id => nil, in which
74
+ # case new_record? will return true, but using +as_new_record+ makes the
75
+ # example a bit more descriptive.
76
+ #
77
+ # While you can use stub_model in any example (model, view, controller,
78
+ # helper), it is especially useful in view examples, which are
79
+ # inherently more state-based than interaction-based.
80
+ #
81
+ # == Database Independence
82
+ #
83
+ # +stub_model+ does not make your examples entirely
84
+ # database-independent. It does not stop the model class itself from
85
+ # loading up its columns from the database. It just prevents data access
86
+ # from the object itself. To completely decouple from the database, take
87
+ # a look at libraries like unit_record or NullDB.
88
+ #
89
+ # == Examples
90
+ #
91
+ # stub_model(Person)
92
+ # stub_model(Person).as_new_record
93
+ # stub_model(Person, :id => 37)
94
+ # stub_model(Person) do |person|
95
+ # person.first_name = "David"
96
+ # end
97
+ def stub_model(model_class, stubs={})
98
+ stubs = {:id => next_id}.merge(stubs)
99
+ returning model_class.new do |model|
100
+ model.id = stubs.delete(:id)
101
+ model.extend ModelStubber
102
+ stubs.each do |k,v|
103
+ if model.has_attribute?(k)
104
+ model[k] = stubs.delete(k)
105
+ end
106
+ end
107
+ model.stub!(stubs)
108
+ yield model if block_given?
109
+ end
110
+ end
111
+
112
+ # DEPRECATED - use object.stub!(:method => value, :method2 => value)
113
+ #
114
+ # Stubs methods on +object+ (if +object+ is a symbol or string a new mock
115
+ # with that name will be created). +stubs+ is a Hash of +method=>value+
116
+ def add_stubs(object, stubs = {}) #:nodoc:
117
+ Kernel.warn <<-WARNING
118
+ DEPRECATION NOTICE: add_stubs is deprecated and will be removed
119
+ from a future version of rspec-rails. Use this instead:
120
+
121
+ object.stub!(:method => value, :method2 => value)
122
+
123
+ WARNING
124
+ object.stub!(stubs)
125
+ end
126
+
127
+ private
128
+ @@model_id = 1000
129
+ def next_id
130
+ @@model_id += 1
131
+ end
132
+
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,16 @@
1
+ module Spec # :nodoc:
2
+ module Rails # :nodoc:
3
+ module VERSION # :nodoc:
4
+ unless defined? MAJOR
5
+ MAJOR = 1
6
+ MINOR = 2
7
+ TINY = 9
8
+ PRE = nil
9
+
10
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
11
+
12
+ SUMMARY = "rspec-rails #{STRING}"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+ require File.dirname(__FILE__) + '/../../lib/autotest/rails_rspec'
3
+ require File.dirname(__FILE__) + '/../../../rspec/spec/autotest/autotest_matchers'
4
+
5
+ describe Autotest::RailsRspec, "file mapping" do
6
+ before(:each) do
7
+ @autotest = Autotest::RailsRspec.new
8
+ @autotest.hook :initialize
9
+ end
10
+
11
+ it "should map model example to model" do
12
+ @autotest.should map_specs(['spec/models/thing_spec.rb']).
13
+ to('app/models/thing.rb')
14
+ end
15
+
16
+ it "should map controller example to controller" do
17
+ @autotest.should map_specs(['spec/controllers/things_controller_spec.rb']).
18
+ to('app/controllers/things_controller.rb')
19
+ end
20
+
21
+ it "should map view.rhtml" do
22
+ @autotest.should map_specs(['spec/views/things/index.rhtml_spec.rb']).
23
+ to('app/views/things/index.rhtml')
24
+ end
25
+
26
+ it "should map view.rhtml with underscores in example filename" do
27
+ @autotest.should map_specs(['spec/views/things/index_rhtml_spec.rb']).
28
+ to('app/views/things/index.rhtml')
29
+ end
30
+
31
+ it "should map view.html.erb" do
32
+ @autotest.should map_specs(['spec/views/things/index.html.erb_spec.rb']).
33
+ to('app/views/things/index.html.erb')
34
+ end
35
+
36
+ describe "between routes.rb and things which depend on routes" do
37
+ it "should map routes.rb to controllers" do
38
+ @autotest.should map_specs(['spec/controllers/things_controller_spec.rb']).
39
+ to('config/routes.rb')
40
+ end
41
+
42
+ it "should map routes.rb to views" do
43
+ @autotest.should map_specs(['spec/views/things/action.html.erb_spec.rb']).
44
+ to('config/routes.rb')
45
+ end
46
+
47
+ it "should map routes.rb to helpers" do
48
+ @autotest.should map_specs(['spec/helpers/things_helper_spec.rb']).
49
+ to('config/routes.rb')
50
+ end
51
+
52
+ it "should map routing example to routes" do
53
+ @autotest.should map_specs(['spec/routing/thing_spec.rb']).
54
+ to('config/routes.rb')
55
+ end
56
+ end
57
+
58
+ describe "between the config and specs" do
59
+ ['spec/controllers/things_controller_spec.rb',
60
+ 'spec/views/things/action.html.erb_spec.rb',
61
+ 'spec/helpers/things_helper_spec.rb',
62
+ 'spec/routing/thing_spec.rb',
63
+ 'spec/models/thing_spec.rb'].each do |file_path|
64
+
65
+ it "should map environment.rb to #{file_path}" do
66
+ @autotest.should map_specs([file_path]).
67
+ to('config/environment.rb')
68
+ end
69
+
70
+ it "should map environments/test.rb to #{file_path}" do
71
+ @autotest.should map_specs([file_path]).
72
+ to('config/environments/test.rb')
73
+ end
74
+
75
+ it "should map boot.rb to #{file_path}" do
76
+ @autotest.should map_specs([file_path]).
77
+ to('config/boot.rb')
78
+ end
79
+
80
+ it "should map spec_helper.rb to #{file_path}" do
81
+ @autotest.should map_specs([file_path]).
82
+ to('spec/spec_helper.rb')
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,7 @@
1
+ dir = File.dirname(__FILE__)
2
+ Dir["#{dir}/**/*_example.rb"].each do |file|
3
+ require file
4
+ end
5
+ Dir["#{dir}/**/*_spec.rb"].each do |file|
6
+ require file
7
+ end
@@ -0,0 +1,2 @@
1
+ class ActionViewBaseSpecController < ActionController::Base
2
+ end
@@ -0,0 +1,9 @@
1
+ class ApplicationController < ActionController::Base
2
+ before_filter :i_should_only_be_run_once,
3
+ :only => 'action_with_inherited_before_filter'
4
+
5
+ def i_should_only_be_run_once
6
+ true
7
+ end
8
+ private :i_should_only_be_run_once
9
+ end
@@ -0,0 +1,127 @@
1
+ class ControllerSpecController < ActionController::Base
2
+ before_filter :raise_error, :only => :action_with_skipped_before_filter
3
+
4
+ def raise_error
5
+ raise "from a before filter"
6
+ end
7
+
8
+ skip_before_filter :raise_error
9
+
10
+ prepend_view_path File.join(File.dirname(__FILE__), "..", "views")
11
+
12
+ def some_action
13
+ render :template => "template/that/does/not/actually/exist"
14
+ end
15
+
16
+ def some_action_with_implied_template
17
+ end
18
+
19
+ def action_with_template
20
+ render :template => "controller_spec/action_with_template"
21
+ end
22
+
23
+ def action_which_sets_flash
24
+ flash[:flash_key] = "flash value"
25
+ render :text => ""
26
+ end
27
+
28
+ def action_which_gets_session
29
+ raise "expected #{params[:session_key].inspect}\ngot #{session[:session_key].inspect}" unless (session[:session_key] == params[:expected])
30
+ render :text => ""
31
+ end
32
+
33
+ def action_which_sets_session
34
+ session[:session_key] = "session value"
35
+ end
36
+
37
+ def action_which_gets_cookie
38
+ raise "expected #{params[:expected].inspect}, got #{cookies[:cookie_key].inspect}" unless (cookies[:cookie_key] == params[:expected])
39
+ render :text => ""
40
+ end
41
+
42
+ def action_which_sets_cookie
43
+ cookies['cookie_key'] = params[:value]
44
+ render :text => ""
45
+ end
46
+
47
+ def action_with_partial
48
+ render :partial => "controller_spec/partial"
49
+ end
50
+
51
+ def action_with_partial_with_object
52
+ render :partial => "controller_spec/partial", :object => params[:thing]
53
+ end
54
+
55
+ def action_with_partial_with_locals
56
+ render :partial => "controller_spec/partial", :locals => {:thing => params[:thing]}
57
+ end
58
+
59
+ def action_with_errors_in_template
60
+ render :template => "controller_spec/action_with_errors_in_template"
61
+ end
62
+
63
+ def action_setting_the_assigns_hash
64
+ @indirect_assigns_key = :indirect_assigns_key_value
65
+ end
66
+
67
+ def action_setting_flash_after_session_reset
68
+ reset_session
69
+ flash[:after_reset] = "available"
70
+ end
71
+
72
+ def action_setting_flash_before_session_reset
73
+ flash[:before_reset] = 'available'
74
+ reset_session
75
+ end
76
+
77
+ def action_with_render_update
78
+ render :update do |page|
79
+ page.replace :bottom, 'replace_me',
80
+ :partial => 'non_existent_partial'
81
+ end
82
+ end
83
+
84
+ def action_with_skipped_before_filter
85
+ render :text => ""
86
+ end
87
+
88
+ def action_that_renders_inline
89
+ render :inline => "<%= 'inline code' %>"
90
+ end
91
+
92
+ def action_that_assigns_false_to_a_variable
93
+ @a_variable = false
94
+ render :text => ""
95
+ end
96
+
97
+ def action_with_two_arg_render
98
+ render :update, :status => 404 do |page|
99
+ page.visual_effect :highlight, 'user_list'
100
+ end
101
+ end
102
+
103
+ class RescuedError < Exception; end
104
+ class UnRescuedError < Exception; end
105
+
106
+ rescue_from RescuedError do |e|
107
+ render :text => 'Rescued!'
108
+ end
109
+
110
+ def rescued_error_action
111
+ raise ControllerSpecController::RescuedError
112
+ end
113
+
114
+ def un_rescued_error_action
115
+ raise ControllerSpecController::UnRescuedError
116
+ end
117
+
118
+ def action_that_returns_headers
119
+ render :text => request.headers[params[:header]]
120
+ end
121
+ end
122
+
123
+ class ControllerInheritingFromApplicationControllerController < ApplicationController
124
+ def action_with_inherited_before_filter
125
+ render :text => ""
126
+ end
127
+ end
@@ -0,0 +1 @@
1
+ This is an example file to download.
@@ -0,0 +1,70 @@
1
+ class RedirectSpecController < ApplicationController
2
+
3
+ def action_with_no_redirect
4
+ render :text => "this is just here to keep this from causing a MissingTemplate error"
5
+ end
6
+
7
+ def action_with_redirect_to_somewhere
8
+ redirect_to :action => 'somewhere'
9
+ end
10
+
11
+ def action_with_redirect_to_other_somewhere
12
+ redirect_to :controller => 'render_spec', :action => 'text_action'
13
+ end
14
+
15
+ def action_with_redirect_to_somewhere_and_return
16
+ redirect_to :action => 'somewhere' and return
17
+ render :text => "this is after the return"
18
+ end
19
+
20
+ def somewhere
21
+ render :text => "this is just here to keep this from causing a MissingTemplate error"
22
+ end
23
+
24
+ def action_with_redirect_to_rspec_site
25
+ redirect_to "http://rspec.rubyforge.org"
26
+ end
27
+
28
+ def action_with_redirect_back
29
+ redirect_to :back
30
+ end
31
+
32
+ def action_with_redirect_in_respond_to
33
+ respond_to do |wants|
34
+ wants.html { redirect_to :action => 'somewhere' }
35
+ end
36
+ end
37
+
38
+ def action_with_redirect_which_creates_query_string
39
+ redirect_to :action => "somewhere", :id => 1111, :param1 => "value1", :param2 => "value2"
40
+ end
41
+
42
+ # note: sometimes this is the URL which rails will generate from the hash in
43
+ # action_with_redirect_which_creates_query_string
44
+ def action_with_redirect_with_query_string_order1
45
+ redirect_to "http://test.host/redirect_spec/somewhere/1111?param1=value1&param2=value2"
46
+ end
47
+
48
+ # note: sometimes this is the URL which rails will generate from the hash in
49
+ # action_with_redirect_which_creates_query_string
50
+ def action_with_redirect_with_query_string_order2
51
+ redirect_to "http://test.host/redirect_spec/somewhere/1111?param2=value2&param1=value1"
52
+ end
53
+
54
+ def action_with_redirect_to_unroutable_url_inside_app
55
+ redirect_to :controller => "nonexistant", :action => "none"
56
+ end
57
+
58
+ def action_with_method_restriction
59
+ render :text => ''
60
+ end
61
+
62
+ def action_to_redirect_to_action_with_method_restriction
63
+ redirect_to :action => 'action_with_method_restriction'
64
+ end
65
+
66
+ def action_with_redirect_to_somewhere_with_status
67
+ redirect_to :action => 'somewhere', :status => 301
68
+ end
69
+ end
70
+