【问题标题】:cabybara-webkit + rspec: Records are not availablecabybara-webkit + rspec:记录不可用
【发布时间】:2011-08-30 21:06:30
【问题描述】:

我是集成测试的新手,虽然我已经为我的模型和控制器做了很多单元测试。但现在我想测试整个堆栈。 (我不想用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 doActiveRecord::RecordNotFound 就会被抛出。如果我在我的配置中禁用use_transactional_fixtures,它会再次工作,但这会破坏很多其他测试。是否有其他解决方案,或者我可以仅为我的集成测试禁用 transactional_fixtures?

感谢阅读! :)

【问题讨论】:

    标签: ruby-on-rails rspec integration-testing acceptance-testing


    【解决方案1】:

    您需要为集成测试设置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
    

    【讨论】:

    • 谢谢!但我不得不使用.before(:each).after(:each)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多