ruby datamapper - rspec - why is "eql" matcher adding data to collection -
i have 2 specs. both test data common before(:all) block. if run both, second 1 fails.
putting in logging statements, seems week 1 being added @h_1 twice - happening?
it seems somewhere in first block. if comment out first, second 1 passes. don't understand is, in syntax saying 2 add @w_1 @h_1 twice?
require 'data_mapper' datamapper::setup(:default, "sqlite3://#{dir.pwd}../data/prod.db") class hobby include datamapper::resource property :id, string, :key => true has n, :weeks, :through => resource end class week include datamapper::resource property :id, integer, :key => true has n, :hobbys, :through => resource end datamapper.finalize.auto_migrate! describe "hobby" before(:all){ @h_1 = hobby.create(:id => "zombies") @w_1 = week.create(:id => 1) @w_2 = week.create(:id => 2) @h_1.weeks << @w_1 @h_1.weeks << @w_2 @h_1.save } context "when week added hobby" subject { @h_1.weeks[0] } "should stored in 'weeks' property of hobby" should eql @w_1 #if comment out spec below pass end end context "when week added hobby" "hobby should have 2 weeks" @h_1.weeks.length.should eql 2 @h_1.weeks.first(:id => 2).should_not eql nil end end end
Comments
Post a Comment