overwatering.org

blog

about

So I just went ahead and added the re-usable step definitions support to Cucumber. And it was pulled in time to be included in the new Cucumber 1.2. Which means I’m now looking forward to writing my steps in a much cleaner way.

Given /^I am on the (\w+) page$/, :go_to_known_page,
  :on => lambda { current_user }

class User
  def self.current_user
    ...
  end

  def go_to_known_page(page_name)
    visit Page.page_named(page_name)
  end
end

World(User)

Though I haven’t started yet. Apparently this has triggered some discussion about other ways writing re-usable step definitions could be easier. I’m looking forward to seeing the results of that.

Update 2012-08-22: While implementing this proposal I found that my originally suggested syntax didn’t work. I’ve amended this post to reflect what I actually did implement.