开发者

Why doesn't this Rails Rspec Test Work?

开发者 https://www.devze.com 2023-02-14 08:16 出处:网络
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 r

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"}
     # ./spe开发者_如何学运维c/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"

0

精彩评论

暂无评论...
验证码 换一张
取 消