diff options
author | Jamis Buck <jamis@37signals.com> | 2007-01-15 17:12:32 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2007-01-15 17:12:32 +0000 |
commit | f28eef9a272fd9280416fd8c0984f616ffe102fe (patch) | |
tree | 96acb772243c040f574563fc39a9855773d6139e /activesupport/test | |
parent | 8368e160b4acddf0204a84a9f8d360dcd99fe0ce (diff) | |
download | rails-f28eef9a272fd9280416fd8c0984f616ffe102fe.tar.gz rails-f28eef9a272fd9280416fd8c0984f616ffe102fe.tar.bz2 rails-f28eef9a272fd9280416fd8c0984f616ffe102fe.zip |
Add Object#acts_like? and Time#acts_like_time? and Date#acts_like_date? to facilitate duck-typing
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5951 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/object_and_class_ext_test.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 9daf8d0ac4..e48d87a198 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -96,6 +96,34 @@ class ObjectTests < Test::Unit::TestCase assert object.respond_to?(:baz) end + class DuckTime + def acts_like_time? + true + end + end + + def test_duck_typing + object = Object.new + time = Time.now + date = Date.today + dt = DateTime.new + duck = DuckTime.new + + assert !object.acts_like?(:time) + assert !object.acts_like?(:date) + + assert time.acts_like?(:time) + assert !time.acts_like?(:date) + + assert !date.acts_like?(:time) + assert date.acts_like?(:date) + + assert dt.acts_like?(:time) + assert dt.acts_like?(:date) + + assert duck.acts_like?(:time) + assert !duck.acts_like?(:date) + end end class ObjectInstanceVariableTest < Test::Unit::TestCase |