2011-02-24 81 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" })