2012-03-27 73 views
1

我有一個控制器在某個動作上發佈HTTP請求,我該如何測試/斷言該請求實際上正在發送?測試一個請求是在Rails控制器中發送的

+0

你嘗試過什麼?測試控制器/請求並不是新事物,那裏有很多示例/幫助/工具。 – MrDanA 2012-03-27 18:32:53

+0

我有其他測試來斷言一個響應,但找不到一個來聲明發送了一個請求 – Nonos 2012-03-27 19:39:30

回答

0

我只是測試響應或更高級別的動作(就像這件事情做什麼?)。但如果你想測試交互(也許路由檢查等),然後嘲笑它。以下是一些想法。

# test where the request goes 
request = ActionController::TestRequest.new 
request.query_parameters[:foo] = "bar" 
request.path = "/" 
ActionController::Routing::Routes.recognize(request) 
assert_equal({"controller"=>"your_controller","action"=>"index"}, request.path_parameters) 
# other tests here if you want 

Rspec的型式試驗:

# test that the controller will receive it 
controller = YourController.new 
controller.should respond_to(:create) 
相關問題