"No route matches"轨/rspec 中没有控制器的路由错误



环境: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)>'

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

事实证明,添加控制器解决了这个问题。我添加了这个:

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

现在测试通过了。非常令人沮丧的错误消息!

相关内容

  • 没有找到相关文章

最新更新