我正在将一个应用程序从 Rails 3 升级到 Rails 4,并拥有一个名为 item 的模型,其架构如下:
#===Schema Information
# Table name: items
#
#type :string
#maturity: string
以及包含一系列测试的规范,但我特别遇到问题的是这个:
describe 'next_version' do
it 'should return the created_at date of the Item one version higher' do
first = FactoryGirl.create(:item, maturity: 'PRODUCTION')
second = FactoryGirl.create(:item, maturity: 'PREPRODUCTION', created_at: Time.now.in_time_zone)
expect(first.next_version_created_at.to_s)to eq second.created_at.utc.to_s)
修复,我相信很简单..只需添加..
created_at: Time.now.in_time_zone
..到生产项目并完成。然而,如果我单独运行它,测试就会通过,并且整个规范在 Rails 3 中通过(146 个测试),但是当我现在运行整个规范时,这个和其他 3 个类似的情况会失败,除非我单独运行它们。 p>
想法?
最佳答案
你可以尝试在每次测试前重新加载工厂女孩。尝试将其添加到spec_helper.rb
config.before(:each) do
FactoryGirl.reload
end
关于ruby-on-rails - FactoryGirl 的 RSpec 测试失败,隔离时通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30037237/