Sha256: aaacf7af03a07c53156414e5ad995ea774b61ab186962da2cb2c28895a591a27

Contents?: true

Size: 1.22 KB

Versions: 8

Compression:

Stored size: 1.22 KB

Contents

require File.dirname(__FILE__)+'/../spec_helper'
require 'gorillib/metaprogramming/mattr_accessor'

describe Module do
  describe 'mattr_accessor' do
    before do
      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

    it 'does not have an effect if already provided by another library.'

    it 'uses mattr default' do
      @module.foo.should be_nil
      @object.foo.should be_nil
    end

    it 'sets mattr value' do
      @module.foo = :test
      @object.foo.should == :test

      @object.foo = :test2
      @module.foo.should == :test2
    end

    it 'with :instance_writer => false, does not create instance writer' do
      @module.should respond_to(:foo)
      @module.should respond_to(:foo=)
      @object.should respond_to(:bar)
      @object.should_not respond_to(:bar=)
    end

    it 'with :instance_writer => false, does not create instance reader' do
      @module.should respond_to(:shaq)
      @object.should_not respond_to(:shaq)
      @object.should_not respond_to(:shaq=)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gorillib-0.1.7 spec/metaprogramming/mattr_accessor_spec.rb
gorillib-0.1.6 spec/metaprogramming/mattr_accessor_spec.rb
gorillib-0.1.5 spec/metaprogramming/mattr_accessor_spec.rb
gorillib-0.1.4 spec/metaprogramming/mattr_accessor_spec.rb
gorillib-0.1.3 spec/metaprogramming/mattr_accessor_spec.rb
gorillib-0.1.2 spec/metaprogramming/mattr_accessor_spec.rb
gorillib-0.1.1 spec/metaprogramming/mattr_accessor_spec.rb
gorillib-0.1.0 spec/metaprogramming/mattr_accessor_spec.rb