Sha256: 559afe6f6b392026c0f14c777c11350e28e7f2019147221b174572804244c4c7

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 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

    it "should append groups of arguments" 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.2.0 spec/classy_adornments_spec.rb