我的控制器中有这个方法:
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
答案 0 :(得分:1)
您的测试应该是:
it "should respond with javascript" do
get :index, {:id => @return_value}, format: :xls
expect(response).to be_success
end