← Back to Upcase

When is it appropriate to define helper methods in Specs

(Chad Heinen) #1

@christoomey - While reviewing a recent Upcase PR I saw that you decided decided to move the sign_in redirect into it’s own method for the spec at the link below.

https://github.com/thoughtbot/upcase/pull/1536/files#diff-001a1e4c64489698395e276e88b8b521R75

I was curious as to why you did this and what value it added. Were you predicting that you would need to extract this method out into a helper and reuse it in the future anyway?

Thanks,
Chad

(Chris Toomey) #2

HI @Chadh13, thanks for the question.

For the line in question, I think I actually took the extraction a bit too far. The extracted line does nothing to clarify the test, and is likely an artifact of an earlier form of the code, rather than something worth repeating.

That said, I’m a huge fan of extracting methods to help clarify specs. You can see this starting a bit further down in that same PR. Anything I can do to keep the spec itself nice and high level, focused only on the pertinent details of the spec while hiding the extraneous details, the better.