2009-07-23 51 views
0

我已經開發的before_filter - http://gist.github.com/138659和 測試,如測試用的before_filter

test "should get index" do 
    get :index 
    assert_response :success 
    assert_not_nil assigns(:articles) 
    end 

我看到

test_should_get_index(ArticlesControllerTest): 
NoMethodError: You have a nil object when you didn't expect it! 
You might have expected an instance of Array. 
The error occurred while evaluating nil.split 
    app/controllers/application_controller.rb:20:in 

set_locale' /test/functional/articles_controller_test.rb:5:in test_should_get_index」

當我加入

setup do 
@request.headers['HTTP_ACCEPT_LANGUAGE'] = "en" 
end 

沒有什麼改變:(你能告訴我PLZ - 什麼是錯的?

線路2.3.2,紅寶石1.8

回答

1

我已經解決了這一問題

@request.env['HOST'] = "somesite.com" 
@request.env['HTTP_ACCEPT_LANGUAGE'] = "en"