testing on davidchua https://dchua.com/tags/testing/ Recent content in testing on davidchua Hugo -- gohugo.io en-us Tue, 12 Aug 2014 00:00:00 +0000 Testing with Rack-test custom headers https://dchua.com/posts/2014-08-12-testing-with-rack-test-custom-headers/ Tue, 12 Aug 2014 00:00:00 +0000 https://dchua.com/posts/2014-08-12-testing-with-rack-test-custom-headers/ When writing a method that requires a custom request header, ie. “X-Api-Key”, use the following: key = request.headers['HTTP_X_API_KEY'] Instead of key = request.headers['X-Api-Key'] This is because Rack converts all custom headers into the HTTP_ format. When writing your tests, remember to specify like the following get '/test', {}, {"HTTP_X_API_KEY" => "key"} Even though when in your actual query, you’re sending the header as X-Api-Key