I have two specs. They both test data from a common before(:all) block. If I run both, the second one fails.
Putting in some logging statements, it seems like Week 1 is being added to @h_1 twice - but where is this happening?
It seems to be somewhere in the first it block. If I comment out the first, the second one passes. What I don't understand is, where in the syntax is it saying two add @w_1 to @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" do
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 a week is added to hobby" do
subject { @h_1.weeks[0] }
it "should be stored in the 'weeks' property of the hobby" do
should eql @w_1 #if I comment out this the spec below will pass
end
end
context "when another week is added to hobby" do
it "hobby should have two weeks" do
@h_1.weeks.length.should eql 2
@h_1.weeks.first(:id => 2).should_not eql nil
end
end
end