monologue icon indicating copy to clipboard operation
monologue copied to clipboard

This is much jasmine hell as I could raise in an hour

Open searls opened this issue 13 years ago • 2 comments

I just tried to hack up as much of this as I could without changing any production source.

searls avatar May 17 '12 23:05 searls

Nicely done.

I'm not actually sold on jasmine-given. I think it's a really interesting idea, but I don't love it. It doesn't feel to me like it adds clarity. Want to convince me?

bkeepers avatar May 19 '12 21:05 bkeepers

The benefits of the *-given style are nuanced, and they become clearer if you just give it a try (I was actually turned off to them until Jim Weirich encouraged me to try rspec-given on a real project).

So, with the caveat that "you just have to try it", I do like these aspects a lot:

  • No it strings - the vast majority of example descriptions I write are obvious if you read the expectation. The non-obvious expectations should be made to be obvious.
  • Every arrange/act/assert action you take is pressured into being expressed in one line, and as a result: clearly. In multi-line beforeEach and it blocks, the test phases are often ambiguous (or out-of-order)
  • The act of refactoring spec code is much easier, because each line can easily be pulled up or pushed down to a different level of nesting (great for DRYing specs up)
  • Most of my tests boil down to easy boolean assertions, so I like that returning false from a Then will trip a failure. (meaning I don't write expect() so much)

As a bonus, after converting a very large project to jasmine-given I was happy to find that the ratio of spec-to-production lines dropped from 4:1 to around 2.5:1. The increased information density just made it easier to read and less intimidating to others.

searls avatar May 19 '12 22:05 searls