如何使用rspec发布到命名路由?

时间:2014-12-16 21:32:55

标签: ruby-on-rails rspec

在routes.rb中我定义:

post '/api/create-entities-for-date-tags', to: 'bulk_update#create_entities_for_date_tags', as: 'createdates'

在我的rspec测试中我有:

require "spec_helper"

describe BulkUpdateController do

  describe 'routing' do
    it "routes to #index" do
      post createdates_path, {}
    end
  end
end

当我运行测试时,输出为:

 Failure/Error: post createdates_path, {}
 ActionController::RoutingError:
   No route matches {:controller=>"bulk_update", :action=>"/api/create-entities-for-date-tags"}

1 个答案:

答案 0 :(得分:0)

我认为您需要将as: 'createdates'添加到您定义的路线中,以使其按规格运行。

或者,更改您在规范中引用路线的方式,以匹配路线中的路径。 (rake routes在您想要路线的确切名称时非常有用。)