[rspec-users] Stories - Use view matchers rather than assigns[].should?

Pat Maddox pergesu at gmail.com
Thu Apr 10 18:38:07 EDT 2008

On Thu, Apr 10, 2008 at 3:30 PM, Ashley Moran
<ashley.moran at patchspace.co.uk> wrote:
>  On 10 Apr 2008, at 23:06, Pat Maddox wrote:
>  >>   Given ...
>  >>   When I run User.create!(:foo => "bar")
>  >>   Then the Users page should have a row with "bar" in the "foo"
>  >> column
>  >
>  > Gah, that looks hideous.
>  I think you misunderstood the point - it's supposed to look hideous :)

Yes, I am thoroughly confused.

>  What I meant was if you have a load of steps like
>  Given a user named Pat
>  And the user is 22 years old
>  When I view the user list
>  Then I should see the user's name and age
>  But say that actually, "Given a user named Pat"  and "Given the user
>  is 22 years old" are implemented as DB API calls - in this case is
>  there merit to having a special set of stories on one side, just to
>  verify that your low-level steps actually produce the user-facing data
>  you expect, as if they used the GUI to create the data?

I don't know what you mean by a special set of stories.  In the
example I gave, the Given steps would most likely be implemented as AR
calls - not as separate requests.  The When and Then would likely be
implemented as an HTTP request and an assertion on the returned HTML.
But there's no way to tell that from the story narrative.  And
sometimes if the logic is complex and will take a couple iterations, I
might first implement the When and Then steps as AR calls, and then as
we build up the HTML pages around that infrastructure, I'd convert the
step implementations to go through the web request.

Are we somewhat getting on the same page by now? :)

>  I sometimes write "assumption" specs for third party code, if I am
>  relying on behaviour I'm unsure about, just so if the lib API changes
>  it gets flagged.  I saw this as an extension of the idea, not a
>  suggestion to send ActiveRecord method calls to a client's marketing
>  director!!!  (I'm sure there's some bizarre political situation
>  somewhere where that might have an advantage though...)

Michael Feathers, in Working Effectively with Legacy Code, calls these
characterization tests.  They can certainly be very useful.


More information about the rspec-users mailing list