Update to ruby/mspec@bd47c2a
This commit is contained in:
parent
c1790f8c11
commit
1dc6bed0ca
@ -4,4 +4,4 @@ $:.unshift File.expand_path('../../lib', __FILE__)
|
|||||||
|
|
||||||
require 'mspec/commands/mspec'
|
require 'mspec/commands/mspec'
|
||||||
|
|
||||||
MSpecMain.main
|
MSpecMain.main(false)
|
||||||
|
@ -25,6 +25,7 @@ class MSpecMain < MSpecScript
|
|||||||
config[:command] = argv.shift if ["ci", "run", "tag"].include?(argv[0])
|
config[:command] = argv.shift if ["ci", "run", "tag"].include?(argv[0])
|
||||||
|
|
||||||
options = MSpecOptions.new "mspec [COMMAND] [options] (FILE|DIRECTORY|GLOB)+", 30, config
|
options = MSpecOptions.new "mspec [COMMAND] [options] (FILE|DIRECTORY|GLOB)+", 30, config
|
||||||
|
@options = options
|
||||||
|
|
||||||
options.doc " The mspec command sets up and invokes the sub-commands"
|
options.doc " The mspec command sets up and invokes the sub-commands"
|
||||||
options.doc " (see below) to enable, for instance, running the specs"
|
options.doc " (see below) to enable, for instance, running the specs"
|
||||||
@ -110,8 +111,9 @@ class MSpecMain < MSpecScript
|
|||||||
if config[:multi]
|
if config[:multi]
|
||||||
exit multi_exec(argv)
|
exit multi_exec(argv)
|
||||||
else
|
else
|
||||||
$stderr.puts "$ #{argv.join(' ')}"
|
log = config[:options].include?('--error-output') ? $stdout : $stderr
|
||||||
$stderr.flush
|
log.puts "$ #{argv.join(' ')}"
|
||||||
|
log.flush
|
||||||
exec(*argv, close_others: false)
|
exec(*argv, close_others: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
class RaiseErrorMatcher
|
class RaiseErrorMatcher
|
||||||
|
FAILURE_MESSAGE_FOR_EXCEPTION = {}.compare_by_identity
|
||||||
|
|
||||||
attr_writer :block
|
attr_writer :block
|
||||||
|
|
||||||
def initialize(exception, message, &block)
|
def initialize(exception, message, &block)
|
||||||
@ -15,7 +17,7 @@ class RaiseErrorMatcher
|
|||||||
def matches?(proc)
|
def matches?(proc)
|
||||||
@result = proc.call
|
@result = proc.call
|
||||||
return false
|
return false
|
||||||
rescue Exception => actual
|
rescue Object => actual
|
||||||
@actual = actual
|
@actual = actual
|
||||||
|
|
||||||
if matching_exception?(actual)
|
if matching_exception?(actual)
|
||||||
@ -23,7 +25,7 @@ class RaiseErrorMatcher
|
|||||||
@block[actual] if @block
|
@block[actual] if @block
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
actual.instance_variable_set(:@mspec_raise_error_message, failure_message)
|
FAILURE_MESSAGE_FOR_EXCEPTION[actual] = failure_message
|
||||||
raise actual
|
raise actual
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -29,7 +29,7 @@ class ExceptionState
|
|||||||
|
|
||||||
if @failure
|
if @failure
|
||||||
message
|
message
|
||||||
elsif raise_error_message = @exception.instance_variable_get(:@mspec_raise_error_message)
|
elsif raise_error_message = RaiseErrorMatcher::FAILURE_MESSAGE_FOR_EXCEPTION[@exception]
|
||||||
raise_error_message.join("\n")
|
raise_error_message.join("\n")
|
||||||
else
|
else
|
||||||
"#{@exception.class}: #{message}"
|
"#{@exception.class}: #{message}"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
require 'mspec/expectations/expectations'
|
require 'mspec/expectations/expectations'
|
||||||
require 'mspec/runner/actions/timer'
|
require 'mspec/runner/actions/timer'
|
||||||
require 'mspec/runner/actions/tally'
|
require 'mspec/runner/actions/tally'
|
||||||
|
require 'mspec/utils/options'
|
||||||
|
|
||||||
if ENV['CHECK_LEAKS']
|
if ENV['CHECK_LEAKS']
|
||||||
require 'mspec/runner/actions/leakchecker'
|
require 'mspec/runner/actions/leakchecker'
|
||||||
@ -18,10 +19,17 @@ class BaseFormatter
|
|||||||
|
|
||||||
@count = 0 # For subclasses
|
@count = 0 # For subclasses
|
||||||
|
|
||||||
if out.nil?
|
if out
|
||||||
@out = $stdout
|
|
||||||
else
|
|
||||||
@out = File.open out, "w"
|
@out = File.open out, "w"
|
||||||
|
else
|
||||||
|
@out = $stdout
|
||||||
|
end
|
||||||
|
|
||||||
|
err = MSpecOptions.latest && MSpecOptions.latest.config[:error_output]
|
||||||
|
if err
|
||||||
|
@err = (err == 'stderr') ? $stderr : File.open(err, "w")
|
||||||
|
else
|
||||||
|
@err = @out
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -115,9 +123,9 @@ class BaseFormatter
|
|||||||
|
|
||||||
def print_exception(exc, count)
|
def print_exception(exc, count)
|
||||||
outcome = exc.failure? ? "FAILED" : "ERROR"
|
outcome = exc.failure? ? "FAILED" : "ERROR"
|
||||||
print "\n#{count})\n#{exc.description} #{outcome}\n"
|
@err.print "\n#{count})\n#{exc.description} #{outcome}\n"
|
||||||
print exc.message, "\n"
|
@err.print exc.message, "\n"
|
||||||
print exc.backtrace, "\n"
|
@err.print exc.backtrace, "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
# A convenience method to allow printing to different outputs.
|
# A convenience method to allow printing to different outputs.
|
||||||
|
@ -117,7 +117,7 @@ module MSpec
|
|||||||
raise e
|
raise e
|
||||||
rescue SkippedSpecError => e
|
rescue SkippedSpecError => e
|
||||||
return false
|
return false
|
||||||
rescue Exception => exc
|
rescue Object => exc
|
||||||
register_exit 1
|
register_exit 1
|
||||||
actions :exception, ExceptionState.new(current && current.state, location, exc)
|
actions :exception, ExceptionState.new(current && current.state, location, exc)
|
||||||
return false
|
return false
|
||||||
|
@ -32,6 +32,10 @@ class MSpecOptions
|
|||||||
# Raised if an unrecognized option is encountered.
|
# Raised if an unrecognized option is encountered.
|
||||||
class ParseError < Exception; end
|
class ParseError < Exception; end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
attr_accessor :latest
|
||||||
|
end
|
||||||
|
|
||||||
attr_accessor :config, :banner, :width, :options
|
attr_accessor :config, :banner, :width, :options
|
||||||
|
|
||||||
def initialize(banner = "", width = 30, config = nil)
|
def initialize(banner = "", width = 30, config = nil)
|
||||||
@ -46,7 +50,7 @@ class MSpecOptions
|
|||||||
@extra << x
|
@extra << x
|
||||||
}
|
}
|
||||||
|
|
||||||
yield self if block_given?
|
MSpecOptions.latest = self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Registers an option. Acceptable formats for arguments are:
|
# Registers an option. Acceptable formats for arguments are:
|
||||||
@ -311,6 +315,11 @@ class MSpecOptions
|
|||||||
"Write formatter output to FILE") do |f|
|
"Write formatter output to FILE") do |f|
|
||||||
config[:output] = f
|
config[:output] = f
|
||||||
end
|
end
|
||||||
|
|
||||||
|
on("--error-output", "FILE",
|
||||||
|
"Write error output of failing specs to FILE, or $stderr if value is 'stderr'.") do |f|
|
||||||
|
config[:error_output] = f
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def filters
|
def filters
|
||||||
|
@ -37,6 +37,17 @@ class MSpecScript
|
|||||||
config[key]
|
config[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
attr_accessor :child_process
|
||||||
|
end
|
||||||
|
|
||||||
|
# True if the current process is the one going to run the specs with `MSpec.process`.
|
||||||
|
# False for e.g. `mspec` which exec's to `mspec-run`.
|
||||||
|
# This is useful in .mspec config files.
|
||||||
|
def self.child_process?
|
||||||
|
MSpecScript.child_process
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
check_version!
|
check_version!
|
||||||
|
|
||||||
@ -267,7 +278,9 @@ class MSpecScript
|
|||||||
|
|
||||||
# Instantiates an instance and calls the series of methods to
|
# Instantiates an instance and calls the series of methods to
|
||||||
# invoke the script.
|
# invoke the script.
|
||||||
def self.main
|
def self.main(child_process = true)
|
||||||
|
MSpecScript.child_process = child_process
|
||||||
|
|
||||||
script = new
|
script = new
|
||||||
script.load_default
|
script.load_default
|
||||||
script.try_load '~/.mspecrc'
|
script.try_load '~/.mspecrc'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user