Cucumber 中的 World

引用
require 'spec/stubs/cucumber'

The spec/stubs/cucumber ships with RSpec (as of version 1.2.8), and
adds behaviour to the Cucumber World to support using RSpec stubs
in Cucumber scenarios.3

To ensure that each cucumber scenario starts with a clean slate, your scenarios are run upon a blank Object.new object. Or in a Rails project its a new Rails test session ActionController::IntegrationTest.

These are called World objects (see cucumber wiki). You pass in a specific World object you’d like to use, else it defaults to Object.new For a Rails project, you’re using Cucumber::Rails::World.new for your world object each time, which is a subclass of ActionController::IntegrationTest.

The benefit of a World object starting point for each scenario is that you can add methods to it, that won’t affect the rest of the Ruby world you live in: which will be the Cucumber runner. That is, you cannot accidently blow up Cucumber.


World(*world_modules, &proc)


Registers any number of world_modules (Ruby Modules) and/or a Proc. The proc will be executed once before each scenario to create an Object that the scenario’s steps will run within. Any world_modules will be mixed into this Object (via Object#extend).

This method is typically called from one or more Ruby scripts under features/support. You can call this method as many times as you like (to register more modules), but if you try to register more than one Proc you will get an error.

Cucumber will not yield anything to the proc. Examples:

   World do
     MyClass.new
   end

   World(MyModule)


########been excuted#########
########been excuted#########
########been excuted#########
You can only pass a proc to #World once, but it's happening
in 2 places:

/world.rb:27:in `World'
vendor/plugins/email-spec/features/support/env.rb:14:in `World'







# File 'lib/cucumber/rb_support/rb_dsl.rb', line 47

def World(*world_modules, &proc)
  RbDsl.build_rb_world_factory(world_modules, proc)
end




你可能感兴趣的:(REST,Ruby,UP,Rails,rspec)