0

I'm trying to parse HTTP request headers in Test::Unit, but to no avail. I'm writing a functional test for a controller like so:

test "create a shopify order" do
  get :order, PARAMS, {HEADER1 => VAL, HEADER2 => VAL}
  assert_response :success # Make sure this returns 200, first off
  ...
end

Normally, I would read the headers like, request.headers[HEADER1], but this returns nil in Test::Unit. request isn't defined.

How do I actually grab the value of the headers I set in the above request? And how do I assign them to request? My app pulls from webservices, and I need to test the values that are passed through in headers, so I don't want to change my app code. I just need to simulate what those requests are like in Test::Unit.

Thanks!

ideaoforder
  • 1,023
  • 2
  • 9
  • 23
  • using "test" and "assert_response" are usually descriptive of Test::Unit tests. are you positive you're using rspec? – Jesse Wolgamott May 08 '13 at 17:06
  • Not at all sure! I'm using the default RoR testing suite...I guess since this is a functional test, and not a unit test, I assumed I wasn't using Test::Unit. I could definitely be wrong. Long-time RoR dev, total testing newb. – ideaoforder May 08 '13 at 17:15
  • Which specific header attributes you are going to use? – Billy Chan May 08 '13 at 18:06
  • 1
    @ideaoforder to help your googling and stack overflowing: you're using test::unit – Jesse Wolgamott May 08 '13 at 18:59
  • Why do you need to grab the values of the headers in the request in that spec? You manually set them. There's not need to test the underlying Rails core behavior. The values are what you set them in the `get` message. Did you mean headers of the `response` from the `get` request? – Aaron K May 09 '13 at 02:56
  • I'm simulating a request from an external app. My controller parses the headers that are sent. Without those headers, the action I'm testing fails. – ideaoforder May 09 '13 at 16:14

1 Answers1

1

Knowing what test quite you're using certainly helps (thanks Jesse). I found that I'd been looking at the doc for integration tests, not functional tests, and that setting headers works differently in functional tests:

http://twobitlabs.com/2010/09/setting-request-headers-in-rails-functional-tests/

So I wasn't setting the headers I thought I was. They were being read just fine--just not set.

ideaoforder
  • 1,023
  • 2
  • 9
  • 23