2011-07-13 26 views
2

我的驗證測試登錄頁面時出現奇怪的問題。當js啓用時驗收測試失敗

登錄工作正常,當js在未啓用ie。以下情況:

scenario "login with valid authentication" do 
    visit login_path 
    page.should have_content("Sprout Login") 
    fill_in("user_login", :with => "mark") 
    fill_in("user_password", :with => "secured") 
    click_button "Sign in" 
    page.should have_content("mark") 
    end 

但是,當我啓用JavaScript,登錄失敗,並提供無效登錄消息。

scenario "login with valid authentication", :js => true do 
    visit login_path 
    page.should have_content("Sprout Login") 
    fill_in("user_login", :with => "mark") 
    fill_in("user_password", :with => "secured") 
    click_button "Sign in" 
    page.should have_content("mark") 
    end 

順便說一句我正在使用Devise進行身份驗證。 在此先感謝。

更新:最近注意到,當啓用js時,測試服務器沒有啓動,因此登錄失敗。任何想法?

回答

0

除非創建了默認用戶並在每次測試運行前登錄,否則您的測試將失敗。 Devise提供測試助手,使創建和登錄默認用戶變得簡單。創建一個文件規範/支持/ devise.rb:

RSpec.configure do |config| 
    config.include Devise::TestHelpers, :type => :controller 
end 
+0

它對你有幫助嗎? – Anatoly

+0

不,我想問題是與啓動測試服務器。當我啓動測試時,我想它必須自動啓動測試服務器,但它不會。我必須手動啓動服務器'rails -s -e test',然後再次測試,它的工作原理。令人困惑的是,爲什麼只有在啓用了js的情況下才會發生這種情況。 :S – kxhitiz

0

我有同樣的問題,並發現a thread with a solution

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

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

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

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

end 

對於DatabaseCleaner東西的工作,你會需要包括database_cleaner寶石。如果您之前沒有使用過,則在重新運行測試之前,您可能需要rake db:test:prepare。我希望這也適用於你!

相關問題