Devise test helpers (ie. sign_in) not available in view specs

2,141 views
Skip to first unread message

Gordon Yeong

unread,
Aug 28, 2011, 8:48:50 PM8/28/11
to Devise
Hi, guys,



I refered to https://github.com/plataformatec/devise as I'm trying
to get my view specs updated to use with Devise.
My views were written in rspec2 and the application runs on rails
3.0.9.


I have done what the reference above asks for:

1) ran 'rails generate devise:views' to set up the views. My model/
role is called 'User' (default)
2) created a new file, 'spec/support/devise.rb' and added the
following contents:
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end


When I run the application ('script/rails server'),
devise does work as in, I can sign up, login and logout.

Nevertheless, When I run 'rake spec:views', I noticed that sign_in,
which is a devise test helper is not included.
What is missing?



thank you.




Other efforts:
===============


a) I have also looked at
https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with-Rails-3-(and-rspec)
which in the view spec:

1) requires 'spec_helper' and 'devise/test_helpers'
2) defined the let block for :user and before hook for assigning a
user object

b) Looked at https://github.com/RailsApps/rails3-devise-rspec-cucumber
which is an example of rails 3, devise , rspec and cucumber. Noticed
it did not have any view specs.

Gordon Yeong

unread,
Aug 28, 2011, 8:52:29 PM8/28/11
to Devise
Error message:

1) parts/new.html.erb renders a form to add a new part
Failure/Error: sign_in @user
NoMethodError:
undefined method `sign_in' for
#<RSpec::Core::ExampleGroup::Nested_1:0x6f159a88cbc8>
# ./spec/views/parts/new.html.erb_spec.rb:9
# ./spec/views/parts/new.html.erb_spec.rb:19

Aashish Kiran

unread,
May 27, 2013, 3:45:09 AM5/27/13
to plataforma...@googlegroups.com
Hi,
I am stuck with same problem. Can I know how you solved this problem.

Lucas Mazza

unread,
May 27, 2013, 9:09:25 AM5/27/13
to plataforma...@googlegroups.com
Devise test helpers are for controller specs (I can't confirm that they are compatible with view specs) and they need to be explicitly included in your specs. There is a page in the wiki with some examples for using the test helpers when testing your controllers.


--
 
---
You received this message because you are subscribed to the Google Groups "Devise" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

and...@benjamin.dk

unread,
May 30, 2013, 5:09:44 AM5/30/13
to plataforma...@googlegroups.com
I saw a lot of people linking here:

https://github.com/plataformatec/devise/wiki/How-To:-Controllers-tests-with-Rails-3-(and-rspec)

but I get a blank write yourself there... does anybody still know where we can find this information?

Aashish Kiran

unread,
May 30, 2013, 6:42:06 AM5/30/13
to plataforma...@googlegroups.com
Hi,
Found a solution to run authenticated view specs

require 'spec_helper'


describe "home/index.html.haml" do
  include Devise::TestHelpers

  before(:each) do
    @request.env["devise.mapping"] = Devise.mappings[:user]
    @current_user = FactoryGirl.create(:user)
    #      user.confirm! # or set a confirmed_at inside the factory. Only necessary if you are using the confirmable module
    sign_in @current_user
  end 





--
 
---
You received this message because you are subscribed to a topic in the Google Groups "Devise" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/plataformatec-devise/H6DMfgeHIXE/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to plataformatec-de...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
with regards,
Ashish
Reply all
Reply to author
Forward
0 new messages