如何将语言环境传递给Minitest集成测试

时间:2019-02-12 10:44:54

标签: ruby-on-rails integration-testing minitest

尝试传递给文字路径名不起作用。

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>'

那么我们如何在测试级别为未登录用户传递语言环境?

1 个答案:

答案 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