cabybara-webkit + rspec:记录不可用
我是集成测试的新手,虽然我已经为我的模型和控制器做了很多unit testing。 但现在我想测试整个堆栈。 (我不想使用Cucumber,因为没有客户,我可以阅读代码)
这是我的(简化)规范
describe ArticlesController, "#show" do before do @article = Factory :article, :title => "Lorem ipsum" end it "should show the article page" do visit article_path(:id => @article) page.should have_content("Lorem ipsum") end end
规范通过了,但是一旦我添加:js => true
, it "should show the article page", :js => true do
,抛出一个ActiveRecord::RecordNotFound
。 如果我在我的配置中禁用use_transactional_fixtures
,它会再次起作用,但这会打破很多其他测试。 是否有另一种解决方案或者我可以为我的集成测试禁用transactional_fixtures吗?
谢谢阅读! 🙂
您需要为集成测试设置use_transactional_fixtures
= false。 正如您所发现的,这会导致其他测试出现问题,这些测试假设您的表一开始是空的。
您可以尝试使用database_cleaner gem。 spec_helper
的典型配置如下所示:
RSpec.configure do |c| c.before(:suite) do DatabaseCleaner.start end c.after(:suite) do DatabaseCleaner.clean end end