tpitale-shoulda 2.11.0

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 (170) hide show
  1. data/CONTRIBUTION_GUIDELINES.rdoc +10 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.rdoc +171 -0
  4. data/Rakefile +71 -0
  5. data/bin/convert_to_should_syntax +42 -0
  6. data/lib/shoulda.rb +11 -0
  7. data/lib/shoulda/action_controller.rb +26 -0
  8. data/lib/shoulda/action_controller/macros.rb +240 -0
  9. data/lib/shoulda/action_controller/matchers.rb +37 -0
  10. data/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
  11. data/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
  12. data/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
  13. data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +74 -0
  14. data/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +81 -0
  15. data/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
  16. data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +87 -0
  17. data/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
  18. data/lib/shoulda/action_mailer.rb +10 -0
  19. data/lib/shoulda/action_mailer/assertions.rb +38 -0
  20. data/lib/shoulda/action_view.rb +10 -0
  21. data/lib/shoulda/action_view/macros.rb +61 -0
  22. data/lib/shoulda/active_record.rb +16 -0
  23. data/lib/shoulda/active_record/assertions.rb +69 -0
  24. data/lib/shoulda/active_record/helpers.rb +27 -0
  25. data/lib/shoulda/active_record/macros.rb +512 -0
  26. data/lib/shoulda/active_record/matchers.rb +43 -0
  27. data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
  28. data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
  29. data/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
  30. data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
  31. data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
  32. data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
  33. data/lib/shoulda/active_record/matchers/have_db_index_matcher.rb +112 -0
  34. data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +128 -0
  35. data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
  36. data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
  37. data/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb +67 -0
  38. data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
  39. data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
  40. data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
  41. data/lib/shoulda/active_record/matchers/validation_matcher.rb +57 -0
  42. data/lib/shoulda/assertions.rb +71 -0
  43. data/lib/shoulda/autoload_macros.rb +46 -0
  44. data/lib/shoulda/context.rb +413 -0
  45. data/lib/shoulda/helpers.rb +8 -0
  46. data/lib/shoulda/macros.rb +133 -0
  47. data/lib/shoulda/minitest.rb +24 -0
  48. data/lib/shoulda/private_helpers.rb +13 -0
  49. data/lib/shoulda/proc_extensions.rb +14 -0
  50. data/lib/shoulda/rails.rb +13 -0
  51. data/lib/shoulda/rspec.rb +11 -0
  52. data/lib/shoulda/tasks.rb +3 -0
  53. data/lib/shoulda/tasks/list_tests.rake +29 -0
  54. data/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
  55. data/lib/shoulda/test_unit.rb +22 -0
  56. data/rails/init.rb +7 -0
  57. data/test/README +36 -0
  58. data/test/fail_macros.rb +39 -0
  59. data/test/fixtures/addresses.yml +3 -0
  60. data/test/fixtures/friendships.yml +0 -0
  61. data/test/fixtures/posts.yml +5 -0
  62. data/test/fixtures/products.yml +0 -0
  63. data/test/fixtures/taggings.yml +0 -0
  64. data/test/fixtures/tags.yml +9 -0
  65. data/test/fixtures/users.yml +6 -0
  66. data/test/functional/posts_controller_test.rb +121 -0
  67. data/test/functional/users_controller_test.rb +19 -0
  68. data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +68 -0
  69. data/test/matchers/active_record/allow_value_matcher_test.rb +64 -0
  70. data/test/matchers/active_record/association_matcher_test.rb +263 -0
  71. data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +80 -0
  72. data/test/matchers/active_record/ensure_length_of_matcher_test.rb +158 -0
  73. data/test/matchers/active_record/have_db_column_matcher_test.rb +169 -0
  74. data/test/matchers/active_record/have_db_index_matcher_test.rb +91 -0
  75. data/test/matchers/active_record/have_named_scope_matcher_test.rb +65 -0
  76. data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +29 -0
  77. data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +44 -0
  78. data/test/matchers/active_record/validate_format_of_matcher_test.rb +39 -0
  79. data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +52 -0
  80. data/test/matchers/active_record/validate_presence_of_matcher_test.rb +86 -0
  81. data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +147 -0
  82. data/test/matchers/controller/assign_to_matcher_test.rb +35 -0
  83. data/test/matchers/controller/filter_param_matcher_test.rb +32 -0
  84. data/test/matchers/controller/render_with_layout_matcher_test.rb +33 -0
  85. data/test/matchers/controller/respond_with_content_type_matcher_test.rb +32 -0
  86. data/test/matchers/controller/respond_with_matcher_test.rb +106 -0
  87. data/test/matchers/controller/route_matcher_test.rb +58 -0
  88. data/test/matchers/controller/set_session_matcher_test.rb +38 -0
  89. data/test/matchers/controller/set_the_flash_matcher.rb +41 -0
  90. data/test/model_builder.rb +106 -0
  91. data/test/other/autoload_macro_test.rb +18 -0
  92. data/test/other/context_test.rb +203 -0
  93. data/test/other/convert_to_should_syntax_test.rb +63 -0
  94. data/test/other/helpers_test.rb +340 -0
  95. data/test/other/private_helpers_test.rb +32 -0
  96. data/test/other/should_test.rb +271 -0
  97. data/test/rails_root/app/controllers/application_controller.rb +25 -0
  98. data/test/rails_root/app/controllers/posts_controller.rb +87 -0
  99. data/test/rails_root/app/controllers/users_controller.rb +84 -0
  100. data/test/rails_root/app/helpers/application_helper.rb +3 -0
  101. data/test/rails_root/app/helpers/posts_helper.rb +2 -0
  102. data/test/rails_root/app/helpers/users_helper.rb +2 -0
  103. data/test/rails_root/app/models/address.rb +7 -0
  104. data/test/rails_root/app/models/flea.rb +3 -0
  105. data/test/rails_root/app/models/friendship.rb +4 -0
  106. data/test/rails_root/app/models/pets/cat.rb +7 -0
  107. data/test/rails_root/app/models/pets/dog.rb +10 -0
  108. data/test/rails_root/app/models/post.rb +12 -0
  109. data/test/rails_root/app/models/product.rb +12 -0
  110. data/test/rails_root/app/models/profile.rb +2 -0
  111. data/test/rails_root/app/models/registration.rb +2 -0
  112. data/test/rails_root/app/models/tag.rb +8 -0
  113. data/test/rails_root/app/models/tagging.rb +4 -0
  114. data/test/rails_root/app/models/treat.rb +3 -0
  115. data/test/rails_root/app/models/user.rb +32 -0
  116. data/test/rails_root/app/views/layouts/posts.rhtml +19 -0
  117. data/test/rails_root/app/views/layouts/users.rhtml +17 -0
  118. data/test/rails_root/app/views/layouts/wide.html.erb +1 -0
  119. data/test/rails_root/app/views/posts/edit.rhtml +27 -0
  120. data/test/rails_root/app/views/posts/index.rhtml +25 -0
  121. data/test/rails_root/app/views/posts/new.rhtml +26 -0
  122. data/test/rails_root/app/views/posts/show.rhtml +18 -0
  123. data/test/rails_root/app/views/users/edit.rhtml +22 -0
  124. data/test/rails_root/app/views/users/index.rhtml +22 -0
  125. data/test/rails_root/app/views/users/new.rhtml +21 -0
  126. data/test/rails_root/app/views/users/show.rhtml +13 -0
  127. data/test/rails_root/config/boot.rb +110 -0
  128. data/test/rails_root/config/database.yml +4 -0
  129. data/test/rails_root/config/environment.rb +18 -0
  130. data/test/rails_root/config/environments/test.rb +0 -0
  131. data/test/rails_root/config/initializers/new_rails_defaults.rb +15 -0
  132. data/test/rails_root/config/initializers/shoulda.rb +8 -0
  133. data/test/rails_root/config/routes.rb +6 -0
  134. data/test/rails_root/db/migrate/001_create_users.rb +19 -0
  135. data/test/rails_root/db/migrate/002_create_posts.rb +13 -0
  136. data/test/rails_root/db/migrate/003_create_taggings.rb +12 -0
  137. data/test/rails_root/db/migrate/004_create_tags.rb +11 -0
  138. data/test/rails_root/db/migrate/005_create_dogs.rb +12 -0
  139. data/test/rails_root/db/migrate/006_create_addresses.rb +14 -0
  140. data/test/rails_root/db/migrate/007_create_fleas.rb +11 -0
  141. data/test/rails_root/db/migrate/008_create_dogs_fleas.rb +12 -0
  142. data/test/rails_root/db/migrate/009_create_products.rb +17 -0
  143. data/test/rails_root/db/migrate/010_create_friendships.rb +14 -0
  144. data/test/rails_root/db/migrate/011_create_treats.rb +12 -0
  145. data/test/rails_root/db/migrate/20090506203502_create_profiles.rb +12 -0
  146. data/test/rails_root/db/migrate/20090506203536_create_registrations.rb +14 -0
  147. data/test/rails_root/db/migrate/20090513104502_create_cats.rb +12 -0
  148. data/test/rails_root/db/schema.rb +0 -0
  149. data/test/rails_root/log/test.log +1 -0
  150. data/test/rails_root/public/404.html +30 -0
  151. data/test/rails_root/public/422.html +30 -0
  152. data/test/rails_root/public/500.html +30 -0
  153. data/test/rails_root/script/console +3 -0
  154. data/test/rails_root/script/generate +3 -0
  155. data/test/rails_root/test/shoulda_macros/custom_macro.rb +6 -0
  156. data/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +6 -0
  157. data/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +6 -0
  158. data/test/rspec_test.rb +207 -0
  159. data/test/test_helper.rb +28 -0
  160. data/test/unit/address_test.rb +10 -0
  161. data/test/unit/cat_test.rb +7 -0
  162. data/test/unit/dog_test.rb +9 -0
  163. data/test/unit/flea_test.rb +6 -0
  164. data/test/unit/friendship_test.rb +6 -0
  165. data/test/unit/post_test.rb +19 -0
  166. data/test/unit/product_test.rb +23 -0
  167. data/test/unit/tag_test.rb +15 -0
  168. data/test/unit/tagging_test.rb +6 -0
  169. data/test/unit/user_test.rb +80 -0
  170. metadata +226 -0
