ruby on rails - rspec can't find @user when application can -


the following rspec test file

require 'spec_helper'  describe evaluationscontroller render_views    before(:each)     association_attr   end    describe "'eval_selektor'"      before(:each)       @eval_selektor = :eval_selektor, student_group_id: @student_group     end      "should successful"       @eval_selektor       response.should be_success     end      ...    end    ...  end 

is throwing following error:

  1) evaluationscontroller 'eval_selektor' should successful      failure/error: @eval_selektor = :eval_selektor, student_group_id: @student_group      nomethoderror:        undefined method `student_groups' nil:nilclass      # ./app/controllers/application_controller.rb:7:in `get_student_group'      # ./spec/controllers/evaluations_controller_spec.rb:14:in `block (3 levels) in <top (required)>' 

from method in application_controller:

def get_student_group   @user = current_user   @student_group = @user.student_groups.find(params[:student_group_id]) end 

at first thought maybe rspec wasn't getting passed method application_controller, that's not case can see in error. code works in browser, , if put <%= @user %> in view, shows correct user instance. ideas why rspec can't read @user?

apneadiving got me started in right direction, , between this post , this 1 got correct code:

  applicationcontroller.any_instance.stub(:current_user).and_return(@user) 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -