Method: Wukong::SpecHelpers::UnitTests#runner

Defined in:
lib/wukong/spec_helpers/unit_tests.rb

#runner(klass, program_name, *args, &block) ⇒ Object

Create and boot up a runner of the given klass.

Options to the runner class are given in the args Array. The last element of this Array can be a Hash of options to directly pass to the runner (especially useful in unit tests). The rest of the elements are strings that will be parsed as though they were command-line arguments.

A passed block will be eval'd in the context of the newlyl created runner instance. This can be used to interact with the runner's insides after initialization.

Examples:

Create a runner that simulates wu-local with a set of arguments


runner Wukong::Local::LocalRunner, 'wu-local', '--foo=bar', '--baz=boof', wof: 'bing'

Create a custom runner and set a property on it


runner(CustomRunner, 'wu-custom', '--foo=bar') do
  # eval'd in scope of new runner instance
  do_some_special_thing!
end

Parameters:

  • klass (Class)
  • program_name (String)
  • args (Array<String>, Hash)


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/wukong/spec_helpers/unit_tests.rb', line 38

def runner klass, program_name, *args, &block
  settings = args.extract_options!
  
  ARGV.replace(args.map(&:to_s))

  klass.new.tap do |the_runner|
    the_runner.program_name = program_name
    the_runner.instance_eval(&block) if block_given?
    the_runner.boot!(settings)
  end
end