[RFE] Generic way for setting headers to be used in the setup phase of integration tests

14 views
Skip to first unread message

imtay...@gmail.com

unread,
Oct 11, 2016, 12:46:55 PM10/11/16
to Ruby on Rails: Core

In integration tests, I like that you can set the Accept header ahead of time (i.e. before the request is made):


self.accept = "application/json"


AFAIK this is the only header that can be set in this way. I am missing a way to set any header arbitrarily in the setup phase of these tests. Without it, the alternatives seem to be a) duplicated test code, or b) wrapping the request helpers. Setting a header as in the case of accept= would be preferable to me.

Are there plans to enhance the integration tests in this way? Or reasons to not want to? If acceptable, I'd be happy to tackle this, but wanted to check first. Thanks!


P.S. I had this objection from Rafael França:


You are able to set the headers when doing the request so why you need to do it globally? Duplication in tests is totally fine and even make the tests more clear.

Duplication in test code seems to be a matter of debate. While I largely agree that duplication is fine, I think that it can be desirable to extract common code into a setup method if it's not particularly salient to the behavior being tested. I think setting the same headers in all my API tests would fall into that category. That may be my preference, but I know that many developers are a lot more concerned about duplication in test code than me, so I think this would be a useful feature.
Reply all
Reply to author
Forward
0 new messages