在rails / rspec中没有控制器的路由“没有路由匹配”错误

时间:2013-02-21 22:09:09

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

环境:Rails 3.2.12,rspec 2.12

我正在尝试使用非常简单的路由测试来引导应用程序。测试失败了,我看不出有什么不对。

这是失败的测试:

# spec/routing/meow_route_spec.rb
require 'spec_helper'
describe "meow routes" do
  it "routes post /meows to meows#create" do
    expect(:post => "/meows").to route_to(
      :controller => "meows",
      :action => "create",
    )
  end
end

我的路线:

# config/routes.rb
Meowserver::Application.routes.draw do
  resources :meows
end

rake routes告诉我:

polk:meowserver dpassage$ rake routes
    meows GET    /meows(.:format)          meows#index
          POST   /meows(.:format)          meows#create
 new_meow GET    /meows/new(.:format)      meows#new
edit_meow GET    /meows/:id/edit(.:format) meows#edit
     meow GET    /meows/:id(.:format)      meows#show
          PUT    /meows/:id(.:format)      meows#update
          DELETE /meows/:id(.:format)      meows#destroy

但是当我运行rspec时,我收到了这个错误:

1) meow routes routes post /meows to meows#create
  Failure/Error: expect(:post => "/meows").to route_to(
    No route matches "/meows"
  # ./spec/routing/meow_route_spec.rb:4:in `block (2 levels) in <top (required)>'

这到底是怎么回事?到目前为止,这些都是我应用程序中唯一的后果文件 - 甚至不是任何控制器或模型,只是试图从外部构建它。

1 个答案:

答案 0 :(得分:1)

嗯,事实证明,添加控制器可以解决问题。我补充说:

# app/controllers/meows_controller.rb
class MeowsController < ApplicationController
end

......现在考试通过了。非常令人沮丧的错误信息!