gpt4 book ai didi

ruby-on-rails - Rspec send_data 测试未通过

转载 作者:行者123 更新时间:2023-12-04 11:34:57 26 4
gpt4 key购买 nike

我似乎无法通过这个测试,我不明白为什么。

controller_spec.rb:

require 'rails_helper'

RSpec.describe QuotationRequestsController, type: :controller do

describe "GET download" do
it "streams the sample text as a text file" do
#setup
quotation_request = create(:quotation_request)
file_options = {filename: "#{quotation_request.id}-#{quotation_request.client.name.parameterize}.txt", type: 'plain/text', disposition: 'attachment'}

#exercise
get :download, id: quotation_request

#verification
expect(@controller).to receive(:send_data).with(file_options) {@controller.render nothing: true}
end
end
end

Controller :
def download
@quotation_request = QuotationRequest.find(params[:id])
send_data @quotation_request.sample_text, {
filename: @quotation_request.sample_text_file,
type: "text/plain",
disposition: "attachment"
}
end

测试输出:
1) QuotationRequestsController GET download streams the sample text as a text file
Failure/Error: expect(@controller).to receive(:send_data).with(file_options) {
@controller.render nothing: true
}
(# <QuotationRequestsController:0x007ff35f926058>).send_data({
:filename=>"1-peter-johnson.txt",
:type=>"plain/text",
:disposition=>"attachment"
})
expected: 1 time with arguments: ({
:filename=>"1-peter-johnson.txt",
:type=>"plain/text", :disposition=>"attachment"
})
received: 0 times
# ./spec/controllers/quotation_requests_controller_spec.rb:380:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'

最佳答案

你应该传递2个参数
expect(@controller).to receive(:send_data).with(quotation_request.sample_text, file_options) {@controller.render nothing: true}

关于ruby-on-rails - Rspec send_data 测试未通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39523964/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com