【发布时间】:2020-03-05 01:10:23
【问题描述】:
我的班级负责与我要测试的 Jira 公司董事会建立联系。
class
module Jira
class JiraConnection
URL = 'https://company_name.atlassian.net/'.freeze
def call
JIRA::Client.new(options)
end
private
def options
{
username: ENV['USERNAME'],
password: ENV['PASSWORD'],
site: URL,
context_path: '',
auth_type: :basic,
use_ssl: true
}
end
end
end
JIRA::Client.new 来自jira-ruby gem。我想测试一下
我的规格:
RSpec.describe Jira::JiraConnection, type: :service do
subject(:connect) { described_class.new }
let(:options) do
{
username: username_secret,
password: password_secret,
site: 'https://company_name.atlassian.net/',
context_path: '',
auth_type: :basic,
use_ssl: true
}
end
let(:username_secret) { ENV.fetch('USERNAME') }
let(:password_secret) { ENV.fetch('PASSWORD') }
before do
allow(JIRA::Client).to receive(:new).with(options)
end
it 'connect to Jira API' do
expect(subject.call).to receive(JIRA::Client)
end
end
使用上述规格,我遇到了一个错误:
Failure/Error: expect(subject.call).to receive(JIRA::Client)
NoMethodError:
undefined method `to_sym' for JIRA::Client:Class
Did you mean? to_s
【问题讨论】:
-
receive需要一个符号作为其第一个参数,表示要调用的方法。你正在通过一个课程JIRA::Client。你到底想用这条线做什么? -
我期待与代表 JIRA::Client 类的 Jira 板建立连接。
标签: ruby-on-rails ruby rspec