Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

searls
Copy link

@searls searls commented May 17, 2012

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

  (I'm recognizing how hilariously unnecessary
     this all is so far, given the test coverage)
  separately, so I've reworked the tests to demo
  that a bit. 

This change is 50% style and (IMO) 50% beneficial.
  The benefits are primarily that it tends to make
  unit isolation a tad easier to pull off, and in 
  the long run I've found specs that focus on 
  tackling named methods easier to maintain. I say
  maintenance is easier b/c the spec tells me the 
  public API very clearly (when I need to change
  a method I know where to go), and when a second
  event calls the same method, I don't have to hide
  behind any shenanigans like "shared example groups"
  to DRY things up.*

*But really I do love shared example groups when
  they make sense
@bkeepers
Copy link
Owner

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?

@searls
Copy link
Author

searls commented May 19, 2012

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants