使用JS的Capybara请求规范问题 - 无法找到模型

时间:2012-05-21 20:29:21

标签: ruby-on-rails capybara capybara-webkit

我遇到了JS请求规范的问题 - 模型编辑页面的基本访问:

it "can edit a doc", :js => true do
  doc = FactoryGirl.create(:doc) # tried with Doc.create as well
  puts Doc.find(doc.id) # 1 <- so it's definitely in the DB!
  visit edit_doc_path(doc) 
end

结果: “ActiveRecord :: RecordNotFound - 找不到ID = 1的文档”

奇怪的是它适用于标准请求规范。我尝试了webkit和selenium驱动程序。我的spec_helper看起来像这样(应该很标准):

RSpec.configure do |config|
  config.use_transactional_fixtures = false

  Capybara.javascript_driver = :webkit

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.before(:each, :type => :request) do
    Capybara.reset_sessions!
  end
end

Rails 3.1.4,没有版本的capybara,rspec等测试库。

任何输入都非常感谢!谢谢!

1 个答案:

答案 0 :(得分:-1)

好像你有同样的问题: Capybara with :js => true causes test to fail

尝试将DatabaseCleaner策略设置为:截断并查看其是否有效

config.before(:suite) do
  DatabaseCleaner.strategy = :truncation
end