instiki/vendor/rails/activesupport/test/core_ext/module/attribute_accessor_test.rb

40 lines
958 B
Ruby
Raw Normal View History

require 'abstract_unit'
2007-02-10 00:12:31 +01:00
class ModuleAttributeAccessorTest < Test::Unit::TestCase
def setup
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
@class.instance_eval { include m }
2007-02-10 00:12:31 +01:00
@object = @class.new
end
2007-02-10 00:12:31 +01:00
def test_should_use_mattr_default
assert_nil @module.foo
assert_nil @object.foo
end
2007-02-10 00:12:31 +01:00
def test_should_set_mattr_value
@module.foo = :test
assert_equal :test, @object.foo
2007-02-10 00:12:31 +01:00
@object.foo = :test2
assert_equal :test2, @module.foo
end
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
end