gpt4 book ai didi

ruby-on-rails - Rspec respond_to xls

转载 作者:行者123 更新时间:2023-11-28 20:11:45 25 4
gpt4 key购买 nike

我的 Controller 中有这个方法:

def index
@hedge_fund_index_matrix = HedgeFundIndices.matrix
@hedge_fund_index_headers = HedgeFundIndices.headers
respond_to do |format|
format.html {}
format.xls {
headers["Content-Disposition"] = "attachment; filename=\"HedgeFundIndices_#{DateTime.now.strftime('%Y%m%d_%H%M')}\""
}
end
end

而且,我需要测试respond_to:

it "should respond with javascript" do
get :index, {:id => @return_value}
expect(.....).to (....)
end

最佳答案

你的测试应该是这样的:

it "should respond with javascript" do
get :index, {:id => @return_value}, format: :xls
expect(response).to be_success
end

关于ruby-on-rails - Rspec respond_to xls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26263509/

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