cabybara-webkit + rspec: Records are not available

微笑、不失礼 提交于 2020-01-15 11:19:09

问题


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

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?

Thanks for reading! :)


回答1:


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.

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


来源:https://stackoverflow.com/questions/7249827/cabybara-webkit-rspec-records-are-not-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!