ruby-on-rails - Rails Minitest API 连接 - NoMethodError:未定义的方法“调用”
问题描述
我想为负责在外部提供者内部创建数据并更新我的数据库中的一些内容的服务创建一个 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
服务'test/services/identity_checks/check_creator_test.rb:23:in `block in class:CheckCreator'
我以为是因为 VCR,但当我摆脱它时,它仍然是一样的。在 Rails 控制台内部,一切正常。
解决方案
推荐阅读
- python-3.x - ValueError:形状(4155,1445)和(4587,7)未对齐:1445(dim 1)!= 4587(dim 0)
- php - 以前的例外
- java - 如何模拟这个创建kafka主题并等待未来对象的简单方法?
- php - 我无法使用连接表提取结果
- html - 连续使用圆形按钮的 Flex
- function - : 在 Dart 函数中有什么用?
- python - 如何将 txt 中的一行 url 放入我的请求和保存功能?
- python - 如何使用 Opencv 检测三角形交通标志
- node.js - PM2 和 DotEnv 无法在 ubuntu 服务器上运行的问题
- android - 以编程方式启用 android:forceDarkMode?