2008-05-18 06:22:34 +02:00
|
|
|
require 'abstract_unit'
|
2007-02-10 00:12:31 +01:00
|
|
|
|
|
|
|
class ModuleAttributeAccessorTest < Test::Unit::TestCase
|
|
|
|
def setup
|
2007-12-21 08:48:59 +01:00
|
|
|
m = @module = Module.new do
|
2007-02-10 00:12:31 +01:00
|
|
|
mattr_accessor :foo
|
2010-05-25 19:45:45 +02:00
|
|
|
mattr_accessor :bar, :instance_writer => false
|
|
|
|
mattr_reader :shaq, :instance_reader => false
|
2007-02-10 00:12:31 +01:00
|
|
|
end
|
|
|
|
@class = Class.new
|
2007-12-21 08:48:59 +01:00
|
|
|
@class.instance_eval { include m }
|
2007-02-10 00:12:31 +01:00
|
|
|
@object = @class.new
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-02-10 00:12:31 +01:00
|
|
|
def test_should_use_mattr_default
|
|
|
|
assert_nil @module.foo
|
|
|
|
assert_nil @object.foo
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-02-10 00:12:31 +01:00
|
|
|
def test_should_set_mattr_value
|
|
|
|
@module.foo = :test
|
|
|
|
assert_equal :test, @object.foo
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-02-10 00:12:31 +01:00
|
|
|
@object.foo = :test2
|
|
|
|
assert_equal :test2, @module.foo
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-02-10 00:12:31 +01:00
|
|
|
def test_should_not_create_instance_writer
|
|
|
|
assert @module.respond_to?(:foo)
|
|
|
|
assert @module.respond_to?(:foo=)
|
|
|
|
assert @object.respond_to?(:bar)
|
|
|
|
assert !@object.respond_to?(:bar=)
|
|
|
|
end
|
2010-05-25 19:45:45 +02:00
|
|
|
|
|
|
|
def test_should_not_create_instance_reader
|
|
|
|
assert @module.respond_to?(:shaq)
|
|
|
|
assert !@object.respond_to?(:shaq)
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
end
|