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.
- data/Gemfile +9 -0
- data/Gemfile.lock +108 -0
- data/README.md +95 -0
- data/Rakefile +6 -50
- data/lib/shoulda/version.rb +1 -1
- metadata +50 -269
- data/README.rdoc +0 -154
- data/bin/convert_to_should_syntax +0 -42
- data/lib/shoulda.rb +0 -9
- data/lib/shoulda/action_controller.rb +0 -34
- data/lib/shoulda/action_controller/macros.rb +0 -221
- data/lib/shoulda/action_controller/matchers.rb +0 -39
- data/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +0 -112
- data/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +0 -74
- data/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb +0 -62
- data/lib/shoulda/action_controller/matchers/render_template_matcher.rb +0 -54
- data/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +0 -99
- data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +0 -74
- data/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +0 -85
- data/lib/shoulda/action_controller/matchers/route_matcher.rb +0 -93
- data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +0 -98
- data/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +0 -100
- data/lib/shoulda/action_mailer.rb +0 -13
- data/lib/shoulda/action_mailer/assertions.rb +0 -42
- data/lib/shoulda/action_mailer/matchers.rb +0 -22
- data/lib/shoulda/action_mailer/matchers/have_sent_email.rb +0 -110
- data/lib/shoulda/active_record.rb +0 -16
- data/lib/shoulda/active_record/assertions.rb +0 -69
- data/lib/shoulda/active_record/helpers.rb +0 -32
- data/lib/shoulda/active_record/macros.rb +0 -457
- data/lib/shoulda/active_record/matchers.rb +0 -42
- data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +0 -83
- data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +0 -110
- data/lib/shoulda/active_record/matchers/association_matcher.rb +0 -226
- data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +0 -87
- data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +0 -141
- data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +0 -169
- data/lib/shoulda/active_record/matchers/have_db_index_matcher.rb +0 -112
- data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +0 -59
- data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +0 -41
- data/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb +0 -65
- data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +0 -39
- data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +0 -60
- data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +0 -148
- data/lib/shoulda/active_record/matchers/validation_matcher.rb +0 -56
- data/lib/shoulda/assertions.rb +0 -79
- data/lib/shoulda/autoload_macros.rb +0 -46
- data/lib/shoulda/context.rb +0 -433
- data/lib/shoulda/helpers.rb +0 -8
- data/lib/shoulda/integrations/rspec.rb +0 -13
- data/lib/shoulda/integrations/rspec2.rb +0 -22
- data/lib/shoulda/integrations/test_unit.rb +0 -22
- data/lib/shoulda/macros.rb +0 -161
- data/lib/shoulda/private_helpers.rb +0 -13
- data/lib/shoulda/proc_extensions.rb +0 -14
- data/lib/shoulda/rails.rb +0 -8
- data/lib/shoulda/tasks.rb +0 -3
- data/lib/shoulda/tasks/list_tests.rake +0 -29
- data/lib/shoulda/tasks/yaml_to_shoulda.rake +0 -28
- data/rails/init.rb +0 -8
- data/test/README +0 -36
- data/test/fail_macros.rb +0 -55
- data/test/fixtures/addresses.yml +0 -3
- data/test/fixtures/friendships.yml +0 -0
- data/test/fixtures/posts.yml +0 -5
- data/test/fixtures/products.yml +0 -0
- data/test/fixtures/taggings.yml +0 -0
- data/test/fixtures/tags.yml +0 -9
- data/test/fixtures/users.yml +0 -6
- data/test/functional/posts_controller_test.rb +0 -121
- data/test/functional/users_controller_test.rb +0 -19
- data/test/matchers/action_mailer/have_sent_email_test.rb +0 -70
- data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +0 -74
- data/test/matchers/active_record/allow_value_matcher_test.rb +0 -64
- data/test/matchers/active_record/association_matcher_test.rb +0 -263
- data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +0 -81
- data/test/matchers/active_record/ensure_length_of_matcher_test.rb +0 -158
- data/test/matchers/active_record/have_db_column_matcher_test.rb +0 -169
- data/test/matchers/active_record/have_db_index_matcher_test.rb +0 -91
- data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +0 -29
- data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +0 -44
- data/test/matchers/active_record/validate_format_of_matcher_test.rb +0 -39
- data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +0 -52
- data/test/matchers/active_record/validate_presence_of_matcher_test.rb +0 -86
- data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +0 -147
- data/test/matchers/controller/assign_to_matcher_test.rb +0 -45
- data/test/matchers/controller/filter_param_matcher_test.rb +0 -40
- data/test/matchers/controller/redirect_to_matcher_test.rb +0 -37
- data/test/matchers/controller/render_template_matcher_test.rb +0 -37
- data/test/matchers/controller/render_with_layout_matcher_test.rb +0 -47
- data/test/matchers/controller/respond_with_content_type_matcher_test.rb +0 -32
- data/test/matchers/controller/respond_with_matcher_test.rb +0 -96
- data/test/matchers/controller/route_matcher_test.rb +0 -75
- data/test/matchers/controller/set_session_matcher_test.rb +0 -48
- data/test/matchers/controller/set_the_flash_matcher.rb +0 -95
- data/test/other/autoload_macro_test.rb +0 -18
- data/test/other/context_test.rb +0 -372
- data/test/other/convert_to_should_syntax_test.rb +0 -63
- data/test/other/helpers_test.rb +0 -317
- data/test/other/private_helpers_test.rb +0 -32
- data/test/other/should_test.rb +0 -271
- data/test/rails2_model_builder.rb +0 -130
- data/test/rails2_root/app/controllers/application_controller.rb +0 -22
- data/test/rails2_root/app/controllers/posts_controller.rb +0 -87
- data/test/rails2_root/app/controllers/users_controller.rb +0 -84
- data/test/rails2_root/app/helpers/application_helper.rb +0 -3
- data/test/rails2_root/app/helpers/posts_helper.rb +0 -2
- data/test/rails2_root/app/helpers/users_helper.rb +0 -2
- data/test/rails2_root/app/models/address.rb +0 -7
- data/test/rails2_root/app/models/flea.rb +0 -11
- data/test/rails2_root/app/models/friendship.rb +0 -4
- data/test/rails2_root/app/models/notifier.rb +0 -8
- data/test/rails2_root/app/models/pets/cat.rb +0 -7
- data/test/rails2_root/app/models/pets/dog.rb +0 -10
- data/test/rails2_root/app/models/post.rb +0 -12
- data/test/rails2_root/app/models/product.rb +0 -12
- data/test/rails2_root/app/models/profile.rb +0 -2
- data/test/rails2_root/app/models/registration.rb +0 -2
- data/test/rails2_root/app/models/tag.rb +0 -8
- data/test/rails2_root/app/models/tagging.rb +0 -4
- data/test/rails2_root/app/models/treat.rb +0 -3
- data/test/rails2_root/app/models/user.rb +0 -32
- data/test/rails2_root/app/views/layouts/posts.rhtml +0 -19
- data/test/rails2_root/app/views/layouts/users.rhtml +0 -17
- data/test/rails2_root/app/views/layouts/wide.html.erb +0 -1
- data/test/rails2_root/app/views/notifier/the_email.html.erb +0 -1
- data/test/rails2_root/app/views/posts/edit.rhtml +0 -27
- data/test/rails2_root/app/views/posts/index.rhtml +0 -25
- data/test/rails2_root/app/views/posts/new.rhtml +0 -26
- data/test/rails2_root/app/views/posts/show.rhtml +0 -18
- data/test/rails2_root/app/views/users/edit.rhtml +0 -22
- data/test/rails2_root/app/views/users/index.rhtml +0 -22
- data/test/rails2_root/app/views/users/new.rhtml +0 -21
- data/test/rails2_root/app/views/users/show.rhtml +0 -13
- data/test/rails2_root/config/boot.rb +0 -110
- data/test/rails2_root/config/database.yml +0 -4
- data/test/rails2_root/config/environment.rb +0 -17
- data/test/rails2_root/config/environments/test.rb +0 -23
- data/test/rails2_root/config/initializers/new_rails_defaults.rb +0 -15
- data/test/rails2_root/config/initializers/shoulda.rb +0 -8
- data/test/rails2_root/config/routes.rb +0 -6
- data/test/rails2_root/db/migrate/001_create_users.rb +0 -19
- data/test/rails2_root/db/migrate/002_create_posts.rb +0 -13
- data/test/rails2_root/db/migrate/003_create_taggings.rb +0 -12
- data/test/rails2_root/db/migrate/004_create_tags.rb +0 -11
- data/test/rails2_root/db/migrate/005_create_dogs.rb +0 -12
- data/test/rails2_root/db/migrate/006_create_addresses.rb +0 -14
- data/test/rails2_root/db/migrate/007_create_fleas.rb +0 -11
- data/test/rails2_root/db/migrate/008_create_dogs_fleas.rb +0 -12
- data/test/rails2_root/db/migrate/009_create_products.rb +0 -17
- data/test/rails2_root/db/migrate/010_create_friendships.rb +0 -14
- data/test/rails2_root/db/migrate/011_create_treats.rb +0 -12
- data/test/rails2_root/db/migrate/20090506203502_create_profiles.rb +0 -12
- data/test/rails2_root/db/migrate/20090506203536_create_registrations.rb +0 -14
- data/test/rails2_root/db/migrate/20090513104502_create_cats.rb +0 -12
- data/test/rails2_root/db/schema.rb +0 -0
- data/test/rails2_root/log/test.log +0 -50381
- data/test/rails2_root/public/404.html +0 -30
- data/test/rails2_root/public/422.html +0 -30
- data/test/rails2_root/public/500.html +0 -30
- data/test/rails2_root/script/console +0 -3
- data/test/rails2_root/script/generate +0 -3
- data/test/rails2_root/test/shoulda_macros/custom_macro.rb +0 -6
- data/test/rails2_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +0 -6
- data/test/rails2_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +0 -6
- data/test/rails2_test_helper.rb +0 -6
- data/test/rails3_model_builder.rb +0 -118
- data/test/rails3_root/Gemfile +0 -28
- data/test/rails3_root/README +0 -244
- data/test/rails3_root/Rakefile +0 -10
- data/test/rails3_root/app/controllers/application_controller.rb +0 -22
- data/test/rails3_root/app/controllers/posts_controller.rb +0 -87
- data/test/rails3_root/app/controllers/users_controller.rb +0 -82
- data/test/rails3_root/app/helpers/application_helper.rb +0 -2
- data/test/rails3_root/app/models/address.rb +0 -7
- data/test/rails3_root/app/models/flea.rb +0 -11
- data/test/rails3_root/app/models/friendship.rb +0 -4
- data/test/rails3_root/app/models/notifier.rb +0 -8
- data/test/rails3_root/app/models/pets/cat.rb +0 -7
- data/test/rails3_root/app/models/pets/dog.rb +0 -10
- data/test/rails3_root/app/models/post.rb +0 -12
- data/test/rails3_root/app/models/product.rb +0 -12
- data/test/rails3_root/app/models/profile.rb +0 -2
- data/test/rails3_root/app/models/registration.rb +0 -2
- data/test/rails3_root/app/models/tag.rb +0 -8
- data/test/rails3_root/app/models/tagging.rb +0 -4
- data/test/rails3_root/app/models/treat.rb +0 -3
- data/test/rails3_root/app/models/user.rb +0 -32
- data/test/rails3_root/app/views/layouts/application.html.erb +0 -14
- data/test/rails3_root/app/views/layouts/posts.rhtml +0 -19
- data/test/rails3_root/app/views/layouts/users.rhtml +0 -17
- data/test/rails3_root/app/views/layouts/wide.html.erb +0 -1
- data/test/rails3_root/app/views/notifier/the_email.html.erb +0 -1
- data/test/rails3_root/app/views/posts/edit.rhtml +0 -27
- data/test/rails3_root/app/views/posts/index.rhtml +0 -25
- data/test/rails3_root/app/views/posts/new.rhtml +0 -24
- data/test/rails3_root/app/views/posts/show.rhtml +0 -18
- data/test/rails3_root/app/views/users/edit.rhtml +0 -22
- data/test/rails3_root/app/views/users/index.rhtml +0 -22
- data/test/rails3_root/app/views/users/new.rhtml +0 -21
- data/test/rails3_root/app/views/users/show.rhtml +0 -13
- data/test/rails3_root/config.ru +0 -4
- data/test/rails3_root/config/application.rb +0 -46
- data/test/rails3_root/config/boot.rb +0 -6
- data/test/rails3_root/config/database.yml +0 -22
- data/test/rails3_root/config/environment.rb +0 -5
- data/test/rails3_root/config/environments/development.rb +0 -19
- data/test/rails3_root/config/environments/production.rb +0 -42
- data/test/rails3_root/config/environments/test.rb +0 -32
- data/test/rails3_root/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails3_root/config/initializers/inflections.rb +0 -10
- data/test/rails3_root/config/initializers/mime_types.rb +0 -5
- data/test/rails3_root/config/initializers/secret_token.rb +0 -7
- data/test/rails3_root/config/initializers/session_store.rb +0 -8
- data/test/rails3_root/config/locales/en.yml +0 -5
- data/test/rails3_root/config/routes.rb +0 -4
- data/test/rails3_root/db/migrate/001_create_users.rb +0 -19
- data/test/rails3_root/db/migrate/002_create_posts.rb +0 -13
- data/test/rails3_root/db/migrate/003_create_taggings.rb +0 -12
- data/test/rails3_root/db/migrate/004_create_tags.rb +0 -11
- data/test/rails3_root/db/migrate/005_create_dogs.rb +0 -12
- data/test/rails3_root/db/migrate/006_create_addresses.rb +0 -14
- data/test/rails3_root/db/migrate/007_create_fleas.rb +0 -11
- data/test/rails3_root/db/migrate/008_create_dogs_fleas.rb +0 -12
- data/test/rails3_root/db/migrate/009_create_products.rb +0 -17
- data/test/rails3_root/db/migrate/010_create_friendships.rb +0 -14
- data/test/rails3_root/db/migrate/011_create_treats.rb +0 -12
- data/test/rails3_root/db/migrate/20090506203502_create_profiles.rb +0 -12
- data/test/rails3_root/db/migrate/20090506203536_create_registrations.rb +0 -14
- data/test/rails3_root/db/migrate/20090513104502_create_cats.rb +0 -12
- data/test/rails3_root/db/seeds.rb +0 -7
- data/test/rails3_root/db/test.sqlite3 +0 -0
- data/test/rails3_root/log/test.log +0 -10834
- data/test/rails3_root/public/404.html +0 -26
- data/test/rails3_root/public/422.html +0 -26
- data/test/rails3_root/public/500.html +0 -26
- data/test/rails3_root/public/favicon.ico +0 -0
- data/test/rails3_root/public/images/rails.png +0 -0
- data/test/rails3_root/public/index.html +0 -279
- data/test/rails3_root/public/javascripts/application.js +0 -2
- data/test/rails3_root/public/javascripts/controls.js +0 -965
- data/test/rails3_root/public/javascripts/dragdrop.js +0 -974
- data/test/rails3_root/public/javascripts/effects.js +0 -1123
- data/test/rails3_root/public/javascripts/prototype.js +0 -4874
- data/test/rails3_root/public/javascripts/rails.js +0 -118
- data/test/rails3_root/public/robots.txt +0 -5
- data/test/rails3_root/script/rails +0 -9
- data/test/rails3_root/test/performance/browsing_test.rb +0 -9
- data/test/rails3_root/test/test_helper.rb +0 -13
- data/test/rails3_test_helper.rb +0 -6
- data/test/rspec_test.rb +0 -207
- data/test/test_helper.rb +0 -36
- data/test/unit/address_test.rb +0 -10
- data/test/unit/cat_test.rb +0 -7
- data/test/unit/dog_test.rb +0 -9
- data/test/unit/flea_test.rb +0 -14
- data/test/unit/friendship_test.rb +0 -6
- data/test/unit/post_test.rb +0 -15
- data/test/unit/product_test.rb +0 -23
- data/test/unit/tag_test.rb +0 -11
- data/test/unit/tagging_test.rb +0 -6
- data/test/unit/user_test.rb +0 -46
data/test/other/helpers_test.rb
DELETED
@@ -1,317 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'action_mailer'
|
3
|
-
require 'mocha'
|
4
|
-
|
5
|
-
class HelpersTest < ActiveSupport::TestCase # :nodoc:
|
6
|
-
|
7
|
-
context "given delivered emails" do
|
8
|
-
setup do
|
9
|
-
email1 = stub(:subject => "one", :to => ["none1@email.com"])
|
10
|
-
email2 = stub(:subject => "two", :to => ["none2@email.com"])
|
11
|
-
ActionMailer::Base.stubs(:deliveries).returns([email1, email2])
|
12
|
-
end
|
13
|
-
|
14
|
-
should "have sent an email" do
|
15
|
-
assert_sent_email
|
16
|
-
|
17
|
-
assert_raises(Test::Unit::AssertionFailedError) do
|
18
|
-
assert_did_not_send_email
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
should "find email one" do
|
23
|
-
assert_sent_email do |e|
|
24
|
-
e.subject =~ /one/
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
should "not find an email that doesn't exist" do
|
29
|
-
assert_raises(Test::Unit::AssertionFailedError) do
|
30
|
-
assert_sent_email do |e|
|
31
|
-
e.subject =~ /whatever/
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when there are no emails" do
|
38
|
-
setup do
|
39
|
-
ActionMailer::Base.stubs(:deliveries).returns([])
|
40
|
-
end
|
41
|
-
|
42
|
-
should "not have sent an email" do
|
43
|
-
assert_did_not_send_email
|
44
|
-
|
45
|
-
assert_raises(Test::Unit::AssertionFailedError) do
|
46
|
-
assert_sent_email
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "an array of values" do
|
52
|
-
setup do
|
53
|
-
@a = ['abc', 'def', 3]
|
54
|
-
end
|
55
|
-
|
56
|
-
[/b/, 'abc', 3].each do |x|
|
57
|
-
should "contain #{x.inspect}" do
|
58
|
-
assert_raises(Test::Unit::AssertionFailedError) do
|
59
|
-
assert_does_not_contain @a, x
|
60
|
-
end
|
61
|
-
assert_contains @a, x
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
should "not contain 'wtf'" do
|
66
|
-
assert_raises(Test::Unit::AssertionFailedError) {assert_contains @a, 'wtf'}
|
67
|
-
assert_does_not_contain @a, 'wtf'
|
68
|
-
end
|
69
|
-
|
70
|
-
should "be the same as another array, ordered differently" do
|
71
|
-
assert_same_elements(@a, [3, "def", "abc"])
|
72
|
-
assert_raises(Test::Unit::AssertionFailedError) do
|
73
|
-
assert_same_elements(@a, [3, 3, "def", "abc"])
|
74
|
-
end
|
75
|
-
assert_raises(Test::Unit::AssertionFailedError) do
|
76
|
-
assert_same_elements([@a, "abc"].flatten, [3, 3, "def", "abc"])
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "an array of values" do
|
82
|
-
setup do
|
83
|
-
@a = [1, 2, "(3)"]
|
84
|
-
end
|
85
|
-
|
86
|
-
context "after adding another value" do
|
87
|
-
setup do
|
88
|
-
@a.push(4)
|
89
|
-
end
|
90
|
-
|
91
|
-
should_change("the number of elements", :by => 1) { @a.length }
|
92
|
-
should_change("the number of elements", :from => 3) { @a.length }
|
93
|
-
should_change("the number of elements", :to => 4) { @a.length }
|
94
|
-
should_change("the first element", :by => 0) { @a[0] }
|
95
|
-
should_not_change("the first element") { @a[0] }
|
96
|
-
end
|
97
|
-
|
98
|
-
context "after replacing it with an array of strings" do
|
99
|
-
setup do
|
100
|
-
@a = %w(a b c d e f)
|
101
|
-
end
|
102
|
-
|
103
|
-
should_change("the number of elements", :by => 3) { @a.length }
|
104
|
-
should_change("the number of elements", :from => 3, :to => 6, :by => 3) { @a.length }
|
105
|
-
should_change("the first element") { @a[0] }
|
106
|
-
should_change("the second element", :from => 2, :to => "b") { @a[1] }
|
107
|
-
should_change("the third element", :from => /\d/, :to => /\w/) { @a[2] }
|
108
|
-
should_change("the last element", :to => String) { @a[3] }
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context "assert_good_value" do
|
113
|
-
should "validate a good email address" do
|
114
|
-
assert_good_value User.new, :email, "good@example.com"
|
115
|
-
end
|
116
|
-
|
117
|
-
should "validate a good SSN with a custom message" do
|
118
|
-
assert_good_value User.new, :ssn, "xxxxxxxxx", /length/
|
119
|
-
end
|
120
|
-
|
121
|
-
should "fail to validate a bad email address" do
|
122
|
-
assert_raises Test::Unit::AssertionFailedError do
|
123
|
-
assert_good_value User.new, :email, "bad"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
should "fail to validate a bad SSN that is too short" do
|
128
|
-
assert_raises Test::Unit::AssertionFailedError do
|
129
|
-
assert_good_value User.new, :ssn, "x", /length/
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
should "accept a class as the first argument" do
|
134
|
-
assert_good_value User, :email, "good@example.com"
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "assert_bad_value" do
|
139
|
-
should "invalidate a bad email address" do
|
140
|
-
assert_bad_value User.new, :email, "bad"
|
141
|
-
end
|
142
|
-
|
143
|
-
should "invalidate a bad SSN with a custom message" do
|
144
|
-
assert_bad_value User.new, :ssn, "x", /length/
|
145
|
-
end
|
146
|
-
|
147
|
-
should "fail to invalidate a good email address" do
|
148
|
-
assert_raises Test::Unit::AssertionFailedError do
|
149
|
-
assert_bad_value User.new, :email, "good@example.com"
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
should "fail to invalidate a good SSN" do
|
154
|
-
assert_raises Test::Unit::AssertionFailedError do
|
155
|
-
assert_bad_value User.new, :ssn, "xxxxxxxxx", /length/
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
should "accept a class as the first argument" do
|
160
|
-
assert_bad_value User, :email, "bad"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "a matching matcher" do
|
165
|
-
setup do
|
166
|
-
@matcher = stub('matcher', :matches? => true,
|
167
|
-
:failure_message => 'bad failure message',
|
168
|
-
:negative_failure_message => 'big time failure')
|
169
|
-
end
|
170
|
-
|
171
|
-
should "pass when given to assert_accepts with no message expectation" do
|
172
|
-
assert_accepts @matcher, 'target'
|
173
|
-
end
|
174
|
-
|
175
|
-
should "pass when given to assert_accepts with a matching message" do
|
176
|
-
assert_accepts @matcher, 'target', :message => /big time/
|
177
|
-
end
|
178
|
-
|
179
|
-
should "fail when given to assert_accepts with non-matching message" do
|
180
|
-
assert_raise Test::Unit::AssertionFailedError do
|
181
|
-
assert_accepts @matcher, 'target', :message => /small time/
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context "when given to assert_rejects" do
|
186
|
-
setup do
|
187
|
-
begin
|
188
|
-
assert_rejects @matcher, 'target'
|
189
|
-
rescue Test::Unit::AssertionFailedError => @error
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
should "fail" do
|
194
|
-
assert_not_nil @error
|
195
|
-
end
|
196
|
-
|
197
|
-
should "use the error message from the matcher" do
|
198
|
-
assert_equal 'big time failure', @error.message
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context "a non-matching matcher" do
|
204
|
-
setup do
|
205
|
-
@matcher = stub('matcher', :matches? => false,
|
206
|
-
:failure_message => 'big time failure',
|
207
|
-
:negative_failure_message => 'bad failure message')
|
208
|
-
end
|
209
|
-
|
210
|
-
should "pass when given to assert_rejects with no message expectation" do
|
211
|
-
assert_rejects @matcher, 'target'
|
212
|
-
end
|
213
|
-
|
214
|
-
should "pass when given to assert_rejects with a matching message" do
|
215
|
-
assert_rejects @matcher, 'target', :message => /big time/
|
216
|
-
end
|
217
|
-
|
218
|
-
should "fail when given to assert_rejects with a non-matching message" do
|
219
|
-
assert_raise Test::Unit::AssertionFailedError do
|
220
|
-
assert_rejects @matcher, 'target', :message => /small time/
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context "when given to assert_accepts" do
|
225
|
-
setup do
|
226
|
-
begin
|
227
|
-
assert_accepts @matcher, 'target'
|
228
|
-
rescue Test::Unit::AssertionFailedError => @error
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
should "fail" do
|
233
|
-
assert_not_nil @error
|
234
|
-
end
|
235
|
-
|
236
|
-
should "use the error message from the matcher" do
|
237
|
-
assert_equal 'big time failure', @error.message
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
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
|
-
|
254
|
-
context "given one treat exists and one post exists" do
|
255
|
-
setup do
|
256
|
-
Treat.create!
|
257
|
-
Post.create!(:title => 'title', :body => 'body', :user_id => 1)
|
258
|
-
end
|
259
|
-
|
260
|
-
teardown do
|
261
|
-
Treat.delete_all
|
262
|
-
Post.delete_all
|
263
|
-
end
|
264
|
-
|
265
|
-
context "creating a treat" do
|
266
|
-
setup do
|
267
|
-
Treat.create!
|
268
|
-
end
|
269
|
-
|
270
|
-
should_create :treat
|
271
|
-
should_fail do
|
272
|
-
should_create :post
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context "creating a treat and a post" do
|
277
|
-
setup do
|
278
|
-
Treat.create!
|
279
|
-
Post.create!(:title => 'title 2', :body => 'body', :user_id => 1)
|
280
|
-
end
|
281
|
-
|
282
|
-
should_create :treat
|
283
|
-
should_create :post
|
284
|
-
end
|
285
|
-
|
286
|
-
context "destroying a treat" do
|
287
|
-
setup do
|
288
|
-
Treat.first.destroy
|
289
|
-
end
|
290
|
-
|
291
|
-
should_destroy :treat
|
292
|
-
should_fail do
|
293
|
-
should_destroy :post
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
context "destroying a treat and a post" do
|
298
|
-
setup do
|
299
|
-
Treat.first.destroy
|
300
|
-
Post.first.destroy
|
301
|
-
end
|
302
|
-
|
303
|
-
should_destroy :treat
|
304
|
-
should_destroy :post
|
305
|
-
end
|
306
|
-
|
307
|
-
context "doing nothing" do
|
308
|
-
should_fail do
|
309
|
-
should_create :treat
|
310
|
-
end
|
311
|
-
|
312
|
-
should_fail do
|
313
|
-
should_destroy :treat
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PrivateHelpersTest < ActiveSupport::TestCase # :nodoc:
|
4
|
-
include Shoulda::Private
|
5
|
-
context "get_options!" do
|
6
|
-
should "remove opts from args" do
|
7
|
-
args = [:a, :b, {}]
|
8
|
-
get_options!(args)
|
9
|
-
assert_equal [:a, :b], args
|
10
|
-
end
|
11
|
-
|
12
|
-
should "return wanted opts in order" do
|
13
|
-
args = [{:one => 1, :two => 2}]
|
14
|
-
one, two = get_options!(args, :one, :two)
|
15
|
-
assert_equal 1, one
|
16
|
-
assert_equal 2, two
|
17
|
-
end
|
18
|
-
|
19
|
-
should "raise ArgumentError if given unwanted option" do
|
20
|
-
args = [{:one => 1, :two => 2}]
|
21
|
-
assert_raises ArgumentError do
|
22
|
-
get_options!(args, :one)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
should "return single wanted option" do
|
27
|
-
args = [:a, :b, {:class => Object}]
|
28
|
-
klass = get_options!(args,:class)
|
29
|
-
assert_equal Object, klass
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/test/other/should_test.rb
DELETED
@@ -1,271 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
4
|
-
should "be able to define a should statement outside of a context" do
|
5
|
-
assert true
|
6
|
-
end
|
7
|
-
|
8
|
-
should "see the name of my class as ShouldTest" do
|
9
|
-
assert_equal "ShouldTest", self.class.name
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.should_see_class_methods
|
13
|
-
should "be able to see class methods" do
|
14
|
-
assert true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.should_be_able_to_setup_a_should_eventually_in_a_class_method
|
19
|
-
should "be able to setup a should eventually in a class method"
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.should_see_a_context_block_like_a_Test_Unit_class
|
23
|
-
should "see a context block as a Test::Unit class" do
|
24
|
-
assert_equal "ShouldTest", self.class.name
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.should_see_blah
|
29
|
-
should "see @blah through a macro" do
|
30
|
-
assert @blah
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.should_not_see_blah
|
35
|
-
should "not see @blah through a macro" do
|
36
|
-
assert_nil @blah
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.should_be_able_to_make_context_macros(prefix = nil)
|
41
|
-
context "a macro" do
|
42
|
-
should "have the tests named correctly" do
|
43
|
-
assert_match(/^test: #{prefix}a macro should have the tests named correctly/, self.to_s)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "Context" do
|
49
|
-
|
50
|
-
should_see_class_methods
|
51
|
-
should_see_a_context_block_like_a_Test_Unit_class
|
52
|
-
should_be_able_to_make_context_macros("Context ")
|
53
|
-
should_be_able_to_setup_a_should_eventually_in_a_class_method
|
54
|
-
|
55
|
-
should "not define @blah" do
|
56
|
-
assert ! self.instance_variables.include?("@blah")
|
57
|
-
end
|
58
|
-
|
59
|
-
should_not_see_blah
|
60
|
-
|
61
|
-
should "be able to define a should statement" do
|
62
|
-
assert true
|
63
|
-
end
|
64
|
-
|
65
|
-
should "see the name of my class as ShouldTest" do
|
66
|
-
assert_equal "ShouldTest", self.class.name
|
67
|
-
end
|
68
|
-
|
69
|
-
context "with a subcontext" do
|
70
|
-
should_be_able_to_make_context_macros("Context with a subcontext ")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context "Context with setup block" do
|
75
|
-
setup do
|
76
|
-
@blah = "blah"
|
77
|
-
end
|
78
|
-
|
79
|
-
should "have @blah == 'blah'" do
|
80
|
-
assert_equal "blah", @blah
|
81
|
-
end
|
82
|
-
should_see_blah
|
83
|
-
|
84
|
-
should "have name set right" do
|
85
|
-
assert_match(/^test: Context with setup block/, self.to_s)
|
86
|
-
end
|
87
|
-
|
88
|
-
context "and a subcontext" do
|
89
|
-
setup do
|
90
|
-
@blah = "#{@blah} twice"
|
91
|
-
end
|
92
|
-
|
93
|
-
should "be named correctly" do
|
94
|
-
assert_match(/^test: Context with setup block and a subcontext should be named correctly/, self.to_s)
|
95
|
-
end
|
96
|
-
|
97
|
-
should "run the setup methods in order" do
|
98
|
-
assert_equal @blah, "blah twice"
|
99
|
-
end
|
100
|
-
should_see_blah
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "Another context with setup block" do
|
105
|
-
setup do
|
106
|
-
@blah = "foo"
|
107
|
-
end
|
108
|
-
|
109
|
-
should "have @blah == 'foo'" do
|
110
|
-
assert_equal "foo", @blah
|
111
|
-
end
|
112
|
-
|
113
|
-
should "have name set right" do
|
114
|
-
assert_match(/^test: Another context with setup block/, self.to_s)
|
115
|
-
end
|
116
|
-
should_see_blah
|
117
|
-
end
|
118
|
-
|
119
|
-
should_eventually "pass, since it's a should_eventually" do
|
120
|
-
flunk "what?"
|
121
|
-
end
|
122
|
-
|
123
|
-
# Context creation and naming
|
124
|
-
|
125
|
-
def test_should_create_a_new_context
|
126
|
-
assert_nothing_raised do
|
127
|
-
Shoulda::Context.new("context name", self) do; end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_should_create_a_nested_context
|
132
|
-
assert_nothing_raised do
|
133
|
-
parent = Shoulda::Context.new("Parent", self) do; end
|
134
|
-
child = Shoulda::Context.new("Child", parent) do; end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_should_name_a_contexts_correctly
|
139
|
-
parent = Shoulda::Context.new("Parent", self) do; end
|
140
|
-
child = Shoulda::Context.new("Child", parent) do; end
|
141
|
-
grandchild = Shoulda::Context.new("GrandChild", child) do; end
|
142
|
-
|
143
|
-
assert_equal "Parent", parent.full_name
|
144
|
-
assert_equal "Parent Child", child.full_name
|
145
|
-
assert_equal "Parent Child GrandChild", grandchild.full_name
|
146
|
-
end
|
147
|
-
|
148
|
-
# Should statements
|
149
|
-
|
150
|
-
def test_should_have_should_hashes_when_given_should_statements
|
151
|
-
context = Shoulda::Context.new("name", self) do
|
152
|
-
should "be good" do; end
|
153
|
-
should "another" do; end
|
154
|
-
end
|
155
|
-
|
156
|
-
names = context.shoulds.map {|s| s[:name]}
|
157
|
-
assert_equal ["another", "be good"], names.sort
|
158
|
-
end
|
159
|
-
|
160
|
-
# setup and teardown
|
161
|
-
|
162
|
-
def test_should_capture_setup_and_teardown_blocks
|
163
|
-
context = Shoulda::Context.new("name", self) do
|
164
|
-
setup do; "setup"; end
|
165
|
-
teardown do; "teardown"; end
|
166
|
-
end
|
167
|
-
|
168
|
-
assert_equal "setup", context.setup_blocks.first.call
|
169
|
-
assert_equal "teardown", context.teardown_blocks.first.call
|
170
|
-
end
|
171
|
-
|
172
|
-
# building
|
173
|
-
|
174
|
-
def test_should_create_shoulda_test_for_each_should_on_build
|
175
|
-
context = Shoulda::Context.new("name", self) do
|
176
|
-
should "one" do; end
|
177
|
-
should "two" do; end
|
178
|
-
end
|
179
|
-
context.expects(:create_test_from_should_hash).with(has_entry(:name => "one"))
|
180
|
-
context.expects(:create_test_from_should_hash).with(has_entry(:name => "two"))
|
181
|
-
context.build
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_should_create_test_methods_on_build
|
185
|
-
tu_class = ActiveSupport::TestCase
|
186
|
-
context = Shoulda::Context.new("A Context", tu_class) do
|
187
|
-
should "define the test" do; end
|
188
|
-
end
|
189
|
-
|
190
|
-
tu_class.expects(:define_method).with(:"test: A Context should define the test. ")
|
191
|
-
context.build
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_should_create_test_methods_on_build_when_subcontext
|
195
|
-
tu_class = ActiveSupport::TestCase
|
196
|
-
context = Shoulda::Context.new("A Context", tu_class) do
|
197
|
-
context "with a child" do
|
198
|
-
should "define the test" do; end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
tu_class.expects(:define_method).with(:"test: A Context with a child should define the test. ")
|
203
|
-
context.build
|
204
|
-
end
|
205
|
-
|
206
|
-
# Test::Unit integration
|
207
|
-
|
208
|
-
def test_should_create_a_new_context_and_build_it_on_Test_Unit_context
|
209
|
-
c = mock("context")
|
210
|
-
c.expects(:build)
|
211
|
-
Shoulda::Context.expects(:new).with("foo", kind_of(Class)).returns(c)
|
212
|
-
self.class.context "foo" do; end
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should
|
216
|
-
s = mock("test")
|
217
|
-
Shoulda::Context.any_instance.expects(:should).with("rock", {}).returns(s)
|
218
|
-
Shoulda::Context.any_instance.expects(:build)
|
219
|
-
self.class.should "rock" do; end
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should_eventually
|
223
|
-
s = mock("test")
|
224
|
-
Shoulda::Context.any_instance.expects(:should_eventually).with("rock").returns(s)
|
225
|
-
Shoulda::Context.any_instance.expects(:build)
|
226
|
-
self.class.should_eventually "rock" do; end
|
227
|
-
end
|
228
|
-
|
229
|
-
should "run a :before proc", :before => lambda { @value = "before" } do
|
230
|
-
assert_equal "before", @value
|
231
|
-
end
|
232
|
-
|
233
|
-
context "A :before proc" do
|
234
|
-
setup do
|
235
|
-
assert_equal "before", @value
|
236
|
-
@value = "setup"
|
237
|
-
end
|
238
|
-
|
239
|
-
should "run before the current setup", :before => lambda { @value = "before" } do
|
240
|
-
assert_equal "setup", @value
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
context "a before statement" do
|
245
|
-
setup do
|
246
|
-
assert_equal "before", @value
|
247
|
-
@value = "setup"
|
248
|
-
end
|
249
|
-
|
250
|
-
before_should "run before the current setup" do
|
251
|
-
@value = "before"
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
context "A context" do
|
256
|
-
setup do
|
257
|
-
@value = "outer"
|
258
|
-
end
|
259
|
-
|
260
|
-
context "with a subcontext and a :before proc" do
|
261
|
-
before = lambda do
|
262
|
-
assert "outer", @value
|
263
|
-
@value = "before"
|
264
|
-
end
|
265
|
-
should "run after the parent setup", :before => before do
|
266
|
-
assert_equal "before", @value
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
end
|