1

How to add headers to my get request.

it "can find an account" do 
    get "/accounts/#{@acc.id}/", headers # like the token or whatever your api needs
end

Below is my controller method where i am passing the token, now how would i append this to my get request.

Account.find(id: @acc.id, authorization: @auth_token);
Frank
  • 179
  • 2
  • 10

2 Answers2

1

Use request.env to set the header

it "can find an account" do 
   request.env['AUTH_TOKEN'] = "token"
   get "/accounts/#{@acc.id}/"
end
usha
  • 28,973
  • 5
  • 72
  • 93
  • Also, see more methods discussed in http://stackoverflow.com/questions/9654465/how-to-set-request-headers-in-rspec-request-spec – sameers Aug 07 '14 at 19:20
1

You can send the headers as the third parameter to get:

get "/accounts/#{@acc.id}/", nil, {'AUTH_TOKEN' => 'token'}.

See the documentation for get for more info.

infused
  • 24,000
  • 13
  • 68
  • 78