2011-02-24 80 views
2

我有一個猜想是創建行動POST形式,但它是做一個POST到索引操作。所以我決定用rspec測試我的路線。在我的例子中,我的測試如下。測試路由使用RSpec對Rails 3

it "should recognize a specific invoices#create route" do 
    assert_routing("/invoices", {:controller => "invoices", :action => "create"}) 
end 

但是當我運行測試它提出了這個錯誤。

1) InvoicesController on get to :index should recognize a specific invoices#create route 
Failure/Error: assert_routing("/invoices", {:controller => "invoices", :action => "create"}) 
The recognized options <{"action"=>"index", "controller"=>"invoices"}> did not match <{"controller"=>"invoices", "action"=>"create"}>, difference: <{"action"=>"create"}>. 
Expected block to return true value. 

所以我嘗試,爲什麼我的表格上做索引,爲什麼一個POST我的測試認爲即時通訊做索引的路線搞清楚。我試過在測試中插入:method =>:post,但它似乎不起作用。

回答

4

您是否嘗試過這個?:

assert_routing({ :path => "invoices", :method => :post }, 
    { :controller => "invoices", :action => "create" })