Hi,
I am stuck at the following. Can anyone help.
I am writting a spec for views.
home/index_html_haml_rspec.rb
require ''spec_helper''
describe "home/index.html.haml" do
include Devise::TestHelpers
login_user
it "should display header with search form" do
render :handlers => "home/index.html.haml"
response.should contain("Hello world!" )
end
# pending "add some examples to (or delete) #{__FILE__}"
end
output:
/spec/views/home/index.html.haml_spec.rb:7:in `block in <top
(required)>'': undefined local variable or method
`login_user'' for
#<Class:0xa07074c> (NameError)
from
/usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in
`module_eval''
from
/usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in
`subclass''
from
/usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in
`describe''
from
/usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/dsl.rb:18:in
`describe''
from
/home/seneca/ashish/affluence2-staging/spec/views/home/index.html.haml_spec.rb:4:in
`<top (required)>''
from
/usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in
`load''
from
/usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in
`block in load_spec_files''
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/79fa1c70ea5c7be52e28cb8d820816b6%40ruby-forum.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
andreo-FdlSlcb4kYpknbxzx/v8hQ@public.gmane.org
2013-May-26 11:04 UTC
Re: rspec rails 3 views authenticate
First thing, there is a forum here: https://groups.google.com/forum/?fromgroups#!forum/plataformatec-devise for devise itself. and there you might get a better help for your question. but I googled around. something I assume you have done and it seems that login_user was a helper you had to redefine yourself. which does not really exist anymore, well, at least looking at the documentation of the devise test helpers. http://rubydoc.info/github/plataformatec/devise/master/Devise/TestHelpers so probably you should use factory girl (https://github.com/thoughtbot/factory_girl) to mock up a user and use the method on the documents called sign_in, something like: @user = Factory(:user) sign_in @user now I also recommend you to read a little bit more about testing in rails with rspec and factory_girl: for example to start with: http://railscasts.com/episodes/275-how-i-test and you can also google a little bit more by yourself! On Friday, 24 May 2013 12:43:40 UTC+2, Ruby-Forum.com User wrote:> > Hi, > > I am stuck at the following. Can anyone help. > I am writting a spec for views. > > home/index_html_haml_rspec.rb > > require ''spec_helper'' > > > describe "home/index.html.haml" do > include Devise::TestHelpers > > login_user > > > > it "should display header with search form" do > > render :handlers => "home/index.html.haml" > response.should contain("Hello world!" ) > > end > # pending "add some examples to (or delete) #{__FILE__}" > end > > > output: > > /spec/views/home/index.html.haml_spec.rb:7:in `block in <top > (required)>'': undefined local variable or method `login_user'' for > #<Class:0xa07074c> (NameError) > from > /usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in > > `module_eval'' > from > /usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in > > `subclass'' > from > /usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in > > `describe'' > from > /usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/dsl.rb:18:in > > `describe'' > from > /home/seneca/ashish/affluence2-staging/spec/views/home/index.html.haml_spec.rb:4:in > > `<top (required)>'' > from > /usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in > > `load'' > from > /usr/local/rvm/gems/ruby-1.9.3-p374@affluence-connect/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in > > `block in load_spec_files'' > > -- > Posted via http://www.ruby-forum.com/. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/466531a7-e1ca-4478-ba48-0385175055c6%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
unknown wrote in post #1110178:> First thing, there is a forum > here: > https://groups.google.com/forum/?fromgroups#!forum/plataformatec-devise > for devise itself. and there you might get a better help for your > question. > > but I googled around. something I assume you have done and it seems that > login_user was a helper you had to redefine yourself. which does not > really > exist anymore, well, at least looking at the documentation of the devise > test helpers. > > http://rubydoc.info/github/plataformatec/devise/master/Devise/TestHelpers > > so probably you should use factory girl > (https://github.com/thoughtbot/factory_girl) to mock up a user and use > the > method on the documents called sign_in, something like: > > @user = Factory(:user) > > sign_in @user > > now I also recommend you to read a little bit more about testing in > rails > with rspec and factory_girl: > > for example to start with: http://railscasts.com/episodes/275-how-i-test > and you can also google a little bit more by yourself!Hi, I created macros, the code is as follows module ControllerMacros def login_admin before(:each) do @request.env["devise.mapping"] = Devise.mappings[:admin] sign_in FactoryGirl.create(:admin) # Using factory girl as an example end end def login_user 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 end def login_as_paid_user before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] @current_user = FactoryGirl.create(:user, :member_paid_monthly) # user.confirm! # or set a confirmed_at inside the factory. Only necessary if you are using the confirmable module sign_in @current_user end end def logout! after(:each) do session[:user] end end end its working in controller. The problem is with only views. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d97faea006240994e9ea78599473f045%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.