[rspec-users] Best practices for sharing state between story steps?
ml at e4net.com
Tue Sep 9 23:54:06 EDT 2008
Sam Stokes wrote:
> 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
> 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
> "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.
Thats true in that case. I also wouldn't do what you show in the second case. If I can get the
result from the API or the database I would.
In my case I store data between states that I can't get anywhere else, or that tells me where to get
the results from.
Jim Morris, http://blog.wolfman.com
More information about the rspec-users