【问题标题】:Testing Routes with Rspec in Rails 3在 Rails 3 中使用 Rspec 测试路由
【发布时间】:2011-02-24 01:51:11
【问题描述】:

我有一个表单,它应该是一个 POST 到 CREATE 操作,但它正在执行一个 POST 到 INDEX 操作。所以我决定用 rspec 测试我的路线。在我的示例中,我的测试如下。

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.

所以我试图弄清楚为什么我的表单在 INDEX 上做一个 POST 以及为什么我的测试认为我在做一个索引路由。我尝试在测试中插入 :method => :post 但它似乎不起作用。

【问题讨论】:

    标签: ruby-on-rails-3 rspec routes


    【解决方案1】:

    你试过了吗?:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      • 1970-01-01
      • 2011-08-21
      相关资源
      最近更新 更多