Rails Minitest API 连接 - NoMethodError:未定义的方法`call'

问题描述

我想为服务创建一个 Minitest,负责在外部提供者内部创建数据并更新我的数据库中的一些内容。为此,我正在使用 VCR 和以下测试:

#test/services/identity_checks/check_creator_test.rb

require 'test_helper'

module IdentityChecks
  class CheckCreator < ActiveSupport::TestCase
    setup do
      VCR.insert_cassette name
      identity_check.user_id = user.id
    end
    
    teardown do
      VCR.eject_cassette
    end
    
    test 'update status' do
      service
      identity_check.reload
      assert_equal 'Not started',identity_check.status
    end
    
    private
    
    def service
      ::CheckCreator.new(identity_check).call
    end
    
    def identity_check
      @identity_check ||= identity_checks(:in_progress)
    end
    
    def user
      @user ||= users(:registered)
    end
  end  
end

经过测试的服务:

#app/services/identity_checks/check_creator.rb

module IdentityChecks
  class CheckCreator
    def initialize(identity_check)
      @identity_check = identity_check
    end
    
    def call
      response = api.create_check(options: build_options)
      identity_check.update!(check_uuid: response['id'],status: response['status_label'],check_body: response)
    end
    
    attr_accessor :identity_check
    
    private
    
    def api
      @api ||= ::Identity::Api.new
    end
  end
end

使用此代码时出现错误

NoMethodError:未定义的方法 call' for #<IdentityChecks::CheckCreator test/services/identity_checks/check_creator_test.rb:31:in service' test/services/identity_checks/check_creator_test.rb:23:in `block in class:CheckCreator'

我以为是因为录像机,但当我摆脱它时,它还是一样。在 Rails 控制台内部一切正常。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)