2016-03-08 37 views
0

對於我的項目,我需要將標題HTTP_ACCEPT添加到我的所有請求中。RSpec - 如何添加默認內容類型?

有沒有解決方案來避免在我的所有控制器的規格這個?

before do 
    @request.env["HTTP_ACCEPT"] = 'application/json' 
end 

回答

0

找到了!

Rspec.configure do |config| 
    config.before(:each) do |example| 
    if example.metadata[:type] == :controller 
     controller.request.env["HTTP_ACCEPT"] = 'application/json' 
    end 
    end 
end 
相關問題