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