thoughtbot-shoulda 2.10.2 → 2.11.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.
- data/CONTRIBUTION_GUIDELINES.rdoc +5 -5
- data/README.rdoc +72 -89
- data/Rakefile +31 -33
- data/lib/shoulda.rb +6 -6
- data/lib/shoulda/action_controller.rb +8 -0
- data/lib/shoulda/action_controller/macros.rb +54 -73
- data/lib/shoulda/action_controller/matchers.rb +7 -5
- data/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +10 -7
- data/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +18 -1
- data/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb +62 -0
- data/lib/shoulda/action_controller/matchers/render_template_matcher.rb +54 -0
- data/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +33 -15
- data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +10 -10
- data/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +17 -13
- data/lib/shoulda/action_controller/matchers/route_matcher.rb +3 -3
- data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +13 -2
- data/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +1 -1
- data/lib/shoulda/action_mailer.rb +3 -0
- data/lib/shoulda/action_mailer/assertions.rb +4 -0
- data/lib/shoulda/action_mailer/matchers.rb +22 -0
- data/lib/shoulda/action_mailer/matchers/have_sent_email.rb +110 -0
- data/lib/shoulda/active_record/helpers.rb +8 -3
- data/lib/shoulda/active_record/macros.rb +88 -143
- data/lib/shoulda/active_record/matchers.rb +0 -1
- data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +1 -1
- data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +10 -2
- data/lib/shoulda/active_record/matchers/association_matcher.rb +8 -8
- data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +1 -1
- data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +2 -2
- data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +11 -11
- data/lib/shoulda/active_record/matchers/have_db_index_matcher.rb +8 -8
- data/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb +2 -4
- data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +3 -3
- data/lib/shoulda/active_record/matchers/validation_matcher.rb +0 -1
- data/lib/shoulda/assertions.rb +10 -2
- data/lib/shoulda/autoload_macros.rb +20 -20
- data/lib/shoulda/context.rb +70 -39
- data/lib/shoulda/{rspec.rb → integrations/rspec.rb} +2 -0
- data/lib/shoulda/integrations/rspec2.rb +22 -0
- data/lib/shoulda/{test_unit.rb → integrations/test_unit.rb} +0 -0
- data/lib/shoulda/macros.rb +46 -18
- data/lib/shoulda/rails.rb +0 -5
- data/lib/shoulda/tasks/yaml_to_shoulda.rake +11 -11
- data/lib/shoulda/version.rb +4 -0
- data/rails/init.rb +3 -2
- data/test/fail_macros.rb +20 -4
- data/test/functional/posts_controller_test.rb +7 -7
- data/test/functional/users_controller_test.rb +1 -1
- data/test/matchers/action_mailer/have_sent_email_test.rb +70 -0
- data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +7 -1
- data/test/matchers/active_record/allow_value_matcher_test.rb +1 -1
- data/test/matchers/active_record/association_matcher_test.rb +16 -16
- data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +3 -2
- data/test/matchers/active_record/ensure_length_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/have_db_column_matcher_test.rb +1 -1
- data/test/matchers/active_record/have_db_index_matcher_test.rb +1 -1
- data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_format_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_presence_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +1 -1
- data/test/matchers/controller/assign_to_matcher_test.rb +11 -1
- data/test/matchers/controller/filter_param_matcher_test.rb +10 -2
- data/test/matchers/controller/redirect_to_matcher_test.rb +37 -0
- data/test/matchers/controller/render_template_matcher_test.rb +37 -0
- data/test/matchers/controller/render_with_layout_matcher_test.rb +15 -1
- data/test/matchers/controller/respond_with_content_type_matcher_test.rb +1 -1
- data/test/matchers/controller/respond_with_matcher_test.rb +1 -11
- data/test/matchers/controller/route_matcher_test.rb +18 -1
- data/test/matchers/controller/set_session_matcher_test.rb +11 -1
- data/test/matchers/controller/set_the_flash_matcher.rb +1 -1
- data/test/other/autoload_macro_test.rb +1 -1
- data/test/other/context_test.rb +210 -27
- data/test/other/convert_to_should_syntax_test.rb +1 -1
- data/test/other/helpers_test.rb +13 -36
- data/test/other/private_helpers_test.rb +2 -2
- data/test/other/should_test.rb +13 -13
- data/test/{model_builder.rb → rails2_model_builder.rb} +32 -8
- data/test/{rails_root → rails2_root}/app/controllers/application_controller.rb +0 -3
- data/test/{rails_root → rails2_root}/app/controllers/posts_controller.rb +0 -0
- data/test/{rails_root → rails2_root}/app/controllers/users_controller.rb +0 -0
- data/test/{rails_root → rails2_root}/app/helpers/application_helper.rb +0 -0
- data/test/{rails_root → rails2_root}/app/helpers/posts_helper.rb +0 -0
- data/test/{rails_root → rails2_root}/app/helpers/users_helper.rb +0 -0
- data/test/{rails_root → rails2_root}/app/models/address.rb +0 -0
- data/test/rails2_root/app/models/flea.rb +11 -0
- data/test/{rails_root → rails2_root}/app/models/friendship.rb +0 -0
- data/test/rails2_root/app/models/notifier.rb +8 -0
- data/test/{rails_root → rails2_root}/app/models/pets/cat.rb +0 -0
- data/test/{rails_root → rails2_root}/app/models/pets/dog.rb +0 -0
- data/test/{rails_root → rails2_root}/app/models/post.rb +1 -1
- data/test/{rails_root → rails2_root}/app/models/product.rb +0 -0
- data/test/{rails_root → rails2_root}/app/models/profile.rb +0 -0
- data/test/{rails_root → rails2_root}/app/models/registration.rb +0 -0
- data/test/{rails_root → rails2_root}/app/models/tag.rb +0 -0
- data/test/{rails_root → rails2_root}/app/models/tagging.rb +0 -0
- data/test/{rails_root → rails2_root}/app/models/treat.rb +0 -0
- data/test/{rails_root → rails2_root}/app/models/user.rb +0 -0
- data/test/{rails_root → rails2_root}/app/views/layouts/posts.rhtml +0 -0
- data/test/{rails_root → rails2_root}/app/views/layouts/users.rhtml +0 -0
- data/test/{rails_root → rails2_root}/app/views/layouts/wide.html.erb +0 -0
- data/test/rails2_root/app/views/notifier/the_email.html.erb +1 -0
- data/test/{rails_root → rails2_root}/app/views/posts/edit.rhtml +0 -0
- data/test/{rails_root → rails2_root}/app/views/posts/index.rhtml +0 -0
- data/test/{rails_root → rails2_root}/app/views/posts/new.rhtml +0 -0
- data/test/{rails_root → rails2_root}/app/views/posts/show.rhtml +0 -0
- data/test/{rails_root → rails2_root}/app/views/users/edit.rhtml +0 -0
- data/test/{rails_root → rails2_root}/app/views/users/index.rhtml +0 -0
- data/test/{rails_root → rails2_root}/app/views/users/new.rhtml +0 -0
- data/test/{rails_root → rails2_root}/app/views/users/show.rhtml +0 -0
- data/test/{rails_root → rails2_root}/config/boot.rb +0 -0
- data/test/{rails_root → rails2_root}/config/database.yml +1 -1
- data/test/{rails_root → rails2_root}/config/environment.rb +0 -1
- data/test/rails2_root/config/environments/test.rb +23 -0
- data/test/{rails_root → rails2_root}/config/initializers/new_rails_defaults.rb +0 -0
- data/test/{rails_root → rails2_root}/config/initializers/shoulda.rb +0 -0
- data/test/{rails_root → rails2_root}/config/routes.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/001_create_users.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/002_create_posts.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/003_create_taggings.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/004_create_tags.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/005_create_dogs.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/006_create_addresses.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/007_create_fleas.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/008_create_dogs_fleas.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/009_create_products.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/010_create_friendships.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/011_create_treats.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/20090506203502_create_profiles.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/20090506203536_create_registrations.rb +0 -0
- data/test/{rails_root → rails2_root}/db/migrate/20090513104502_create_cats.rb +0 -0
- data/test/{rails_root → rails2_root}/db/schema.rb +0 -0
- data/test/{rails_root → rails2_root}/public/404.html +0 -0
- data/test/{rails_root → rails2_root}/public/422.html +0 -0
- data/test/{rails_root → rails2_root}/public/500.html +0 -0
- data/test/{rails_root → rails2_root}/script/console +0 -0
- data/test/{rails_root → rails2_root}/script/generate +0 -0
- data/test/{rails_root → rails2_root}/test/shoulda_macros/custom_macro.rb +0 -0
- data/test/{rails_root → rails2_root}/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +0 -0
- data/test/{rails_root → rails2_root}/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +0 -0
- data/test/rails2_test_helper.rb +6 -0
- data/test/rails3_model_builder.rb +118 -0
- data/test/rails3_root/Gemfile +28 -0
- data/test/rails3_root/README +244 -0
- data/test/rails3_root/Rakefile +10 -0
- data/test/rails3_root/app/controllers/application_controller.rb +22 -0
- data/test/rails3_root/app/controllers/posts_controller.rb +87 -0
- data/test/rails3_root/app/controllers/users_controller.rb +82 -0
- data/test/rails3_root/app/helpers/application_helper.rb +2 -0
- data/test/rails3_root/app/models/address.rb +7 -0
- data/test/rails3_root/app/models/flea.rb +11 -0
- data/test/rails3_root/app/models/friendship.rb +4 -0
- data/test/rails3_root/app/models/notifier.rb +8 -0
- data/test/rails3_root/app/models/pets/cat.rb +7 -0
- data/test/rails3_root/app/models/pets/dog.rb +10 -0
- data/test/rails3_root/app/models/post.rb +12 -0
- data/test/rails3_root/app/models/product.rb +12 -0
- data/test/rails3_root/app/models/profile.rb +2 -0
- data/test/rails3_root/app/models/registration.rb +2 -0
- data/test/rails3_root/app/models/tag.rb +8 -0
- data/test/rails3_root/app/models/tagging.rb +4 -0
- data/test/rails3_root/app/models/treat.rb +3 -0
- data/test/rails3_root/app/models/user.rb +32 -0
- data/test/rails3_root/app/views/layouts/application.html.erb +14 -0
- data/test/rails3_root/app/views/layouts/posts.rhtml +19 -0
- data/test/rails3_root/app/views/layouts/users.rhtml +17 -0
- data/test/rails3_root/app/views/layouts/wide.html.erb +1 -0
- data/test/rails3_root/app/views/notifier/the_email.html.erb +1 -0
- data/test/rails3_root/app/views/posts/edit.rhtml +27 -0
- data/test/rails3_root/app/views/posts/index.rhtml +25 -0
- data/test/rails3_root/app/views/posts/new.rhtml +24 -0
- data/test/rails3_root/app/views/posts/show.rhtml +18 -0
- data/test/rails3_root/app/views/users/edit.rhtml +22 -0
- data/test/rails3_root/app/views/users/index.rhtml +22 -0
- data/test/rails3_root/app/views/users/new.rhtml +21 -0
- data/test/rails3_root/app/views/users/show.rhtml +13 -0
- data/test/rails3_root/config.ru +4 -0
- data/test/rails3_root/config/application.rb +46 -0
- data/test/rails3_root/config/boot.rb +6 -0
- data/test/rails3_root/config/database.yml +22 -0
- data/test/rails3_root/config/environment.rb +5 -0
- data/test/rails3_root/config/environments/development.rb +19 -0
- data/test/rails3_root/config/environments/production.rb +42 -0
- data/test/rails3_root/config/environments/test.rb +32 -0
- data/test/rails3_root/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails3_root/config/initializers/inflections.rb +10 -0
- data/test/rails3_root/config/initializers/mime_types.rb +5 -0
- data/test/rails3_root/config/initializers/secret_token.rb +7 -0
- data/test/rails3_root/config/initializers/session_store.rb +8 -0
- data/test/rails3_root/config/locales/en.yml +5 -0
- data/test/rails3_root/config/routes.rb +4 -0
- data/test/rails3_root/db/migrate/001_create_users.rb +19 -0
- data/test/rails3_root/db/migrate/002_create_posts.rb +13 -0
- data/test/rails3_root/db/migrate/003_create_taggings.rb +12 -0
- data/test/rails3_root/db/migrate/004_create_tags.rb +11 -0
- data/test/rails3_root/db/migrate/005_create_dogs.rb +12 -0
- data/test/rails3_root/db/migrate/006_create_addresses.rb +14 -0
- data/test/rails3_root/db/migrate/007_create_fleas.rb +11 -0
- data/test/rails3_root/db/migrate/008_create_dogs_fleas.rb +12 -0
- data/test/rails3_root/db/migrate/009_create_products.rb +17 -0
- data/test/rails3_root/db/migrate/010_create_friendships.rb +14 -0
- data/test/rails3_root/db/migrate/011_create_treats.rb +12 -0
- data/test/rails3_root/db/migrate/20090506203502_create_profiles.rb +12 -0
- data/test/rails3_root/db/migrate/20090506203536_create_registrations.rb +14 -0
- data/test/rails3_root/db/migrate/20090513104502_create_cats.rb +12 -0
- data/test/rails3_root/db/seeds.rb +7 -0
- data/test/rails3_root/public/404.html +26 -0
- data/test/rails3_root/public/422.html +26 -0
- data/test/rails3_root/public/500.html +26 -0
- data/test/{rails_root/config/environments/test.rb → rails3_root/public/favicon.ico} +0 -0
- data/test/rails3_root/public/images/rails.png +0 -0
- data/test/rails3_root/public/index.html +279 -0
- data/test/rails3_root/public/javascripts/application.js +2 -0
- data/test/rails3_root/public/javascripts/controls.js +965 -0
- data/test/rails3_root/public/javascripts/dragdrop.js +974 -0
- data/test/rails3_root/public/javascripts/effects.js +1123 -0
- data/test/rails3_root/public/javascripts/prototype.js +4874 -0
- data/test/rails3_root/public/javascripts/rails.js +118 -0
- data/test/rails3_root/public/robots.txt +5 -0
- data/test/rails3_root/script/rails +9 -0
- data/test/rails3_root/test/performance/browsing_test.rb +9 -0
- data/test/rails3_root/test/test_helper.rb +13 -0
- data/test/rails3_test_helper.rb +6 -0
- data/test/test_helper.rb +16 -8
- data/test/unit/address_test.rb +1 -1
- data/test/unit/cat_test.rb +1 -1
- data/test/unit/dog_test.rb +1 -1
- data/test/unit/flea_test.rb +9 -1
- data/test/unit/friendship_test.rb +1 -1
- data/test/unit/post_test.rb +1 -5
- data/test/unit/product_test.rb +1 -1
- data/test/unit/tag_test.rb +1 -5
- data/test/unit/tagging_test.rb +1 -1
- data/test/unit/user_test.rb +3 -37
- metadata +184 -118
- data/lib/shoulda/action_view.rb +0 -10
- data/lib/shoulda/action_view/macros.rb +0 -61
- data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +0 -128
- data/test/matchers/active_record/have_named_scope_matcher_test.rb +0 -65
- data/test/rails_root/app/models/flea.rb +0 -3
data/test/other/helpers_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
require 'action_mailer'
|
3
3
|
require 'mocha'
|
4
4
|
|
@@ -93,13 +93,6 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc:
|
|
93
93
|
should_change("the number of elements", :to => 4) { @a.length }
|
94
94
|
should_change("the first element", :by => 0) { @a[0] }
|
95
95
|
should_not_change("the first element") { @a[0] }
|
96
|
-
|
97
|
-
# tests for deprecated behavior
|
98
|
-
should_change "@a.length", :by => 1
|
99
|
-
should_change "@a.length", :from => 3
|
100
|
-
should_change "@a.length", :to => 4
|
101
|
-
should_change "@a[0]", :by => 0
|
102
|
-
should_not_change "@a[0]"
|
103
96
|
end
|
104
97
|
|
105
98
|
context "after replacing it with an array of strings" do
|
@@ -113,14 +106,6 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc:
|
|
113
106
|
should_change("the second element", :from => 2, :to => "b") { @a[1] }
|
114
107
|
should_change("the third element", :from => /\d/, :to => /\w/) { @a[2] }
|
115
108
|
should_change("the last element", :to => String) { @a[3] }
|
116
|
-
|
117
|
-
# tests for deprecated behavior
|
118
|
-
should_change "@a.length", :by => 3
|
119
|
-
should_change "@a.length", :from => 3, :to => 6, :by => 3
|
120
|
-
should_change "@a[0]"
|
121
|
-
should_change "@a[1]", :from => 2, :to => "b"
|
122
|
-
should_change "@a[2]", :from => /\d/, :to => /\w/
|
123
|
-
should_change "@a[3]", :to => String
|
124
109
|
end
|
125
110
|
end
|
126
111
|
|
@@ -148,16 +133,6 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc:
|
|
148
133
|
should "accept a class as the first argument" do
|
149
134
|
assert_good_value User, :email, "good@example.com"
|
150
135
|
end
|
151
|
-
|
152
|
-
context "with an instance variable" do
|
153
|
-
setup do
|
154
|
-
@product = Product.new(:tangible => true)
|
155
|
-
end
|
156
|
-
|
157
|
-
should "use that instance variable" do
|
158
|
-
assert_good_value Product, :price, "9999", /included/
|
159
|
-
end
|
160
|
-
end
|
161
136
|
end
|
162
137
|
|
163
138
|
context "assert_bad_value" do
|
@@ -184,16 +159,6 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc:
|
|
184
159
|
should "accept a class as the first argument" do
|
185
160
|
assert_bad_value User, :email, "bad"
|
186
161
|
end
|
187
|
-
|
188
|
-
context "with an instance variable" do
|
189
|
-
setup do
|
190
|
-
@product = Product.new(:tangible => true)
|
191
|
-
end
|
192
|
-
|
193
|
-
should "use that instance variable" do
|
194
|
-
assert_bad_value Product, :price, "0", /included/
|
195
|
-
end
|
196
|
-
end
|
197
162
|
end
|
198
163
|
|
199
164
|
context "a matching matcher" do
|
@@ -274,6 +239,18 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc:
|
|
274
239
|
end
|
275
240
|
end
|
276
241
|
|
242
|
+
should "assign context to a support matching on assert_accepts" do
|
243
|
+
matcher = stub('matcher', :matches? => true)
|
244
|
+
matcher.expects(:in_context).with(self)
|
245
|
+
assert_accepts matcher, nil
|
246
|
+
end
|
247
|
+
|
248
|
+
should "assign context to a support matching on assert_rejects" do
|
249
|
+
matcher = stub('matcher', :matches? => false)
|
250
|
+
matcher.expects(:in_context).with(self)
|
251
|
+
assert_rejects matcher, nil
|
252
|
+
end
|
253
|
+
|
277
254
|
context "given one treat exists and one post exists" do
|
278
255
|
setup do
|
279
256
|
Treat.create!
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class PrivateHelpersTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
include Shoulda::Private
|
@@ -22,7 +22,7 @@ class PrivateHelpersTest < ActiveSupport::TestCase # :nodoc:
|
|
22
22
|
get_options!(args, :one)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
should "return single wanted option" do
|
27
27
|
args = [:a, :b, {:class => Object}]
|
28
28
|
klass = get_options!(args,:class)
|
data/test/other/should_test.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
should "be able to define a should statement outside of a context" do
|
5
5
|
assert true
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
should "see the name of my class as ShouldTest" do
|
9
9
|
assert_equal "ShouldTest", self.class.name
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def self.should_see_class_methods
|
13
13
|
should "be able to see class methods" do
|
14
14
|
assert true
|
@@ -27,13 +27,13 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|
27
27
|
|
28
28
|
def self.should_see_blah
|
29
29
|
should "see @blah through a macro" do
|
30
|
-
assert @blah
|
30
|
+
assert @blah
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.should_not_see_blah
|
35
35
|
should "not see @blah through a macro" do
|
36
|
-
assert_nil @blah
|
36
|
+
assert_nil @blah
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -75,12 +75,12 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|
75
75
|
setup do
|
76
76
|
@blah = "blah"
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
should "have @blah == 'blah'" do
|
80
80
|
assert_equal "blah", @blah
|
81
81
|
end
|
82
82
|
should_see_blah
|
83
|
-
|
83
|
+
|
84
84
|
should "have name set right" do
|
85
85
|
assert_match(/^test: Context with setup block/, self.to_s)
|
86
86
|
end
|
@@ -89,11 +89,11 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|
89
89
|
setup do
|
90
90
|
@blah = "#{@blah} twice"
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
should "be named correctly" do
|
94
94
|
assert_match(/^test: Context with setup block and a subcontext should be named correctly/, self.to_s)
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
should "run the setup methods in order" do
|
98
98
|
assert_equal @blah, "blah twice"
|
99
99
|
end
|
@@ -105,7 +105,7 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|
105
105
|
setup do
|
106
106
|
@blah = "foo"
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
should "have @blah == 'foo'" do
|
110
110
|
assert_equal "foo", @blah
|
111
111
|
end
|
@@ -115,7 +115,7 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|
115
115
|
end
|
116
116
|
should_see_blah
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
should_eventually "pass, since it's a should_eventually" do
|
120
120
|
flunk "what?"
|
121
121
|
end
|
@@ -152,7 +152,7 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|
152
152
|
should "be good" do; end
|
153
153
|
should "another" do; end
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
names = context.shoulds.map {|s| s[:name]}
|
157
157
|
assert_equal ["another", "be good"], names.sort
|
158
158
|
end
|
@@ -164,7 +164,7 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|
164
164
|
setup do; "setup"; end
|
165
165
|
teardown do; "teardown"; end
|
166
166
|
end
|
167
|
-
|
167
|
+
|
168
168
|
assert_equal "setup", context.setup_blocks.first.call
|
169
169
|
assert_equal "teardown", context.teardown_blocks.first.call
|
170
170
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
class ActiveSupport::TestCase
|
1
|
+
class ActiveSupport::TestCase
|
2
|
+
|
3
|
+
TMP_VIEW_PATH =
|
4
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'rails2_root', 'tmp', 'views')).freeze
|
5
|
+
|
2
6
|
def create_table(table_name, &block)
|
3
7
|
connection = ActiveRecord::Base.connection
|
4
|
-
|
8
|
+
|
5
9
|
begin
|
6
10
|
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
7
11
|
connection.create_table(table_name, &block)
|
@@ -45,6 +49,14 @@ class ActiveSupport::TestCase
|
|
45
49
|
define_model_class(class_name, &block)
|
46
50
|
end
|
47
51
|
|
52
|
+
def define_mailer(name, paths, &block)
|
53
|
+
class_name = name.to_s.pluralize.classify
|
54
|
+
klass = define_constant(class_name, ActionMailer::Base, &block)
|
55
|
+
|
56
|
+
paths.each {|path| create_view("#{name}/#{path}", "<%= @message %>")}
|
57
|
+
klass.template_root = TMP_VIEW_PATH
|
58
|
+
end
|
59
|
+
|
48
60
|
def define_controller(class_name, &block)
|
49
61
|
class_name = class_name.to_s
|
50
62
|
class_name << 'Controller' unless class_name =~ /Controller$/
|
@@ -60,25 +72,35 @@ class ActiveSupport::TestCase
|
|
60
72
|
new_routes.draw(&block)
|
61
73
|
end
|
62
74
|
|
63
|
-
def build_response(&block)
|
75
|
+
def build_response(opts = {}, &block)
|
76
|
+
action = opts[:action] || 'example'
|
64
77
|
klass = define_controller('Examples')
|
65
78
|
block ||= lambda { render :nothing => true }
|
66
|
-
klass.class_eval { define_method(
|
67
|
-
define_routes do |map|
|
68
|
-
map.connect 'examples', :controller => 'examples', :action =>
|
79
|
+
klass.class_eval { define_method(action, &block) }
|
80
|
+
define_routes do |map|
|
81
|
+
map.connect 'examples', :controller => 'examples', :action => action
|
69
82
|
end
|
70
83
|
|
84
|
+
create_view("examples/#{action}.html.erb", "abc")
|
85
|
+
klass.view_paths = [TMP_VIEW_PATH]
|
86
|
+
|
71
87
|
@controller = klass.new
|
72
88
|
@request = ActionController::TestRequest.new
|
73
89
|
@response = ActionController::TestResponse.new
|
74
|
-
get
|
90
|
+
get action
|
75
91
|
|
76
92
|
@controller
|
77
93
|
end
|
78
94
|
|
95
|
+
def create_view(path, contents)
|
96
|
+
full_path = File.join(TMP_VIEW_PATH, path)
|
97
|
+
FileUtils.mkdir_p(File.dirname(full_path))
|
98
|
+
File.open(full_path, 'w') { |file| file.write(contents) }
|
99
|
+
end
|
100
|
+
|
79
101
|
def teardown_with_models
|
80
102
|
if @defined_constants
|
81
|
-
@defined_constants.each do |class_name|
|
103
|
+
@defined_constants.each do |class_name|
|
82
104
|
Object.send(:remove_const, class_name)
|
83
105
|
end
|
84
106
|
end
|
@@ -99,6 +121,8 @@ class ActiveSupport::TestCase
|
|
99
121
|
@replaced_routes.reload!
|
100
122
|
end
|
101
123
|
|
124
|
+
FileUtils.rm_rf(TMP_VIEW_PATH)
|
125
|
+
|
102
126
|
teardown_without_models
|
103
127
|
end
|
104
128
|
alias_method :teardown_without_models, :teardown
|
@@ -2,9 +2,6 @@
|
|
2
2
|
# Likewise, all the methods added will be available for all controllers.
|
3
3
|
|
4
4
|
class ApplicationController < ActionController::Base
|
5
|
-
# Pick a unique cookie name to distinguish our session data from others'
|
6
|
-
session :session_key => '_rails_root_session_id'
|
7
|
-
|
8
5
|
def ensure_logged_in
|
9
6
|
unless session[:logged_in]
|
10
7
|
respond_to do |accepts|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @body %>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The test environment is used exclusively to run your application's
|
4
|
+
# test suite. You never need to work with it otherwise. Remember that
|
5
|
+
# your test database is "scratch space" for the test suite and is wiped
|
6
|
+
# and recreated between test runs. Don't rely on the data there!
|
7
|
+
config.cache_classes = true
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.action_controller.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
config.action_view.cache_template_loading = true
|
16
|
+
|
17
|
+
# Disable request forgery protection in test environment
|
18
|
+
config.action_controller.allow_forgery_protection = false
|
19
|
+
|
20
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
21
|
+
# The :test delivery method accumulates sent emails in the
|
22
|
+
# ActionMailer::Base.deliveries array.
|
23
|
+
config.action_mailer.delivery_method = :test
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|