@@ -0,0 +1,4 @@
1
+ test:
2
+ :adapter: sqlite3
3
+ # :dbfile: db/sqlite3.db
4
+ :dbfile: ":memory:"
@@ -0,0 +1,18 @@
1
+ # Specifies gem version of Rails to use when vendor/rails is not present
2
+ old_verbose, $VERBOSE = $VERBOSE, nil
3
+ RAILS_GEM_VERSION = '= 2.3.2' unless defined? RAILS_GEM_VERSION
4
+ $VERBOSE = old_verbose
5
+
6
+ require File.join(File.dirname(__FILE__), 'boot')
7
+
8
+ Rails::Initializer.run do |config|
9
+ config.log_level = :debug
10
+ config.cache_classes = false
11
+ config.whiny_nils = true
12
+ config.action_controller.session = {
13
+ :key => 'shoulda_session',
14
+ :secret => 'ceae6058a816b1446e09ce90d8372511'
15
+ }
16
+ end
17
+
18
+ # Dependencies.log_activity = true
File without changes
@@ -0,0 +1,15 @@
1
+ # These settings change the behavior of Rails 2 apps and will be defaults
2
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
3
+
4
+ # Include Active Record class name as root for JSON serialized output.
5
+ ActiveRecord::Base.include_root_in_json = true
6
+
7
+ # Store the full class name (including module namespace) in STI type column.
8
+ ActiveRecord::Base.store_full_sti_class = true
9
+
10
+ # Use ISO 8601 format for JSON serialized times and dates.
11
+ ActiveSupport.use_standard_json_time_format = true
12
+
13
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
14
+ # if you're including raw json in an HTML page.
15
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,8 @@
1
+ # This simulates loading the shoulda plugin, but without relying on
2
+ # vendor/plugins
3
+
4
+ shoulda_path = File.join(File.dirname(__FILE__), *%w(.. .. .. ..))
5
+ shoulda_lib_path = File.join(shoulda_path, "lib")
6
+
7
+ $LOAD_PATH.unshift(shoulda_lib_path)
8
+ load File.join(shoulda_path, "init.rb")
@@ -0,0 +1,6 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.resources :posts
4
+ map.resources :users, :has_many => :posts
5
+
6
+ end
@@ -0,0 +1,19 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.column :name, :string
5
+ t.column :email, :string
6
+ t.column :age, :integer
7
+ t.column :ssn, :string
8
+ t.column :phone, :string
9
+ end
10
+ add_index :users, :email, :unique => true
11
+ add_index :users, :name
12
+ add_index :users, :age
13
+ add_index :users, [:email, :name], :unique => true
14
+ end
15
+
16
+ def self.down
17
+ drop_table :users
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :posts do |t|
4
+ t.column :user_id, :integer
5
+ t.column :title, :string
6
+ t.column :body, :text
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :posts
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class CreateTaggings < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :taggings do |t|
4
+ t.column :post_id, :integer
5
+ t.column :tag_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :taggings
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateTags < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :tags do |t|
4
+ t.column :name, :string
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :tags
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class CreateDogs < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :dogs do |t|
4
+ t.column :owner_id, :integer
5
+ t.column :address_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :dogs
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreateAddresses < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :addresses do |t|
4
+ t.column :title, :string
5
+ t.column :addressable_id, :integer
6
+ t.column :addressable_type, :string
7
+ t.column :zip, :string
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :addresses
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ class CreateFleas < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :fleas do |t|
4
+ t.string :name
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :fleas
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class CreateDogsFleas < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :dogs_fleas do |t|
4
+ t.integer :dog_id
5
+ t.integer :flea_id
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :dogs_fleas
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ class CreateProducts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :products do |t|
4
+ t.string :title
5
+ t.integer :price
6
+ t.integer :weight
7
+ t.string :size
8
+ t.boolean :tangible
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table :products
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ class CreateFriendships < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :friendships do |t|
4
+ t.integer :user_id
5
+ t.integer :friend_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :friendships
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class CreateTreats < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :treats do |t|
4
+ t.integer :dog_id
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :treats
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class CreateProfiles < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :profiles do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :profiles
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreateRegistrations < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :registrations do |t|
4
+ t.integer :user_id
5
+ t.integer :profile_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :registrations
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class CreateCats < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :cats do |t|
4
+ t.column :owner_id, :integer
5
+ t.column :address_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :cats
11
+ end
12
+ end
File without changes
@@ -0,0 +1 @@
1
+ # Logfile created on Tue Oct 13 15:18:45 -0400 2009
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The page you were looking for doesn't exist (404)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/404.html -->
25
+ <div class="dialog">
26
+ <h1>The page you were looking for doesn't exist.</h1>
27
+ <p>You may have mistyped the address or the page may have moved.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The change you wanted was rejected (422)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/422.html -->
25
+ <div class="dialog">
26
+ <h1>The change you wanted was rejected.</h1>
27
+ <p>Maybe you tried to change something you didn't have access to.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>We're sorry, but something went wrong (500)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/500.html -->
25
+ <div class="dialog">
26
+ <h1>We're sorry, but something went wrong.</h1>
27
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/generate'
@@ -0,0 +1,6 @@
1
+ module CustomMacro
2
+ def custom_macro
3
+ end
4
+ end
5
+ ActiveSupport::TestCase.extend(CustomMacro)
6
+
@@ -0,0 +1,6 @@
1
+ module GemMacro
2
+ def gem_macro
3
+ end
4
+ end
5
+ ActiveSupport::TestCase.extend(GemMacro)
6
+
@@ -0,0 +1,6 @@
1
+ module PluginMacro
2
+ def plugin_macro
3
+ end
4
+ end
5
+ ActiveSupport::TestCase.extend(PluginMacro)
6
+
@@ -0,0 +1,207 @@
1
+ require 'test_helper'
2
+
3
+ begin
4
+ gem 'rspec'
5
+ gem 'rspec-rails'
6
+ rescue LoadError => exception
7
+ puts exception.message
8
+ puts "RSpec integration was not tested because RSpec is not available"
9
+ else
10
+
11
+ class RspecTest < ActiveSupport::TestCase
12
+
13
+ SHOULDA_ROOT =
14
+ File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
15
+
16
+ def setup
17
+ build_gemspec
18
+ end
19
+
20
+ def teardown
21
+ FileUtils.rm_rf(project_dir)
22
+ FileUtils.rm_rf("#{shoulda_root}/pkg")
23
+ end
24
+
25
+ should "integrate correctly when using config.gem in test.rb" do
26
+ create_project
27
+ insert(rspec_dependencies, "config/environments/test.rb")
28
+ vendor_gems('test')
29
+ configure_spec_rails
30
+ assert_configured
31
+ end
32
+
33
+ should "integrate correctly when using config.gem in environment.rb" do
34
+ create_project
35
+ insert(rspec_dependencies,
36
+ "config/environment.rb",
37
+ /Rails::Initializer\.run/)
38
+ vendor_gems('development')
39
+ configure_spec_rails
40
+ assert_configured
41
+ end
42
+
43
+ should "integrate correctly when using require in spec_helper" do
44
+ create_project
45
+ configure_spec_rails
46
+ insert(%{gem 'shoulda'; require 'shoulda'},
47
+ "spec/spec_helper.rb",
48
+ %{require 'spec/rails'})
49
+ assert_configured
50
+ end
51
+
52
+ should "integrate correctly when unpacked and required in spec_helper" do
53
+ create_project
54
+ configure_spec_rails
55
+ insert(%{require 'shoulda'},
56
+ "spec/spec_helper.rb",
57
+ %{require 'spec/rails'})
58
+ unpack_gems
59
+ assert_configured
60
+ end
61
+
62
+ def create_project
63
+ command "rails #{project_dir}"
64
+ end
65
+
66
+ def vendor_gems(env)
67
+ project_command "rake gems:unpack RAILS_ENV=#{env}"
68
+ end
69
+
70
+ def unpack_gems
71
+ FileUtils.mkdir_p "#{project_dir}/vendor/gems"
72
+ FileUtils.cd "#{project_dir}/vendor/gems" do
73
+ %w(rspec rspec-rails shoulda).each do |gem|
74
+ command "gem unpack #{gem}"
75
+ end
76
+ end
77
+
78
+ insert('config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/*/lib"]',
79
+ "config/environment.rb",
80
+ /Rails::Initializer\.run/)
81
+ end
82
+
83
+ def command(command)
84
+ output = `GEM_PATH=#{shoulda_root}/pkg #{command} 2>&1`
85
+ unless $? == 0
86
+ flunk("Command failed with status #{$?}\n#{command}\n#{output}")
87
+ end
88
+ @command_output ||= ''
89
+ @command_output << output
90
+ output
91
+ end
92
+
93
+ def project_command(command)
94
+ result = nil
95
+ FileUtils.cd project_dir do
96
+ result = command(command)
97
+ end
98
+ result
99
+ end
100
+
101
+ def shoulda_command(command)
102
+ FileUtils.cd shoulda_root do
103
+ command(command)
104
+ end
105
+ end
106
+
107
+ def project_name
108
+ 'example_rails_project'
109
+ end
110
+
111
+ def project_dir
112
+ File.expand_path(File.join(File.dirname(__FILE__), project_name))
113
+ end
114
+
115
+ def insert(content, path, after = nil)
116
+ path = File.join(project_dir, path)
117
+ contents = IO.read(path)
118
+ if after
119
+ contents.gsub!(/^(.*#{after}.*)$/, "\\1\n#{content}")
120
+ else
121
+ contents << "\n" << content
122
+ end
123
+ File.open(path, 'w') {|file| file.write(contents) }
124
+ end
125
+
126
+ def rspec_dependencies
127
+ return <<-EOS
128
+ config.gem 'rspec', :lib => 'spec'
129
+ config.gem 'rspec-rails', :lib => false
130
+ config.gem 'shoulda', :lib => 'shoulda'
131
+ EOS
132
+ end
133
+
134
+ def configure_spec_rails
135
+ project_command "script/generate rspec"
136
+ end
137
+
138
+ def assert_configured
139
+ create_model
140
+ migrate
141
+ create_controller
142
+ assert_spec_passes
143
+ end
144
+
145
+ def create_model
146
+ project_command "script/generate rspec_model person name:string"
147
+ insert "validates_presence_of :name",
148
+ "app/models/person.rb",
149
+ /class Person/
150
+ insert "it { should validate_presence_of(:name) }",
151
+ "spec/models/person_spec.rb",
152
+ /describe Person do/
153
+ end
154
+
155
+ def create_controller
156
+ project_command "script/generate rspec_controller people"
157
+ insert "def index; render :text => 'Hello'; end",
158
+ "app/controllers/people_controller.rb",
159
+ /class PeopleController/
160
+ shoulda_controller_example = <<-EOS
161
+ describe PeopleController, "on GET index" do
162
+ integrate_views
163
+ subject { controller }
164
+ before(:each) { get :index }
165
+ it { should respond_with(:success) }
166
+ end
167
+ EOS
168
+ insert shoulda_controller_example,
169
+ "spec/controllers/people_controller_spec.rb"
170
+ end
171
+
172
+ def migrate
173
+ project_command "rake db:migrate"
174
+ end
175
+
176
+ def assert_spec_passes
177
+ result = project_command("rake spec SPEC_OPTS=-fs")
178
+ assert_match /should require name to be set/, result
179
+ assert_match /should respond with 200/, result
180
+ end
181
+
182
+ def shoulda_root
183
+ SHOULDA_ROOT
184
+ end
185
+
186
+ def build_gemspec
187
+ backup_gemspec do
188
+ shoulda_command "rake gemspec"
189
+ shoulda_command "rake gem"
190
+ shoulda_command "gem install --no-ri --no-rdoc -i pkg pkg/shoulda*.gem"
191
+ end
192
+ end
193
+
194
+ def backup_gemspec
195
+ actual = "#{shoulda_root}/shoulda.gemspec"
196
+ backup = "#{shoulda_root}/backup.gemspec"
197
+ FileUtils.mv(actual, backup)
198
+ begin
199
+ yield
200
+ ensure
201
+ FileUtils.mv(backup, actual)
202
+ end
203
+ end
204
+
205
+ end
206
+
207
+ end