set session for object in Rspec integration test
I have the following in my controller:
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 rspec selenium test I want to set the session for the board. But it seems I can't
describe "greeting creation" do
before(:each) do
@board = Factory(:board)
session[:board] = @board.id
end
THis gives the following error:
Failure/Error: session[:board] = @board.id
NoMe开发者_开发问答thodError:
undefined method `session' for nil:NilClass
How can I set the session so this test works?
I had this issue and 'solved' it by using ApplicationController.session[:key].
But now I get the error TypeError:
can't convert Symbol into Integer
level_spec.rb:7:in
[]='`
Are you sure the fixture is being called correctly? They're usually plural, like factories(:board)
.
You could try just setting it explicitly in the test to see if you can even set the session, instead of trying to load from a fixture. If that works, then you know the problem is in loading the fixture.
精彩评论