我有
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变量。