cabybara-webkit + rspec:记录不可用 [英] cabybara-webkit + rspec: Records are not available

查看:88
本文介绍了cabybara-webkit + rspec:记录不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是集成测试的新手,尽管我已经为模型和控制器做了很多单元测试.但是现在我要测试整个堆栈. (我不想使用Cucumber,因为没有客户,而且我可以阅读代码)

I'm new to the integration testing, although I've done a lot of unit tests for my models and controllers. But now I want to test the whole stack. (I don't want to use Cucumber, since there is no customer and I can read code)

这是我的(简化的)规格

Here my (simplified) spec

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?

The spec passes, but once I add :js => true to it "should show the article page", :js => true do, an ActiveRecord::RecordNotFound gets thrown. If I disable use_transactional_fixtures in my config, it works again, but that breaks alot of other tests. Is there another solution or can I disable the transactional_fixtures just for my integration tests?

感谢您的阅读! :)

推荐答案

对于集成测试,您需要设置use_transactional_fixtures = false.如您所见,这会导致其他假设您的表开始为空的测试出现问题.

You need to set use_transactional_fixtures = false for integration tests. As you found, this causes problems for other tests that assume your tables are empty to start with.

您可以尝试使用 database_cleaner gem. spec_helper中的典型配置如下所示:

You might try the database_cleaner gem. A typical configuration in spec_helper would look like so:

RSpec.configure do |c|
  c.before(:suite) do
    DatabaseCleaner.start
  end

  c.after(:suite) do
    DatabaseCleaner.clean
  end
end

这篇关于cabybara-webkit + rspec:记录不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