2012-08-07 59 views
0

我有以下测试,可以在Rack :: Test中使用但不使用Selenium。即如果我添加, js: true的描述块,我得到在Firefox的错误消息说,它couldn't find the License with id=(的@l的ID)不使用Selenium保存模型,但使用Rack保存:测试

describe "should hide allocation rule # for pdf & clickthrough licenses" do 

    it "reads current state and shows/hides fields appropriately" do          
    @l = FactoryGirl.create(:license:, 
          way: License::CLICK_WAY)                      
    visit edit_admin_license_path(@l)                       
    end 
end 

为什么?我必须缺少东西。我可以使用Sequel Pro验证在使用js: true时记录没有保存。

我需要此规范在Selenium中运行,因为我有javascript来测试。

+0

尝试检查'日志/ test.log'并确认正确的行动正在达成。你也可以在'visit'后面加上'save_and_open_page'来在浏览器中显示页面。 – zetetic 2012-08-07 23:15:07

+0

可能与你的数据库策略有关,你可以包含'spec_helper.rb'吗? – 2012-08-07 23:43:03

回答

0

简单的解决方案是关闭事务夹具。

Why does my Cucumber test fail when run with Selenium?

在规范

/spec_helper.rb:

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

    config.before :each do 
    if Capybara.current_driver == :rack_test 
     DatabaseCleaner.strategy = :transaction 
    else 
     DatabaseCleaner.strategy = :truncation 
    end 
    DatabaseCleaner.start 
    end 

    config.after do 
    DatabaseCleaner.clean 
    end 
end 

,并在Gemfile中,试验段

gem 'database_cleaner' 
+0

这是一个很好的参考设置您的配置rspec请求规格:http://highgroove.com/articles/2012/04/06/sane-rspec-config-for-clean,-and-slightly-faster,-specs .html – 2012-08-07 23:45:13

+0

谢谢shioyama,伟大的文章! – Ivan 2012-08-08 05:17:03