views:

119

answers:

1
+1  Q: 

RSpec-2 and Devise

Hi, i create a customized devise registration controller and i want to test it with rspec.

I've tried it with a very simple test :

it "creates a new parent" do
  Parent.should receive(:new)
  post :create
end

but i get this exception:

Failures:
  1) Parent::RegistrationsController POST create creates a new parent
     Failure/Error: post :create, { :commit => "Daftar",
     uncaught throw `warden'
     # /home/starqle/.rvm/gems/ree-1.8.7-2010.02/gems/devise-1.1.3/lib/devise/hooks/timeoutable.rb:16:in `throw'
     # /home/starqle/.rvm/gems/ree-1.8.7-2010.02/gems/devise-1.1.3/lib/devise/hooks/timeoutable.rb:16

I already put this line within my test:

describe Parent::RegistrationsController do
  include Devise::TestHelpers
end

I also already put this line:

request.env["devise_mapping"] = Devise.mappings[:parent]

anybody have ideas to solve this problem?

+1  A: 

I met this problem too. error: NameError in '...' uncaught throw 'warden'.

I used the sign_in method to. both sign_in(@user) or sign_in(:user, @user) failed and cause this problem.

My Rails version: 2.3.5. windows. ruby 1.8.6. devise: 1.0.8

and come to this solution (after dived into its source code)

use

warden.session_serializer.store(@user,:user)

instead of

sign_in(@user)

any questions please let me know.

Siwei Shen
thank you, a crude way but it works fine for now.
giovanni
Yeah, it's not an elegant solution. I don't know if Rails3 guys met this problem. However I am sure that there are 2 sign_in methods in devise: 1. sign_in (Devise::Controllers::Helpers)2. sign_in (Devise::TestHelpers)they used different implementation strategy, and only the 2nd method works. I don't know if this is a bug, unless I have enough time to read "warden"'s source code. this is my first accepted answer on StackOverflow, thank you!
Siwei Shen