【问题标题】:How to pass locale to a Minitest Integration test如何将语言环境传递给 Minitest 集成测试
【发布时间】:2019-02-12 10:44:53
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案1】:

    帮助文档https://apidock.com/rails/ActionDispatch/Integration/RequestHelpers/get

    第二个参数是

    parameters:要传递的 HTTP 参数。这可能是 nil、Hash 或经过适当编码的 String(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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多