shoulda 2.11.3 → 3.0.0.beta1

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 (262) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +108 -0
  3. data/README.md +95 -0
  4. data/Rakefile +6 -50
  5. data/lib/shoulda/version.rb +1 -1
  6. metadata +50 -269
  7. data/README.rdoc +0 -154
  8. data/bin/convert_to_should_syntax +0 -42
  9. data/lib/shoulda.rb +0 -9
  10. data/lib/shoulda/action_controller.rb +0 -34
  11. data/lib/shoulda/action_controller/macros.rb +0 -221
  12. data/lib/shoulda/action_controller/matchers.rb +0 -39
  13. data/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +0 -112
  14. data/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +0 -74
  15. data/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb +0 -62
  16. data/lib/shoulda/action_controller/matchers/render_template_matcher.rb +0 -54
  17. data/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +0 -99
  18. data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +0 -74
  19. data/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +0 -85
  20. data/lib/shoulda/action_controller/matchers/route_matcher.rb +0 -93
  21. data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +0 -98
  22. data/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +0 -100
  23. data/lib/shoulda/action_mailer.rb +0 -13
  24. data/lib/shoulda/action_mailer/assertions.rb +0 -42
  25. data/lib/shoulda/action_mailer/matchers.rb +0 -22
  26. data/lib/shoulda/action_mailer/matchers/have_sent_email.rb +0 -110
  27. data/lib/shoulda/active_record.rb +0 -16
  28. data/lib/shoulda/active_record/assertions.rb +0 -69
  29. data/lib/shoulda/active_record/helpers.rb +0 -32
  30. data/lib/shoulda/active_record/macros.rb +0 -457
  31. data/lib/shoulda/active_record/matchers.rb +0 -42
  32. data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +0 -83
  33. data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +0 -110
  34. data/lib/shoulda/active_record/matchers/association_matcher.rb +0 -226
  35. data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +0 -87
  36. data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +0 -141
  37. data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +0 -169
  38. data/lib/shoulda/active_record/matchers/have_db_index_matcher.rb +0 -112
  39. data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +0 -59
  40. data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +0 -41
  41. data/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb +0 -65
  42. data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +0 -39
  43. data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +0 -60
  44. data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +0 -148
  45. data/lib/shoulda/active_record/matchers/validation_matcher.rb +0 -56
  46. data/lib/shoulda/assertions.rb +0 -79
  47. data/lib/shoulda/autoload_macros.rb +0 -46
  48. data/lib/shoulda/context.rb +0 -433
  49. data/lib/shoulda/helpers.rb +0 -8
  50. data/lib/shoulda/integrations/rspec.rb +0 -13
  51. data/lib/shoulda/integrations/rspec2.rb +0 -22
  52. data/lib/shoulda/integrations/test_unit.rb +0 -22
  53. data/lib/shoulda/macros.rb +0 -161
  54. data/lib/shoulda/private_helpers.rb +0 -13
  55. data/lib/shoulda/proc_extensions.rb +0 -14
  56. data/lib/shoulda/rails.rb +0 -8
  57. data/lib/shoulda/tasks.rb +0 -3
  58. data/lib/shoulda/tasks/list_tests.rake +0 -29
  59. data/lib/shoulda/tasks/yaml_to_shoulda.rake +0 -28
  60. data/rails/init.rb +0 -8
  61. data/test/README +0 -36
  62. data/test/fail_macros.rb +0 -55
  63. data/test/fixtures/addresses.yml +0 -3
  64. data/test/fixtures/friendships.yml +0 -0
  65. data/test/fixtures/posts.yml +0 -5
  66. data/test/fixtures/products.yml +0 -0
  67. data/test/fixtures/taggings.yml +0 -0
  68. data/test/fixtures/tags.yml +0 -9
  69. data/test/fixtures/users.yml +0 -6
  70. data/test/functional/posts_controller_test.rb +0 -121
  71. data/test/functional/users_controller_test.rb +0 -19
  72. data/test/matchers/action_mailer/have_sent_email_test.rb +0 -70
  73. data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +0 -74
  74. data/test/matchers/active_record/allow_value_matcher_test.rb +0 -64
  75. data/test/matchers/active_record/association_matcher_test.rb +0 -263
  76. data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +0 -81
  77. data/test/matchers/active_record/ensure_length_of_matcher_test.rb +0 -158
  78. data/test/matchers/active_record/have_db_column_matcher_test.rb +0 -169
  79. data/test/matchers/active_record/have_db_index_matcher_test.rb +0 -91
  80. data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +0 -29
  81. data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +0 -44
  82. data/test/matchers/active_record/validate_format_of_matcher_test.rb +0 -39
  83. data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +0 -52
  84. data/test/matchers/active_record/validate_presence_of_matcher_test.rb +0 -86
  85. data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +0 -147
  86. data/test/matchers/controller/assign_to_matcher_test.rb +0 -45
  87. data/test/matchers/controller/filter_param_matcher_test.rb +0 -40
  88. data/test/matchers/controller/redirect_to_matcher_test.rb +0 -37
  89. data/test/matchers/controller/render_template_matcher_test.rb +0 -37
  90. data/test/matchers/controller/render_with_layout_matcher_test.rb +0 -47
  91. data/test/matchers/controller/respond_with_content_type_matcher_test.rb +0 -32
  92. data/test/matchers/controller/respond_with_matcher_test.rb +0 -96
  93. data/test/matchers/controller/route_matcher_test.rb +0 -75
  94. data/test/matchers/controller/set_session_matcher_test.rb +0 -48
  95. data/test/matchers/controller/set_the_flash_matcher.rb +0 -95
  96. data/test/other/autoload_macro_test.rb +0 -18
  97. data/test/other/context_test.rb +0 -372
  98. data/test/other/convert_to_should_syntax_test.rb +0 -63
  99. data/test/other/helpers_test.rb +0 -317
  100. data/test/other/private_helpers_test.rb +0 -32
  101. data/test/other/should_test.rb +0 -271
  102. data/test/rails2_model_builder.rb +0 -130
  103. data/test/rails2_root/app/controllers/application_controller.rb +0 -22
  104. data/test/rails2_root/app/controllers/posts_controller.rb +0 -87
  105. data/test/rails2_root/app/controllers/users_controller.rb +0 -84
  106. data/test/rails2_root/app/helpers/application_helper.rb +0 -3
  107. data/test/rails2_root/app/helpers/posts_helper.rb +0 -2
  108. data/test/rails2_root/app/helpers/users_helper.rb +0 -2
  109. data/test/rails2_root/app/models/address.rb +0 -7
  110. data/test/rails2_root/app/models/flea.rb +0 -11
  111. data/test/rails2_root/app/models/friendship.rb +0 -4
  112. data/test/rails2_root/app/models/notifier.rb +0 -8
  113. data/test/rails2_root/app/models/pets/cat.rb +0 -7
  114. data/test/rails2_root/app/models/pets/dog.rb +0 -10
  115. data/test/rails2_root/app/models/post.rb +0 -12
  116. data/test/rails2_root/app/models/product.rb +0 -12
  117. data/test/rails2_root/app/models/profile.rb +0 -2
  118. data/test/rails2_root/app/models/registration.rb +0 -2
  119. data/test/rails2_root/app/models/tag.rb +0 -8
  120. data/test/rails2_root/app/models/tagging.rb +0 -4
  121. data/test/rails2_root/app/models/treat.rb +0 -3
  122. data/test/rails2_root/app/models/user.rb +0 -32
  123. data/test/rails2_root/app/views/layouts/posts.rhtml +0 -19
  124. data/test/rails2_root/app/views/layouts/users.rhtml +0 -17
  125. data/test/rails2_root/app/views/layouts/wide.html.erb +0 -1
  126. data/test/rails2_root/app/views/notifier/the_email.html.erb +0 -1
  127. data/test/rails2_root/app/views/posts/edit.rhtml +0 -27
  128. data/test/rails2_root/app/views/posts/index.rhtml +0 -25
  129. data/test/rails2_root/app/views/posts/new.rhtml +0 -26
  130. data/test/rails2_root/app/views/posts/show.rhtml +0 -18
  131. data/test/rails2_root/app/views/users/edit.rhtml +0 -22
  132. data/test/rails2_root/app/views/users/index.rhtml +0 -22
  133. data/test/rails2_root/app/views/users/new.rhtml +0 -21
  134. data/test/rails2_root/app/views/users/show.rhtml +0 -13
  135. data/test/rails2_root/config/boot.rb +0 -110
  136. data/test/rails2_root/config/database.yml +0 -4
  137. data/test/rails2_root/config/environment.rb +0 -17
  138. data/test/rails2_root/config/environments/test.rb +0 -23
  139. data/test/rails2_root/config/initializers/new_rails_defaults.rb +0 -15
  140. data/test/rails2_root/config/initializers/shoulda.rb +0 -8
  141. data/test/rails2_root/config/routes.rb +0 -6
  142. data/test/rails2_root/db/migrate/001_create_users.rb +0 -19
  143. data/test/rails2_root/db/migrate/002_create_posts.rb +0 -13
  144. data/test/rails2_root/db/migrate/003_create_taggings.rb +0 -12
  145. data/test/rails2_root/db/migrate/004_create_tags.rb +0 -11
  146. data/test/rails2_root/db/migrate/005_create_dogs.rb +0 -12
  147. data/test/rails2_root/db/migrate/006_create_addresses.rb +0 -14
  148. data/test/rails2_root/db/migrate/007_create_fleas.rb +0 -11
  149. data/test/rails2_root/db/migrate/008_create_dogs_fleas.rb +0 -12
  150. data/test/rails2_root/db/migrate/009_create_products.rb +0 -17
  151. data/test/rails2_root/db/migrate/010_create_friendships.rb +0 -14
  152. data/test/rails2_root/db/migrate/011_create_treats.rb +0 -12
  153. data/test/rails2_root/db/migrate/20090506203502_create_profiles.rb +0 -12
  154. data/test/rails2_root/db/migrate/20090506203536_create_registrations.rb +0 -14
  155. data/test/rails2_root/db/migrate/20090513104502_create_cats.rb +0 -12
  156. data/test/rails2_root/db/schema.rb +0 -0
  157. data/test/rails2_root/log/test.log +0 -50381
  158. data/test/rails2_root/public/404.html +0 -30
  159. data/test/rails2_root/public/422.html +0 -30
  160. data/test/rails2_root/public/500.html +0 -30
  161. data/test/rails2_root/script/console +0 -3
  162. data/test/rails2_root/script/generate +0 -3
  163. data/test/rails2_root/test/shoulda_macros/custom_macro.rb +0 -6
  164. data/test/rails2_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +0 -6
  165. data/test/rails2_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +0 -6
  166. data/test/rails2_test_helper.rb +0 -6
  167. data/test/rails3_model_builder.rb +0 -118
  168. data/test/rails3_root/Gemfile +0 -28
  169. data/test/rails3_root/README +0 -244
  170. data/test/rails3_root/Rakefile +0 -10
  171. data/test/rails3_root/app/controllers/application_controller.rb +0 -22
  172. data/test/rails3_root/app/controllers/posts_controller.rb +0 -87
  173. data/test/rails3_root/app/controllers/users_controller.rb +0 -82
  174. data/test/rails3_root/app/helpers/application_helper.rb +0 -2
  175. data/test/rails3_root/app/models/address.rb +0 -7
  176. data/test/rails3_root/app/models/flea.rb +0 -11
  177. data/test/rails3_root/app/models/friendship.rb +0 -4
  178. data/test/rails3_root/app/models/notifier.rb +0 -8
  179. data/test/rails3_root/app/models/pets/cat.rb +0 -7
  180. data/test/rails3_root/app/models/pets/dog.rb +0 -10
  181. data/test/rails3_root/app/models/post.rb +0 -12
  182. data/test/rails3_root/app/models/product.rb +0 -12
  183. data/test/rails3_root/app/models/profile.rb +0 -2
  184. data/test/rails3_root/app/models/registration.rb +0 -2
  185. data/test/rails3_root/app/models/tag.rb +0 -8
  186. data/test/rails3_root/app/models/tagging.rb +0 -4
  187. data/test/rails3_root/app/models/treat.rb +0 -3
  188. data/test/rails3_root/app/models/user.rb +0 -32
  189. data/test/rails3_root/app/views/layouts/application.html.erb +0 -14
  190. data/test/rails3_root/app/views/layouts/posts.rhtml +0 -19
  191. data/test/rails3_root/app/views/layouts/users.rhtml +0 -17
  192. data/test/rails3_root/app/views/layouts/wide.html.erb +0 -1
  193. data/test/rails3_root/app/views/notifier/the_email.html.erb +0 -1
  194. data/test/rails3_root/app/views/posts/edit.rhtml +0 -27
  195. data/test/rails3_root/app/views/posts/index.rhtml +0 -25
  196. data/test/rails3_root/app/views/posts/new.rhtml +0 -24
  197. data/test/rails3_root/app/views/posts/show.rhtml +0 -18
  198. data/test/rails3_root/app/views/users/edit.rhtml +0 -22
  199. data/test/rails3_root/app/views/users/index.rhtml +0 -22
  200. data/test/rails3_root/app/views/users/new.rhtml +0 -21
  201. data/test/rails3_root/app/views/users/show.rhtml +0 -13
  202. data/test/rails3_root/config.ru +0 -4
  203. data/test/rails3_root/config/application.rb +0 -46
  204. data/test/rails3_root/config/boot.rb +0 -6
  205. data/test/rails3_root/config/database.yml +0 -22
  206. data/test/rails3_root/config/environment.rb +0 -5
  207. data/test/rails3_root/config/environments/development.rb +0 -19
  208. data/test/rails3_root/config/environments/production.rb +0 -42
  209. data/test/rails3_root/config/environments/test.rb +0 -32
  210. data/test/rails3_root/config/initializers/backtrace_silencers.rb +0 -7
  211. data/test/rails3_root/config/initializers/inflections.rb +0 -10
  212. data/test/rails3_root/config/initializers/mime_types.rb +0 -5
  213. data/test/rails3_root/config/initializers/secret_token.rb +0 -7
  214. data/test/rails3_root/config/initializers/session_store.rb +0 -8
  215. data/test/rails3_root/config/locales/en.yml +0 -5
  216. data/test/rails3_root/config/routes.rb +0 -4
  217. data/test/rails3_root/db/migrate/001_create_users.rb +0 -19
  218. data/test/rails3_root/db/migrate/002_create_posts.rb +0 -13
  219. data/test/rails3_root/db/migrate/003_create_taggings.rb +0 -12
  220. data/test/rails3_root/db/migrate/004_create_tags.rb +0 -11
  221. data/test/rails3_root/db/migrate/005_create_dogs.rb +0 -12
  222. data/test/rails3_root/db/migrate/006_create_addresses.rb +0 -14
  223. data/test/rails3_root/db/migrate/007_create_fleas.rb +0 -11
  224. data/test/rails3_root/db/migrate/008_create_dogs_fleas.rb +0 -12
  225. data/test/rails3_root/db/migrate/009_create_products.rb +0 -17
  226. data/test/rails3_root/db/migrate/010_create_friendships.rb +0 -14
  227. data/test/rails3_root/db/migrate/011_create_treats.rb +0 -12
  228. data/test/rails3_root/db/migrate/20090506203502_create_profiles.rb +0 -12
  229. data/test/rails3_root/db/migrate/20090506203536_create_registrations.rb +0 -14
  230. data/test/rails3_root/db/migrate/20090513104502_create_cats.rb +0 -12
  231. data/test/rails3_root/db/seeds.rb +0 -7
  232. data/test/rails3_root/db/test.sqlite3 +0 -0
  233. data/test/rails3_root/log/test.log +0 -10834
  234. data/test/rails3_root/public/404.html +0 -26
  235. data/test/rails3_root/public/422.html +0 -26
  236. data/test/rails3_root/public/500.html +0 -26
  237. data/test/rails3_root/public/favicon.ico +0 -0
  238. data/test/rails3_root/public/images/rails.png +0 -0
  239. data/test/rails3_root/public/index.html +0 -279
  240. data/test/rails3_root/public/javascripts/application.js +0 -2
  241. data/test/rails3_root/public/javascripts/controls.js +0 -965
  242. data/test/rails3_root/public/javascripts/dragdrop.js +0 -974
  243. data/test/rails3_root/public/javascripts/effects.js +0 -1123
  244. data/test/rails3_root/public/javascripts/prototype.js +0 -4874
  245. data/test/rails3_root/public/javascripts/rails.js +0 -118
  246. data/test/rails3_root/public/robots.txt +0 -5
  247. data/test/rails3_root/script/rails +0 -9
  248. data/test/rails3_root/test/performance/browsing_test.rb +0 -9
  249. data/test/rails3_root/test/test_helper.rb +0 -13
  250. data/test/rails3_test_helper.rb +0 -6
  251. data/test/rspec_test.rb +0 -207
  252. data/test/test_helper.rb +0 -36
  253. data/test/unit/address_test.rb +0 -10
  254. data/test/unit/cat_test.rb +0 -7
  255. data/test/unit/dog_test.rb +0 -9
  256. data/test/unit/flea_test.rb +0 -14
  257. data/test/unit/friendship_test.rb +0 -6
  258. data/test/unit/post_test.rb +0 -15
  259. data/test/unit/product_test.rb +0 -23
  260. data/test/unit/tag_test.rb +0 -11
  261. data/test/unit/tagging_test.rb +0 -6
  262. data/test/unit/user_test.rb +0 -46
