Re:The Tragedy of Given-When-Then
by Dangeranger on Tuesday April 16, 2019 @01:47PM
(#19675702)
You can embed G/W/T into RSpec. There's a library called Turnip[0], a play on Cucumber, that extends the syntax to Feature tests in RSpec.
- [0] https://github.com/jnicklas/turnip
The reason RSpec didn't include this originally probably stems from the library being designed for testing at the class or module level, rather than an entire application.
I agree with this. Writing Cucumber/Gherkin scenarios is extra effort if the Cucumber files themselves aren't used/read elsewhere. -- It'd be simpler to embed "Given/When/Then" statements within test code (like RSpec).
I'd emphasise that Gojko Adzic's "Specification By Example" suggests discussing examples before refining to a specification; that may get around the author's complaint that non-table formats don't allow for important cases.
That said, "Given/When/Then" is hardly magical, so doesn't deserve much praise/criticism itself. Any test involves "do an action, check the result" (with "setup the system" and "cleanup" being implied). Sometimes called "Assemble, Act, Assert". "G/W/T" is just a neat, consistent format for describing behaviour in English. A table of values specifies some computation; the column titles help to describe that behaviour.