Sha256: 7908e9555f129b61399ff5ce416fc6d229408cc4e49336beb9e4599ba8893f37

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require 'woyo/world/attributes'

describe Woyo::Attributes do

  before :all do
    class AttrTest
      include Woyo::Attributes
      attributes :attr1, :attr2, :attr3
    end
  end
  
  it 'names can be listed for class' do
    attrs = AttrTest.attributes
    attrs.should be_instance_of Array
    attrs.count.should eq 3
    attrs.all? { |a| a.is_a? Symbol }.should be_true
  end                       

  it 'names and values can be retrieved for instance' do
    attrs = AttrTest.new.attributes
    attrs.should be_instance_of Hash
  end

  it 'can be written with =' do
    attr_test = AttrTest.new
    AttrTest.attributes.each do |attr|
      eval "attr_test.#{attr} = '#{attr}'.upcase"
    end
    attr_test.attributes.count.should eq AttrTest.attributes.count
    attr_test.attributes.each do |name,value|
      value.should eq name.to_s.upcase
    end
  end

  it 'can be written without =' do
    attr_test = AttrTest.new
    AttrTest.attributes.each do |attr|
      eval "attr_test.#{attr} '#{attr}'.upcase"
    end
    attr_test.attributes.count.should eq AttrTest.attributes.count
    attr_test.attributes.each do |name,value|
      value.should eq name.to_s.upcase
    end
  end

  it 'can be read' do
    attr_test = AttrTest.new
    AttrTest.attributes.each do |attr|
      eval "attr_test.#{attr} '#{attr}'.upcase"
    end
    attr_test.attributes.count.should eq AttrTest.attributes.count
    attr_test.attributes.each do |name,value|
      eval("attr_test.#{name}").should eq value
    end
  end

  it 'accepts string or symbol key for retrieval'

  it 'accepts string of symbol key for assignment'

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
woyo-world-0.0.1 spec/woyo/world/attributes_spec.rb
woyo-world-0.0.1.pre2 spec/woyo/world/attributes_spec.rb