[rspec-users] Story runner "macros"

Ben Mabey ben at benmabey.com
Mon Jan 21 01:00:51 EST 2008

Pat Maddox wrote:
> On Jan 20, 2008 9:09 PM, Rick DeNatale <rick.denatale at gmail.com> wrote:
>> Now I really like the idea of the parameterized stories, but the step
>> away from client-speak makes me shy away from them.  Is there a way to
>> get the power without loosing the intelligibility?
> If I were to redo that, it would be something more like
> When "I create an article titled 'The Title' with a body of 'this is the body'"
> I totally agree that you should be speaking entirely in domain terms.
> I'm still learning too :)
> Also since this is related, for any Bay Area RSpec'ers, I'm giving a
> presentation on Story Runner at Tuesday's meetup.  Check out
> http://ruby.meetup.com/6/calendar/6665552/ for time and location info.
> Pat
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

If you haven't already you should also check out webrat.  It allows you 
to easily write steps that allow your stories to speak in terms of 
forms.. which is what my customers relate to the best.

Along the lines of what Pat was saying.. I still use steps like the one 
he suggested but I usually only use them in Give clauses... so stuff like:

Given "$resource exists in the system with $params" do |resource, params|
    resource.gsub!(" ","_")

class String
  # Coverts a string found in the steps into a hash.  Example:
  # ISBN: '0967539854' and comment: 'I love this book' and rating: '4'
  #   => {"rating"=>"4", "isbn"=>"0967539854", "comment"=>"I love this 
  def to_hash_from_story
    self.split(" and ").inject({}){ |hash_so_far, key_value|
                                              key, value = 
key_value.split(":").map{ |v| v.strip}
hash_so_far.merge(key.downcase => value.gsub("'",""))


More information about the rspec-users mailing list