我正在使用 FactoryGirl 为 Rails 相关的 gem 创建日期维度模型的实例。我的工厂是这样的:
FactoryGirl.define do
sequence :next_day do |n|
Date.new(2000,12,31) + n.days
end
factory :date_dimension do
the_date = FactoryGirl.generate(:next_day)
date {the_date.to_s}
calendar_year {the_date.strftime("%Y")}
(...other attributes created similarly to calendar_year)
end
end
出于沮丧,我实际上建立了一个小测试来显示什么不起作用:
describe "working date factories" do
before(:all) do
@date_dimension = FactoryGirl.create(:date_dimension)
@jan_two = FactoryGirl.create(:date_dimension)
end
describe "sequence incrementing" do
it "returns a date dimension object ok" do
@date_dimension.date.should == "2001-01-01"
end
it "returns the next date in the sequence" do
@jan_two.date.should == "2001-01-02"
end
end
end
当我运行该测试时,我得到:
working date factories
sequence incrementing
returns a date dimension object ok
returns the next date in the sequence (FAILED - 1)
Failures:
1) working date factories sequence incrementing returns the next date in the sequence
Failure/Error: @jan_two.date.should == "2001-01-02"
expected: "2001-01-02"
got: "2001-01-01" (using ==)
我已经阅读了一堆与序列相关的其他问题,但似乎我并没有犯其中发现的错误。这是一个不同的(可能更愚蠢的)错误。它是什么?