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
  end
  @current
end

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


_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to