2011-06-21 38 views
3

我最近安裝了一個名爲Gretel的插件來照顧我的麪包屑。這似乎是偉大的工作,但它似乎是打破我的一些規格與下面的錯誤:Rails 3 - 如何擺脫「test.host」?

Failure/Error: response.should redirect_to @course 
Expected response to be a redirect to </courses/904> but was a redirect to 
<http://test.host/courses/904> 

我能做些什麼來擺脫這種錯誤的?該路徑似乎完全正確,除了那個麻煩的test.host的東西。

回答

4

你可能對測試代替my_model_url my_model_path

前者的做一個完整的URI - 包括主機。後者是沒有主機的相對路徑。

請檢查您的控制器,看看它是否使用_path或_url - 並在您的測試用例中使用同一個。

+1

謝謝!作爲對其他人的一個提示,在我的測試中,我沒有明確地檢查URL。在我的控制器中,我有「redirect_to @course」,在測試中我也有「response.should redirect_to @course」。顯然這兩者之間有些不同(我還不太瞭解),我需要在測試中更明確地將測試路徑定義爲「response.should redirect_to course_path(@course)」,以使其工作。 – sapphiremirage

+0

很酷 - 很高興知道。我想redirect_to(@course)只是默認爲完整路徑。 –

1

您需要明確定義您的請求body..Here我有應用程序使用rails 3.0 ...我使用Devise進行身份驗證..我得到一個用戶指定的自定義域。

#get user from fixtures OR create them 

    @user = users(:user1) 

    #used devise "sign_in for testing" 

    sign_in :user, @user 
    #defined my request 

    request.host = 'myblog.free-blog.com' 

    #get 'show_blog" 

    get 'show'