Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ruby rails单元测试中的POST请求_Ruby On Rails_Ruby_Unit Testing_Graphql - Fatal编程技术网

Ruby on rails ruby rails单元测试中的POST请求

Ruby on rails ruby rails单元测试中的POST请求,ruby-on-rails,ruby,unit-testing,graphql,Ruby On Rails,Ruby,Unit Testing,Graphql,在Altair中,要执行类似登录的变异,我必须设置一个环境变量,如server\u url,并在POST请求中调用该变量,如下所示: 只有这样,变异才不会返回null并起作用。我想问一下,在Ruby的单元测试中,我将如何做到这一点。例如,这是我的测试文件: require 'test_helper' class Mutations::SignInUserTest < ActiveSupport::TestCase def perform(args = {}) M

在Altair中,要执行类似登录的变异,我必须设置一个环境变量,如
server\u url
,并在POST请求中调用该变量,如下所示:

只有这样,变异才不会返回null并起作用。我想问一下,在Ruby的单元测试中,我将如何做到这一点。例如,这是我的测试文件:

require 'test_helper'

class Mutations::SignInUserTest < ActiveSupport::TestCase
    def perform(args = {})
        Mutations::SignInUser.new(object: nil, field: nil, context: {}).resolve(args)
    end

    test 'sign in' do
        user = perform(
            auth: {
                user_id: "example",
                password: "example"
            }
        )

        assert user.persisted?
    end
end
需要“测试助手”
类突变::SignInUserTest

它不起作用,因为
user
只返回null。我将把POST请求或我的
服务器url
放在哪里?我已经看过一些帖子,在类中放置
post“example url”
会导致
未定义的方法“post”
错误。我不太了解这一点,希望能提供一些帮助。

您需要继承
ActionDispatch::IntegrationTest
而不是
ActiveSupport::TestCase
。您可能应该从开始。我已经从阅读指南中尝试了继承
ActionDispatch::IntegrationTest
,但它仍然没有将
post
识别为一种方法,没有
post
,它也无法工作。