svenfuchs
2/28/2010 - 2:24 AM

how_to_test_cucumber_step_definitions.rb

# i want to test/unit test some step definitions (webrat compat steps for steam)
# 
# there must be an easier way to do that ... i have to set up the $step_mother globally
# because the steps file is loaded through require, i.e. it wouldn't be reloaded if
# I would set this up in #setup.
#
# this way i can then call something like $step_mother.invoke('I press "button"') in
# my test case.

module PathTo
  def path_to(page_name)
    "http://localhost:3000/#{page_name}"
  end
end
include PathTo

connection = Steam::Connection::Mock.new
$browser = Steam::Browser.create(connection)

$step_mother = Cucumber::StepMother.new
$step_mother.log = Logger.new(File.open('/dev/null', 'w'))
steps_file = File.expand_path('../../../example/cucumber/webrat_compatible_steps.rb', __FILE__)
$step_mother.load_code_file(steps_file)

ruby = $step_mother.load_programming_language('rb')
ruby.build_rb_world_factory([PathTo], lambda { Steam::Session.new($browser) })
ruby.send(:create_world)
ruby.send(:extend_world)