rspec - 为什么“eql”匹配器将数据添加到集合中

时间:2013-04-04 22:59:08

标签: rspec ruby-datamapper

我有两个规格。它们都测试来自公共前(:all)块的数据。如果我同时运行,第二个失败。

在一些日志记录中,似乎第1周被添加到@h_1两次 - 但这是在哪里发生的?

它似乎在第一个阻止的某个地方。如果我注释掉第一个,第二个就过去了。我不明白的是,语法在哪里说两次将@ w_1添加到@h_1两次?

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

0 个答案:

没有答案
相关问题