Skip to content
This repository was archived by the owner on Nov 16, 2018. It is now read-only.

A Whole New World

aslakhellesoy edited this page Aug 13, 2010 · 17 revisions

Cucumber runs scenarios in a World. By default, the World is just an instance of Object. If you want to add any behaviour to the world, perhaps some helper methods, or logging, or whatever. You can do this in support/env.rb:

class CustomWorld
  def a_helper
    ...
  end
end

World do
  CustomWorld.new
end

Now you can call a_helper from any step you want. Note that every scenario gets run in a separate instance of the world, so there is no implicit state-sharing from scenario to scenario.

You can also define several World blocks. They will be called in a chain, yielding the result of the previous to the next:

World do |world|
  world.extend(FirstModule)
  world
end

World do |world|
  world.extend(SecondModule)
  world
end

Clone this wiki locally