2012-08-07 62 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