class RSpec::MultiprocessRunner::RakeTask

Rake task to invoke `multispec`. Lots of it is copied from RSpec::Core::RakeTask.

@see Rakefile

Constants

DEFAULT_MULTIRSPEC_PATH

Default path to the multirspec executable.

Attributes

directories=[RW]

File search will be limited to these directories or specific files. Defaults to nil.

example_timeout_seconds[RW]

The maximum number of seconds to allow a single example to run before killing it. Defaults to 15.

fail_on_error[RW]

Whether or not to fail Rake when an error occurs (typically when examples fail). Defaults to `true`.

failure_message[RW]

A message to print to stderr when there are failures.

file_timeout_seconds[RW]

The maximum number of seconds to allow a single spec file to run before killing it. Defaults to disabled.

files=[RW]

File search will be limited to these directories or specific files. Defaults to nil.

files_or_directories[RW]

File search will be limited to these directories or specific files. Defaults to nil.

first_is_1[RW]

If true, set TEST_ENV_NUMBER=“1” for the first worker (instead of “”)

hostname[RW]

Hostname of head node. Defaults to `localhost`

log_failing_files[RW]

Filename to which to append a list of the files containing specs that failed.

max_nodes[RW]

Max number of connections to head_node. Defaults to `5`

multirspec_path[RW]

Path to the multispec executable. Defaults to the absolute path to the rspec binary from the loaded rspec-core gem.

name[RW]

Name of task. Defaults to `:multispec`.

node[RW]

Be a node to a head node at hostname. Defaults to `false`

pattern[RW]

Files matching this pattern will be loaded. Defaults to `'*/_spec.rb'`.

port[RW]

Port to use for TCP communication. Defaults to `2222`.

rspec_opts[RW]

Command line options to pass to the RSpec workers. Defaults to `nil`.

run_identifier[RW]

Unique string used by nodes to confirm identity

use_given_order[RW]

Use order of files as given on the command line

verbose[RW]

Use verbose output. If this is set to true, the task will print the executed spec command to stdout. Defaults to `true`.

worker_count[RW]

The number of workers to run. Defaults to 3.

Public Class Methods

new(*args, &task_block) click to toggle source
# File lib/rspec/multiprocess_runner/rake_task.rb, line 83
def initialize(*args, &task_block)
  @name            = args.shift || :multispec
  @verbose         = true
  @fail_on_error   = true
  @multirspec_path = DEFAULT_MULTIRSPEC_PATH

  define(args, &task_block)
end

Public Instance Methods

run_task(verbose) click to toggle source

@private

# File lib/rspec/multiprocess_runner/rake_task.rb, line 93
def run_task(verbose)
  command = spec_command
  puts Shellwords.shelljoin(command) if verbose

  return if system(*command)
  puts failure_message if failure_message

  return unless fail_on_error
  $stderr.puts "#{command} failed" if verbose
  exit $?.exitstatus
end

Private Instance Methods

define(args, &task_block) click to toggle source

@private

# File lib/rspec/multiprocess_runner/rake_task.rb, line 108
def define(args, &task_block)
  desc "Run RSpec code examples" unless ::Rake.application.last_description

  task name, *args do |_, task_args|
    RakeFileUtils.__send__(:verbose, verbose) do
      task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
      run_task verbose
    end
  end
end
spec_command() click to toggle source
# File lib/rspec/multiprocess_runner/rake_task.rb, line 119
def spec_command
  cmd_parts = []
  cmd_parts << RUBY
  cmd_parts << multirspec_path
  if worker_count
    cmd_parts << '--worker-count' << worker_count.to_s
  end
  if example_timeout_seconds
    cmd_parts << '--example-timeout' << example_timeout_seconds.to_s
  end
  if file_timeout_seconds
    cmd_parts << '--file-timeout' << file_timeout_seconds.to_s
  end
  if first_is_1
    cmd_parts << '--first-is-1'
  end
  if pattern
    cmd_parts << '--pattern' << pattern
  end
  if log_failing_files
    cmd_parts << '--log-failing-files' << log_failing_files
  end
  if use_given_order
    cmd_parts << '--use-given-order'
  end
  if port
    cmd_parts << '--port' << port.to_s
  end
  if node
    cmd_parts << '--node'
  end
  if hostname
    cmd_parts << '--hostname' << hostname
  end
  if max_nodes
    cmd_parts << '--max-nodes' << max_nodes.to_s
  end
  if run_identifier
    cmd_parts << '--run-identifier' << run_identifier.to_s
  end
  if files_or_directories
    cmd_parts.concat(files_or_directories)
  end
  if rspec_opts
    cmd_parts << '--'
    cmd_parts.concat(Shellwords.shellsplit rspec_opts)
  end

  cmd_parts
end