[rspec-users] BDD / cucumber thought - chaining 'Then' steps with Which

Jonathan Linowes jonathan at parkerhill.com
Fri Sep 26 11:04:37 EDT 2008

On Sep 26, 2008, at 9:06 AM, Matt Wynne wrote:

> FWIW, I think it's rather nice. We went through a fad of using @it  
> for a while, and now we have a stuff[] hash. Both similar ideas -  
> there must be something in this.

I'm doing the same thing. I had @current_project, @current_page etc  
( http://www.mail-archive.com/rspec-users@rubyforge.org/ 
msg06272.html ) but now keep it in a hash @current[:project] etc.

I encountered a problem with things like "When I click the first item  
in the list" or even "When I visit /foos/123", my story doesnt know  
what state its in after that. But then I realized the state is  
embedded in the url !!

This is a RESTful rails app so I wrote a little helper that parses  
the current url to reset my instance variables, which looks something  
like this (mine actually does more, like strips off trailing anchors  
(#foo), assigns variables into @current (?foo=123), and captures  
subdomain.test.com in an :account)

def current_resources( url = nil )
   url ||= response.request.request_uri
   # split resources
   bits = url.split('/')
   bits.shift # initial '/'
   # assign resources
   while !bits.blank?
     @current[ bits.shift.to_sym ] = bits.shift

So after any get, post, visits, clicks etc I call current_resource  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080926/0ad77cce/attachment.html>

More information about the rspec-users mailing list