尝试传递给文字路径名不起作用。
require 'test_helper'
class Info::AccountPendingControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get '/account-pending', locale: 'en'
assert_response :success
assert_equal "index", @controller.action_name
assert_equal "account_pending", @controller.controller_name
end
end
结果
ERROR["test_should_get_index", Minitest::Result, 0.21732900000642985]
test_should_get_index#Minitest::Result (0.22s)
ArgumentError: ArgumentError: unknown keyword: locale
test/controllers/info/account_pending_controller_test.rb:6:in `block in <class:AccountPendingControllerTest>'
那么我们如何在测试级别为未登录用户传递语言环境?
答案 0 :(得分:0)
帮助文档https://apidock.com/rails/ActionDispatch/Integration/RequestHelpers/get。
第二个参数是
参数:您要传递的HTTP参数。可以是nil,哈希或经过适当编码的字符串(application / x-www-form-urlencoded或multipart / form-data)。
尝试下面的代码。
test "should get index" do
get '/account-pending', nil, {HTTP_ACCEPT_LANGUAGE: 'en'}
assert_response :success
assert_equal "index", @controller.action_name
assert_equal "account_pending", @controller.controller_name
end