Class: RSpec::MultiprocessRunner::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/rspec/multiprocess_runner/rake_task.rb

Overview

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

See Also:

  • Rakefile

Constant Summary collapse

DEFAULT_MULTIRSPEC_PATH =

Default path to the multirspec executable.

File.expand_path('../../../../exe/multirspec', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &task_block) ⇒ RakeTask

Returns a new instance of RakeTask.



83
84
85
86
87
88
89
90
# 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

Instance Attribute Details

#example_timeout_secondsObject

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



38
39
40
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 38

def example_timeout_seconds
  @example_timeout_seconds
end

#fail_on_errorObject

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



45
46
47
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 45

def fail_on_error
  @fail_on_error
end

#failure_messageObject

A message to print to stderr when there are failures.



48
49
50
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 48

def failure_message
  @failure_message
end

#file_timeout_secondsObject

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



34
35
36
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 34

def file_timeout_seconds
  @file_timeout_seconds
end

#files_or_directoriesObject

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



25
26
27
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 25

def files_or_directories
  @files_or_directories
end

#first_is_1Object

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



41
42
43
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 41

def first_is_1
  @first_is_1
end

#hostnameObject

Hostname of head node. Defaults to ‘localhost`



75
76
77
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 75

def hostname
  @hostname
end

#log_failing_filesObject

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



60
61
62
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 60

def log_failing_files
  @log_failing_files
end

#max_nodesObject

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



78
79
80
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 78

def max_nodes
  @max_nodes
end

#multirspec_pathObject

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



56
57
58
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 56

def multirspec_path
  @multirspec_path
end

#nameObject

Name of task. Defaults to ‘:multispec`.



17
18
19
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 17

def name
  @name
end

#nodeObject

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



72
73
74
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 72

def node
  @node
end

#patternObject

Files matching this pattern will be loaded. Defaults to ‘’*/_spec.rb’‘.



21
22
23
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 21

def pattern
  @pattern
end

#portObject

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



69
70
71
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 69

def port
  @port
end

#rspec_optsObject

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



66
67
68
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 66

def rspec_opts
  @rspec_opts
end

#run_identifierObject

Unique string used by nodes to confirm identity



81
82
83
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 81

def run_identifier
  @run_identifier
end

#use_given_orderObject

Use order of files as given on the command line



63
64
65
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 63

def use_given_order
  @use_given_order
end

#verboseObject

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



52
53
54
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 52

def verbose
  @verbose
end

#worker_countObject

The number of workers to run. Defaults to 3.



30
31
32
# File 'lib/rspec/multiprocess_runner/rake_task.rb', line 30

def worker_count
  @worker_count
end

Instance Method Details

#run_task(verbose) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# 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