Sha256: 7ef0f76d0ff9c36ee3b94fe87f0ac212594d2a9e064105a305a91823032a844b

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

require File.dirname(__FILE__)+'/../abstract_unit'
require 'gorillib/metaprogramming/cattr_accessor'

class ModuleAttributeAccessorTest < Test::Unit::TestCase
  def setup
    m = @module = Module.new do
      mattr_accessor :foo
      mattr_accessor :bar, :instance_writer => false
      mattr_reader   :shaq, :instance_reader => false
    end
    @class = Class.new
    @class.instance_eval { include m }
    @object = @class.new
  end

  def test_should_use_mattr_default
    assert_nil @module.foo
    assert_nil @object.foo
  end

  def test_should_set_mattr_value
    @module.foo = :test
    assert_equal :test, @object.foo

    @object.foo = :test2
    assert_equal :test2, @module.foo
  end

  def test_should_not_create_instance_writer
    assert_respond_to @module, :foo
    assert_respond_to @module, :foo=
    assert_respond_to @object, :bar
    assert !@object.respond_to?(:bar=)
  end

  def test_should_not_create_instance_reader
    assert_respond_to @module, :shaq
    assert !@object.respond_to?(:shaq)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gorillib-0.0.7 test/metaprogramming/mattr_accessor_test.rb
gorillib-0.0.6 test/metaprogramming/mattr_accessor_test.rb
gorillib-0.0.5 test/metaprogramming/mattr_accessor_test.rb
gorillib-0.0.4 test/metaprogramming/mattr_accessor_test.rb
gorillib-0.0.3 test/metaprogramming/mattr_accessor_test.rb
gorillib-0.0.2 test/metaprogramming/mattr_accessor_test.rb