2011-02-24 47 views
1

我已經剖析了我的特徵文件。我發現我的登錄步驟花費了大部分時間。黃瓜速度,性能調整

Given /^I am logged in as "(.+)"$/ do |login| 
    visit path_to('the home page') 
    fill_in "login", :with => login 
    fill_in "password", :with => 'foobar' 
    click_button "loginButton" 
end 

我的開發箱需要5秒以上。

我想再次登錄登錄功能,但沒有填寫表單,只需設置會話,並在我的其他測試中用作背景場景。

Given /^I am logged in as "(.+)" through session$/ do |login| 
    user= User.find_by_login(login) 
end 

上述步驟找到用戶,但我如何使它存儲會話,並重定向我?

回答

0

你可以避免在其他步驟中進行身份驗證,可能不是一個死黃瓜開發人員會說什麼。但是,如果您在其他地方測試過身份驗證工作流程,那麼我沒有看到這種傷害。我沒有嘗試這個,但我認爲變量範圍應該是正確的。

Given /^I am logged in as "(.+)" through session$/ do |login| 
    @user= User.find_by_login(login) 
    #open the class and spike 
    class ApplicationController < ActionController::Base 
    def current_user 
     @user 
    end 
    end 
end 
+0

這不會取代current_user的剩餘的紅寶石進程的生命週期?如果是這樣,這可能會產生一些真正令人困惑的結果,如果你有其他黃瓜功能,_do_真的登錄... – 2011-02-25 13:32:01

+0

我同意,最好有點哈克。您可以使用after場景掛鉤將current_user重置爲零,也許可以通過標記捕獲場景以瞭解哪些場景需要登錄步驟運行。 – 2011-02-26 21:17:53