Ruby on rails 3 在Rspec集成测试中为对象设置会话

Ruby on rails 3 在Rspec集成测试中为对象设置会话,ruby-on-rails-3,integration-testing,rspec2,Ruby On Rails 3,Integration Testing,Rspec2,我的控制器中有以下各项: 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 f

我的控制器中有以下各项:

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
在我的rspec selenium测试中,我想为电路板设置会话。但似乎我不能

  describe "greeting creation" do

     before(:each) do
        @board = Factory(:board)
        session[:board] = @board.id
      end
这会产生以下错误:

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

如何设置会话以使此测试正常工作?

您确定夹具调用正确吗?它们通常是复数,比如
工厂(:board)


您可以尝试在测试中显式地设置它,看看是否可以设置会话,而不是尝试从夹具加载。如果这样做有效,那么您就知道问题出在加载夹具上。

我遇到了这个问题,并使用ApplicationController.session[:key]将其“解决”

但是现在我得到了错误
TypeError:
无法将符号转换为整数

level_spec.rb:7:in
[]='`

我正在使用factory girl gem,因此调用是正确的。我需要在控制器中设置会话以使测试正常工作。我似乎无法访问会话对象。有什么想法吗?