3

I use Grape api and i need to write a test with custom header

my code:

  it "should accept message" do
    post "/api/v1/my/route", post_data, secret: "ASDFGHJKL"
    last_response.status.should == 201
  end

but the route gets no headers at all, i also tried headers['secret'] = "ASDFGHJKL" and also request.env['secret'] nothing works.

how can i pass headers in rspec to grape route?

Dima
  • 8,586
  • 4
  • 28
  • 57

2 Answers2

4

Did you try header 'secret', 'ASDFGHJKL'?

More on the rack-test docs

oliverbarnes
  • 2,111
  • 1
  • 20
  • 31
0

Try using @request variable, e.g. @request.env['secret'] = 'ASDF..'. Hope this helps.

Also, take a look at this - Sending custom headers through RSpec

Community
  • 1
  • 1
smolnar
  • 736
  • 1
  • 7
  • 14