[rspec-users] RSpec 2.4, named/restful routes falling apart...

Jason Nah jason.nah at gmail.com
Thu Jan 13 00:39:21 EST 2011


Guys,

This could be me, but I thought I'd check

For some reason, when I spec controllers, I run into this problem
(intermittently it would seem). Right now, I have a spec that fails
predictably.

I'm using
* Rspec 2.4.0
* Rspec-rails 2.4.1
* Rails 3
* Mocha 0.9.10

I have the following defined in my routes file


resources :users


And a controller:

class UsersController < ApplicationController
   before_filter :load_user


   def show
      redirect_to(user_path(@user))
   end

   private
   def load_user
      @user = User.find(params[:id])
   end
end

and a spec

describe UsersController do
   before(:each) do
      @user = Factory.build(:user, :id => '12341234')
      User.expects(:find).returns(@user)
      get "show", :id => @user.id
   end
   subject { response }
   it { should redirect_to(user_path(@user)) }
end


The spec fails with the following

Failures:

  1) UsersController
     Failure/Error: get "show", :id => @user.id
     ActionController::RoutingError:
       No route matches {:controller=>"users", :action=>"show", :id=>#<User
_id: 12341234, encrypted_password:
"$2a$10$1gbrD8IZSo7LUYE5l5w1B.AYSu6zTs6lzWw.ZPhRKXCNT88xtjZfy",
last_sign_in_ip: nil, confirmation_sent_at: nil, last_sign_in_at: nil,
sign_in_count: 0, password_salt: "$2a$10$1gbrD8IZSo7LUYE5l5w1B.",
setup_employer_profile: nil, last_name: "Treutel", current_sign_in_ip: nil,
reset_password_token: nil, remember_token: nil, current_sign_in_at: nil,
confirmation_token: "12341234XXX12341234", remember_created_at: nil,
first_name: "Carolyn", confirmed_at: nil, email: "
mrs.faye.anderson1 at zboncakkihn.ca">}
     # ./app/controllers/users_controller.rb:17:in `show'
     # ./spec/controllers/users_controller_spec.rb:50


Could somebody explain what's going on????

It would appear that for some reason, my controllers don't know a thing
about routing. Either that or something's wacky. The annoying thing about
this is that it works perfectly fine when you use a browser to test.


Cheers,
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110113/5b8d852c/attachment.html>


More information about the rspec-users mailing list