在rspec中为所有控制器定义全局变量

时间:2015-11-26 12:34:12

标签: ruby-on-rails rspec

我有

require "rails_helper"

RSpec.describe Api::V1::SessionsController, :type => :controller do

  before do 
   post :create, {email: "raj@gmail.com", user_name: "raj",password: "raj"}
   body = JSON.parse(response.body)
   @session_token = body["session_token"]
  end
end

我添加了新的控制器

require "rails_helper"

RSpec.describe Api::V1::ProductsController, :type => :controller do
  describe "GET #index" do
    it "should list all products" do
        request.env['HTTP_SESSIONTOKEN'] = @session_token
    end
  end
end

现在我想在products_controller_spec中使用session_token。如何定义session_token变量。

0 个答案:

没有答案