1
describe ".valid_jira_build?" do
context 'given valid build name' do
let(:configd_client) { ('login.yml') }
let(:client) { double(configd_client) }
before do
allow(YAML)
.to receive(:load_file)
.with('login.yml')
.and_return(configd_client)
allow(JenkinsApi::Client)
.to receive(:new).with(configd_client)
.and_return(client)
allow(client).to receive_message_chain(:job, :status) {'success'}
end
it 'will return true' do
client.stub(:job)
expect(JenkinsClient.new('build').valid_jira_build?).to be_true
end
end
我試圖嘲弄JenkinsApi ::客戶:: Job.get_latest_build_status,我已經試過許多方法來嘲笑這一點,但相信新RSpec的和我在一個運行許多問題。我不想讓客戶端對象與服務器聯繫,但沒有正確地模擬它以防止發生這種情況。無法嘲笑第三方API客戶端連接工具
任何幫助,將不勝感激。從這個版本獲得當前的錯誤是:
1) JenkinsClient.valid_jira_build? given valid build name will return true
Failure/Error: latest_build_status = client.job.status
("#{jira_build_to_check}")
NoMethodError:
undefined method `status' for nil:NilClass
# ./lib/jenkins_client.rb:59:in `valid_jira_build?'
# ./lib/jenkins_client.rb:30:in `initialize'
# ./spec/jenkins_client_spec.rb:31:in `new'
# ./spec/jenkins_client_spec.rb:31:in `block (4 levels) in <top (required)>'
'code' ..... 在0.02251秒成品(文件採取1.4秒加載) 5實施例中,0失敗 'code' 這些變化有它執行。爲了讓程序的其餘部分能夠正確執行,我做了一些修改,但這樣做解決了我的嘲諷問題。 – Maxley