Sha256: 7f0cc1f096392397f267f044d4258e128e14e266567657ad8d3173df4875df73

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require File.expand_path('../spec_helper', File.dirname(__FILE__))
require 'gorillib/metaprogramming/cattr_accessor'

describe 'metaprogramming' do
  describe 'cattr_accessor' do
    before do
      @class = Class.new do
        cattr_accessor :foo
        cattr_accessor :bar,  :instance_writer => false
        cattr_reader   :shaq, :instance_reader => false
      end
      @object = @class.new
    end

    it 'does not have an effect if already provided by another library.' unless ENV['QUIET_RSPEC']

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

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

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gorillib-0.6.0 old/spec/gorillib/metaprogramming/cattr_accessor_spec.rb
gorillib-0.5.2 old/spec/gorillib/metaprogramming/cattr_accessor_spec.rb