@@ -1,8 +0,0 @@
1
- module Shoulda # :nodoc:
2
- module Helpers
3
- # Prints a message to stdout, tagged with the name of the calling method.
4
- def report!(msg = "")
5
- puts("#{caller.first}: #{msg}")
6
- end
7
- end
8
- end
@@ -1,13 +0,0 @@
1
- require 'shoulda/active_record/matchers'
2
- require 'shoulda/action_controller/matchers'
3
- require 'shoulda/action_mailer/matchers'
4
- require 'active_support/test_case'
5
-
6
- # :enddoc:
7
- module ActiveSupport
8
- class TestCase
9
- include Shoulda::ActiveRecord::Matchers
10
- include Shoulda::ActionController::Matchers
11
- include Shoulda::ActionMailer::Matchers
12
- end
13
- end
@@ -1,22 +0,0 @@
1
- require 'shoulda/active_record/matchers'
2
- require 'shoulda/action_controller/matchers'
3
- require 'shoulda/action_mailer/matchers'
4
-
5
- # :enddoc:
6
-
7
- module RSpec
8
- module Matchers
9
- include Shoulda::ActiveRecord::Matchers
10
- end
11
-
12
- module Rails
13
- module ControllerExampleGroup
14
- include Shoulda::ActionController::Matchers
15
- end
16
-
17
- module MailerExampleGroup
18
- include Shoulda::ActionMailer::Matchers
19
- end
20
- end
21
- end
22
-
@@ -1,22 +0,0 @@
1
- require 'test/unit'
2
-
3
- require 'shoulda/context'
4
- require 'shoulda/proc_extensions'
5
- require 'shoulda/assertions'
6
- require 'shoulda/macros'
7
- require 'shoulda/helpers'
8
- require 'shoulda/autoload_macros'
9
- require 'shoulda/rails' if defined? RAILS_ROOT
10
-
11
- module Test # :nodoc: all
12
- module Unit
13
- class TestCase
14
- include Shoulda::InstanceMethods
15
- extend Shoulda::ClassMethods
16
- include Shoulda::Assertions
17
- extend Shoulda::Macros
18
- include Shoulda::Helpers
19
- end
20
- end
21
- end
22
-
@@ -1,161 +0,0 @@
1
- require 'shoulda/private_helpers'
2
-
3
- module Shoulda # :nodoc:
4
- module Macros
5
- # Deprecated.
6
- #
7
- # Macro that creates a test asserting a change between the return value
8
- # of a block that is run before and after the current setup block
9
- # is run. This is similar to Active Support's <tt>assert_difference</tt>
10
- # assertion, but supports more than just numeric values. See also
11
- # should_not_change.
12
- #
13
- # The passed description will be used when generating the test name and failure messages.
14
- #
15
- # Example:
16
- #
17
- # context "Creating a post" do
18
- # setup { Post.create }
19
- # should_change("the number of posts", :by => 1) { Post.count }
20
- # end
21
- #
22
- # As shown in this example, the <tt>:by</tt> option expects a numeric
23
- # difference between the before and after values of the expression. You
24
- # may also specify <tt>:from</tt> and <tt>:to</tt> options:
25
- #
26
- # should_change("the number of posts", :from => 0, :to => 1) { Post.count }
27
- # should_change("the post title", :from => "old", :to => "new") { @post.title }
28
- #
29
- # Combinations of <tt>:by</tt>, <tt>:from</tt>, and <tt>:to</tt> are allowed:
30
- #
31
- # # Assert the value changed in some way:
32
- # should_change("the post title") { @post.title }
33
- #
34
- # # Assert the value changed to anything other than "old:"
35
- # should_change("the post title", :from => "old") { @post.title }
36
- #
37
- # # Assert the value changed to "new:"
38
- # should_change("the post title", :to => "new") { @post.title }
39
- #
40
- # This macro was deprecated because these tests aren't as valuable as
41
- # alternative tests that explicitly test the final state.
42
- #
43
- # Consider an alternative:
44
- #
45
- # context "updating a post" do
46
- # setup do
47
- # @post = Post.create(:title => "old")
48
- # put :update, :post => {:title => "new"}, :id => @post.to_param
49
- # end
50
- # should "update the title" do
51
- # assert_equal "new", @post.reload.title
52
- # end
53
- # end
54
- def should_change(description, options = {}, &block)
55
- ::ActiveSupport::Deprecation.warn("Not considered a useful test. Instead, test the end state explicitly.")
56
- by, from, to = get_options!([options], :by, :from, :to)
57
- stmt = "change #{description}"
58
- stmt << " from #{from.inspect}" if from
59
- stmt << " to #{to.inspect}" if to
60
- stmt << " by #{by.inspect}" if by
61
-
62
- before = lambda { @_before_should_change = block.bind(self).call }
63
- should stmt, :before => before do
64
- old_value = @_before_should_change
65
- new_value = block.bind(self).call
66
- assert_operator from, :===, old_value, "#{description} did not originally match #{from.inspect}" if from
67
- assert_not_equal old_value, new_value, "#{description} did not change" unless by == 0
68
- assert_operator to, :===, new_value, "#{description} was not changed to match #{to.inspect}" if to
69
- assert_equal old_value + by, new_value if by
70
- end
71
- end
72
-
73
- # Deprecated.
74
- #
75
- # Macro that creates a test asserting no change between the return value
76
- # of a block that is run before and after the current setup block
77
- # is run. This is the logical opposite of should_change.
78
- #
79
- # The passed description will be used when generating the test name and failure message.
80
- #
81
- # Example:
82
- #
83
- # context "Updating a post" do
84
- # setup { @post.update_attributes(:title => "new") }
85
- # should_not_change("the number of posts") { Post.count }
86
- # end
87
- #
88
- # This macro was deprecated because these tests aren't as valuable as
89
- # alternative tests that explicitly test the final state.
90
- #
91
- # Consider an alternative:
92
- #
93
- # context "updating a post" do
94
- # setup do
95
- # @post = Post.create(:title => "old")
96
- # put :update, :post => {:title => ""}, :id => @post.to_param
97
- # end
98
- # should "not update the title" do
99
- # assert_equal "old", @post.reload.title
100
- # end
101
- # end
102
- def should_not_change(description, &block)
103
- ::ActiveSupport::Deprecation.warn("Not considered a useful test. Instead, test the end state explicitly.")
104
- before = lambda { @_before_should_not_change = block.bind(self).call }
105
- should "not change #{description}", :before => before do
106
- new_value = block.bind(self).call
107
- assert_equal @_before_should_not_change, new_value, "#{description} changed"
108
- end
109
- end
110
-
111
- # Deprecated.
112
- #
113
- # Macro that creates a test asserting that a record of the given class was
114
- # created.
115
- #
116
- # Example:
117
- #
118
- # context "creating a post" do
119
- # setup { Post.create(post_attributes) }
120
- # should_create :post
121
- # end
122
- def should_create(class_name)
123
- ::ActiveSupport::Deprecation.warn
124
- should_change_record_count_of(class_name, 1, 'create')
125
- end
126
-
127
- # Deprecated.
128
- #
129
- # Macro that creates a test asserting that a record of the given class was
130
- # destroyed.
131
- #
132
- # Example:
133
- #
134
- # context "destroying a post" do
135
- # setup { Post.first.destroy }
136
- # should_destroy :post
137
- # end
138
- def should_destroy(class_name)
139
- ::ActiveSupport::Deprecation.warn
140
- should_change_record_count_of(class_name, -1, 'destroy')
141
- end
142
-
143
- private
144
-
145
- def should_change_record_count_of(class_name, amount, action) # :nodoc:
146
- klass = class_name.to_s.camelize.constantize
147
- before = lambda do
148
- @_before_change_record_count = klass.count
149
- end
150
- human_name = class_name.to_s.humanize.downcase
151
- should "#{action} a #{human_name}", :before => before do
152
- assert_equal @_before_change_record_count + amount,
153
- klass.count,
154
- "Expected to #{action} a #{human_name}"
155
- end
156
- end
157
-
158
- include Shoulda::Private
159
- end
160
- end
161
-
@@ -1,13 +0,0 @@
1
- module Shoulda # :nodoc:
2
- module Private # :nodoc:
3
- # Returns the values for the entries in the args hash who's keys are listed in the wanted array.
4
- # Will raise if there are keys in the args hash that aren't listed.
5
- def get_options!(args, *wanted)
6
- ret = []
7
- opts = (args.last.is_a?(Hash) ? args.pop : {})
8
- wanted.each {|w| ret << opts.delete(w)}
9
- raise ArgumentError, "Unsupported options given: #{opts.keys.join(', ')}" unless opts.keys.empty?
10
- return wanted.size == 1 ? ret.first : ret
11
- end
12
- end
13
- end
@@ -1,14 +0,0 @@
1
- # Stolen straight from ActiveSupport
2
-
3
- class Proc #:nodoc:
4
- def bind(object)
5
- block, time = self, Time.now
6
- (class << object; self end).class_eval do
7
- method_name = "__bind_#{time.to_i}_#{time.usec}"
8
- define_method(method_name, &block)
9
- method = instance_method(method_name)
10
- remove_method(method_name)
11
- method
12
- end.bind(object)
13
- end
14
- end
@@ -1,8 +0,0 @@
1
- require 'rubygems'
2
- require 'active_support'
3
- require 'shoulda'
4
-
5
- require 'shoulda/active_record' if defined? ActiveRecord::Base
6
- require 'shoulda/action_controller' if defined? ActionController::Base
7
- require 'shoulda/action_mailer' if defined? ActionMailer::Base
8
-
@@ -1,3 +0,0 @@
1
- Dir[File.join(File.dirname(__FILE__), 'tasks', '*.rake')].each do |f|
2
- load f
3
- end
@@ -1,29 +0,0 @@
1
- namespace :shoulda do
2
- desc "List the names of the test methods in a specification like format"
3
- task :list do
4
- $LOAD_PATH.unshift("test")
5
-
6
- require 'test/unit'
7
- require 'rubygems'
8
- require 'active_support'
9
-
10
- # bug in test unit. Set to true to stop from running.
11
- Test::Unit.run = true
12
-
13
- test_files = Dir.glob(File.join('test', '**', '*_test.rb'))
14
- test_files.each do |file|
15
- load file
16
- klass = File.basename(file, '.rb').classify
17
- unless Object.const_defined?(klass.to_s)
18
- puts "Skipping #{klass} because it doesn't map to a Class"
19
- next
20
- end
21
- klass = klass.constantize
22
-
23
- puts klass.name.gsub('Test', '')
24
-
25
- test_methods = klass.instance_methods.grep(/^test/).map {|s| s.gsub(/^test: /, '')}.sort
26
- test_methods.each {|m| puts " " + m }
27
- end
28
- end
29
- end
@@ -1,28 +0,0 @@
1
- namespace :shoulda do
2
- # From http://blog.internautdesign.com/2007/11/2/a-yaml_to_shoulda-rake-task
3
- # David.Lowenfels@gmail.com
4
- desc "Converts a YAML file (FILE=./path/to/yaml) into a Shoulda skeleton"
5
- task :from_yaml do
6
- require 'yaml'
7
-
8
- def yaml_to_context(hash, indent = 0)
9
- indent1 = ' ' * indent
10
- indent2 = ' ' * (indent + 1)
11
- hash.each_pair do |context, shoulds|
12
- puts indent1 + "context \"#{context}\" do"
13
- puts
14
- shoulds.each do |should|
15
- yaml_to_context( should, indent + 1 ) and next if should.is_a?( Hash )
16
- puts indent2 + "should_eventually \"" + should.gsub(/^should +/,'') + "\" do"
17
- puts indent2 + "end"
18
- puts
19
- end
20
- puts indent1 + "end"
21
- end
22
- end
23
-
24
- puts("Please pass in a FILE argument.") and exit unless ENV['FILE']
25
-
26
- yaml_to_context( YAML.load_file( ENV['FILE'] ) )
27
- end
28
- end
@@ -1,8 +0,0 @@
1
- if RAILS_ENV == 'test'
2
- if defined? Spec
3
- require 'shoulda/integrations/rspec'
4
- else
5
- require 'shoulda/integrations/test_unit'
6
- Shoulda.autoload_macros RAILS_ROOT, File.join("vendor", "{plugins,gems}", "*")
7
- end
8
- end
@@ -1,36 +0,0 @@
1
- The Shoulda test suite (in particular - the tests that test shoulda)
2
-
3
- Quick overview:
4
-
5
- The test directory contains the following files and subdirectories:
6
-
7
- * rails_root - contains the stripped down rails application that the tests run against. The rails root contains:
8
- ** the models, controllers, and views defined under app/
9
- ** the test.rb environment file
10
- ** a migration file for each model
11
- ** a shoulda initializer that simulates loading the plugin but without relying on vendor/plugins
12
- * fixtures - contain the sample DB data for each model
13
- * functional - controller tests for each of the controllers under rails_root/app
14
- * unit - model tests for each of the models under rails_root/app
15
- * other - tests for the shoulda contexts, should statements, and assertions
16
- * test_helper.rb - responsible for initializing the test environment
17
- ** sets the rails_env to test
18
- ** sets the rails_root
19
- ** runs all the migrations against the in-memory sqlite3 db
20
- ** adds some magic to load the right fixture files
21
-
22
- In order to add a new model (or controller) to the test suite:
23
-
24
- * add that model to rails_root/app/models
25
- * add a migration for that model
26
- * add a fixture file
27
- * add a test for that file under test/units
28
-
29
- Dependencies:
30
-
31
- * Rails gem installed in the host system
32
- * A working sqlite3 installation.
33
-
34
- If you have problems running these tests, please notify the mailing list: shoulda@googlegroups.com
35
-
36
- - Tammer Saleh <tsaleh@thoughtbot.com>
@@ -1,55 +0,0 @@
1
- module Shoulda
2
- class << self
3
- attr_accessor :expected_exceptions
4
- end
5
-
6
- module ClassMethods
7
- # Enables the core shoulda test suite to test for failure scenarios. For
8
- # example, to ensure that a set of test macros should fail, do this:
9
- #
10
- # should_fail do
11
- # should_validate_presence_of :comments
12
- # should_not_allow_mass_assignment_of :name
13
- # end
14
- def should_fail(&block)
15
- context "should fail when trying to run:" do
16
- if defined?(Test::Unit::AssertionFailedError)
17
- failures = [Test::Unit::AssertionFailedError]
18
- elsif defined?(MiniTest::Assertion)
19
- failures = [MiniTest::Assertion]
20
- end
21
- Shoulda.expected_exceptions = failures
22
- yield block
23
- Shoulda.expected_exceptions = nil
24
- end
25
- end
26
- end
27
-
28
- class Context
29
- # alias_method_chain hack to allow the should_fail macro to work
30
- def should_with_failure_scenario(*args, &block)
31
- should_without_failure_scenario(*args, &block)
32
- wrap_last_should_with_failure_expectation
33
- end
34
- alias_method_chain :should, :failure_scenario
35
-
36
- # alias_method_chain hack to allow the should_fail macro to work
37
- def should_not_with_failure_scenario(*args, &block)
38
- should_not_without_failure_scenario(*args, &block)
39
- wrap_last_should_with_failure_expectation
40
- end
41
- alias_method_chain :should_not, :failure_scenario
42
-
43
- def wrap_last_should_with_failure_expectation
44
- if Shoulda.expected_exceptions
45
- expected_exceptions = Shoulda.expected_exceptions
46
- should = self.shoulds.last
47
- assertion_block = should[:block]
48
- failure_block = lambda do
49
- assert_raise(*expected_exceptions, &assertion_block.bind(self))
50
- end
51
- should[:block] = failure_block
52
- end
53
- end
54
- end
55
- end
@@ -1,3 +0,0 @@
1
- first:
2
- title: Home
3
- addressable: first (User)
File without changes