[rspec-users] Best practices for sharing state between story steps?
Sam Stokes
lists at ruby-forum.com
Tue Sep 9 20:50:23 EDT 2008
Thanks everyone for your responses - this is a really helpful discussion
and every post has added to my understanding. Thanks also for
disagreeing with each other, as it makes me feel less stupid for asking
the question :)
Jim Morris wrote:
> Ok I think I see the difference, by the state being in the Database or
> the response variable it does
> not implicitly couple steps like an @variable would. But it still
> requires the database to have been
> setup in a certain state by certain preceding Givens or Whens, which is
> a kind of coupling. But
> maybe I am stretching too far on that argument? I still feel coupling is
> coupling and state is state :)
It seems to me that with
"Given an existing post 'lol internet'" # creates a post with that title
"Then the page should include 'lol internet'" # assumes a post with that
title
the assumptions are in line with what you'd naturally understand from
the English, whereas
"Given an existing post 'lol internet'" # creates and stores in
@the_post
"Then I should see the post title" # verifies @the_post matches what's
in the db
seems to make more assumptions than are obvious from the English.
In fact, couldn't one argue that the second example is redundantly
storing the post in two places (the database and @the_post)? I think
this is what Aslak means by distinguishing "stateful" and "stateless" -
@variables are *extra* state, on top of the application state which must
change either way or you're not testing anything.
--
Posted via http://www.ruby-forum.com/.
More information about the rspec-users
mailing list