Sha256: 4dac52b4791f70ae467bc2a3a8711aaabdefffbbec425695887c9c6fc1071f1f

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe ClassyAdornments, "#adorn" do

  let(:test_class) do
    dummy = Class.new
    dummy.send(:include, ClassyAdornments)
    dummy
  end

  describe "with single argument" do

    subject do
      test_class.adorn :some_attr
      test_class
    end

    its(:instance_methods){should include('some_attr') }
    its(:instance_methods){should include('some_attr=') }

    it "should provide working getter/setter method" do
      obj = subject.new
      obj.some_attr.should == nil
      obj.some_attr(5).should == 5
      obj.some_attr.should == 5
    end

    it "should create the an instance variable" do
      obj = subject.new
      attribute = Object.new
      obj.some_attr(attribute)

      obj.instance_variable_get("@some_attr").should equal(attribute)
    end

  end

  describe "with empty array argument" do

    subject do
      test_class.adorn :array_attr, :array => true
      test_class.new
    end

    its("class.instance_methods"){should     include('array_attr') }
    its("class.instance_methods"){should_not include('array_attr=') }

    it "should append single values" do
      subject.array_attr.should == []
      subject.array_attr :something
      subject.array_attr.should == [:something]
    end

    it "should append an array of values" do
      subject.array_attr.should == []
      subject.array_attr 1
      subject.array_attr [2,3]
      subject.array_attr.should == [1,2,3]
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
classy-adornments-0.1.2 spec/classy_adornments_spec.rb