2012-02-10 80 views
2

我有这样的整合规格:无法使用Selenium,Capybara-webkit进行测试; RackTest工作正常

feature "When buying a deal, a user" do 
    let(:current_market) { Factory.create(:market) } 
    let(:deal) { Factory.create(:deal_with_products, market: current_market) } 

    scenario "can change quanitity and see an updated total" do 
    visit_checkout_for_product deal.products.first 
    # ... 
    end 

    # ... 
end 

def visit_checkout_for_product(product) 
    visit deal_path current_market, product.deal 
    choose product.title 
    click_button 'buy now' 
end 

这与RackTest奇妙的作品,但是当我改变规格到:

scenario "can change quanitity and see an updated total", js: true do 
    visit_checkout_for_product deal.products.first 
    # ... 
    end 

我的测试中突破,给我一个500 Internal Server错误,像这样:

enter image description here

我似乎无法找到反正拿到STA CK跟踪,但我确信nil:NilClass应该是deal让我们先定义变量。

我不明白的是为什么这不是一个问题,RackTest ...有一些额外的配置,我错过了吗?我使用RSpec 2.8.0Rails 3.1.1。如果您需要查看其他文件,请告诉我。

回答

3

问题是database_cleaner,配置不正确,因为它正在运行Selenium/capybara-webkit测试之前擦除我的测试数据。这里是我现在使用的配置,允许一切都通过:

DatabaseCleaner.strategy = :truncation 

RSpec.configure do |config| 
    config.use_transactional_fixtures = false 
    config.before(:each) { DatabaseCleaner.start } 
    config.after(:each) { DatabaseCleaner.clean } 
end 
+1

谢谢!有同样的问题。我正在使用交易。改为截断修复了它。 – jacklin 2012-10-25 18:21:20

相关问题