简体   繁体   中英

“No route matches” error for route without a controller in rails/rspec

Environment: Rails 3.2.12, rspec 2.12

I'm trying to bootstrap an app with a very simple routing test. The test is failing, and I can't see what could be wrong.

Here's the test that fails:

# 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

And my route:

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

rake routes tells me:

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

But when I run rspec, I get this error:

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)>'

What on earth is going on here? Those are really the only files of consequence in my app so far - not even any controllers or models, just trying to build it from the outside in.

Well, it turns out that adding in the controller resolves the issue. I added this:

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

...and now the test passes. Very frustrating error message!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM