2013-04-07 82 views

回答

1

爲了使用RSpec測試中間件您需要定義,要麼做

let(:inner_app) { lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['All good!'] } } 


let(:app) { SomeMiddleware.new } 

def app 
    SomeMiddleware.new 
end 

讓你的中間件實例的方法,您還必須包括請在您的spec_helper.rb或您的測試文件中輸入Rack::Test::Methods模塊。

然後,您在Rspec中執行的任何請求都將通過該中間件。

檢查此資源http://blog.kesor.net/2012/06/05/rack-middleware/