简体   繁体   中英

Why doesn't this Rails Rspec Test Work?

I create all the routes of my program manually and so do with my rspec tests of course. Generally, my routes and tests work fine, but i have a problem with the test for my characters controller. The route is :

  scope :path => '/characters', :controller => :characters do
    get '/' => :show, :as => 'user_character'
  end  

The /characters works fine when tested with my browser. Everything seems fine. But, the test :

require 'spec_helper'
require 'devise/test_helpers'

describe CharactersController do
    login_user

    describe "when it GETS 'show'" do
        it "should render the template and be successful" do
            get :show
            response.should render_template(:show)
            response.should be_success
        end
    end

end

Fails with the error :

  1) CharactersController when it GETS 'show' should render the template and be successful
     Failure/Error: get :show
     ActionController::RoutingError:
       No route matches {:controller=>"characters", :action=>"show"}
     # ./spec/controllers/characters_controller_spec.rb:9

All my controllers have similar tests that work fine. Why does this not work ?

IMPORTANT EDIT :

Just saw that if i turn Spork off, the test passes ! Why is this happening ? Does Spork need to be restarted every time a new test is added ?

You have to restart spork when changing routes.

Or put this in your spec_helper.rb:

Spork.each_run do
  ApplicationName::Application.reload_routes!
end

See also "Speedy Test Iterations for Rails 3 with Spork and Guard"

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