Establish a session for an object in an Rspec integration test

My controller has the following:

def create @board = Board.find(session[:board]) @greeting = @board.Greetings.build(params[:greeting]) respond_to do |format| if @greeting.save format.js { render :action => "success" } else format.js { render :action => "failure" } end end end 

In my testing of rspec selenium, I want to establish a session for the board. But it seems like I can’t

  describe "greeting creation" do before(:each) do @board = Factory(:board) session[:board] = @board.id end 

This results in the following error:

  Failure/Error: session[:board] = @board.id NoMethodError: undefined method `session' for nil:NilClass 

How to set up a session for this test to work?

+6
source share
2 answers

I had this problem and "resolved" it using ApplicationController.session [: key].

But now I get the error TypeError: can't convert Symbol into Integer level_spec.rb:7:in [] = ''

+1
source

Are you sure the device is correctly named? Usually they are plural, for example factories(:board) .

You can try just setting it explicitly in the test to see if you can even set up a session instead of trying to download from the device. If this works, then you know that the problem is loading the device.

0
source

Source: https://habr.com/ru/post/892124/


All Articles