2010-08-25 70 views
0

我有以下代碼訪問on Rails的控制器中的 「請求」 變量測試

require 'test_helper' 

class ApplicationControllerTest < ActionController::TestCase 
    test "should display the page in german" do 
    get :index 
    assert_response :success 
    # ... 
    request.env["HTTP_REFERER"] = :index 
    # ... 
    end 
end 

如果我運行該軌道的功能測試與

$ rake test:functionals 

我得到這個錯誤:

test_should_display_the_page_in_german(ApplicationControllerTest): 
NameError: undefined local variable or method `request' for #<ApplicationControllerTest:0x1044c6d00> 

我如何訪問「請求」變量?

回答

6
@request.env["HTTP_REFERER"] = :index 

Testing Guide

4.4實例變量可用 您還可以訪問三個實例變量在功能測試:

@controller – The controller processing the request 
@request – The request 
@response – The response 
相關問題