在每个示例之后,factory_girl + rspec似乎没有回滚更改 [英] factory_girl + rspec doesn't seem to roll back changes after each example
本文介绍了在每个示例之后,factory_girl + rspec似乎没有回滚更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
类似于此处描述的问题: http://rpheath.com/posts/411-how -to-use-factory-girl-with-rspec
Similar to the problem described here: http://rpheath.com/posts/411-how-to-use-factory-girl-with-rspec
简写(缩短代码)
spec_helper:
spec_helper:
config.use_transactional_fixtures = true
config.use_instantiated_fixtures = false
factories.rb:
factories.rb:
Factory.define :state do
f.name "NY"
end
在我的规范中
before(:each) do
@static_model = Factory(:state) # with validate uniqueness of state name
end
错误:
重复的条目名称"NY"等.
duplicate entry name "NY" etc.
问题: rspec不应在每个规格示例之前清除数据库,从而不会引发重复的输入错误吗?
Question: Shouldn't rspec clear database before each spec example and hence not throwing duplicate entry errors?
推荐答案
我认为:
- 您是否使用
rake spec
运行测试套件:这会从头开始建立数据库(以确保没有任何粘附) - 您在任何地方都使用
before (:all)
吗?因为您在before :all
中创建的任何内容都应在after :all
中再次删除,否则它会继续存在.
- do you use
rake spec
to run your testsuite: that builds up the database from scratch (to make sure nothing is sticking) - do you use, anywhere, a
before (:all)
? Because whatever you create inside abefore :all
should be deleted again in aafter :all
or it keeps on existing.
这篇关于在每个示例之后,factory_girl + rspec似乎没有回滚更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文