![](/img/trans.png)
[英]Testing a ApplicationController before_filter in Rails
[英]testing with before_filter
我已經開發了before_filter- http: //gist.github.com/138659並在類似的測試中
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
functional/set_locale' /test/functional/articles_controller_test.rb:5:in
test_should_get_index'中
當我添加
setup do
@request.headers['HTTP_ACCEPT_LANGUAGE'] = "en"
end
什么都沒改變:(你能告訴我嗎-怎么了?
Rails 2.3.2,Ruby 1.8
我已經解決了這個問題
@request.env['HOST'] = "somesite.com"
@request.env['HTTP_ACCEPT_LANGUAGE'] = "en"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.