mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/mspec@a401f63
This commit is contained in:
parent
93a512414c
commit
ab8345271e
56 changed files with 305 additions and 278 deletions
|
@ -19,7 +19,7 @@ class MkSpec
|
|||
@map = NameMap.new true
|
||||
end
|
||||
|
||||
def options(argv=ARGV)
|
||||
def options(argv = ARGV)
|
||||
options = MSpecOptions.new "mkspec [options]", 32
|
||||
|
||||
options.on("-c", "--constant", "CONSTANT",
|
||||
|
|
|
@ -8,7 +8,7 @@ require 'mspec/utils/script'
|
|||
|
||||
|
||||
class MSpecCI < MSpecScript
|
||||
def options(argv=ARGV)
|
||||
def options(argv = ARGV)
|
||||
options = MSpecOptions.new "mspec ci [options] (FILE|DIRECTORY|GLOB)+", 30, config
|
||||
|
||||
options.doc " Ask yourself:"
|
||||
|
|
|
@ -14,7 +14,7 @@ class MSpecRun < MSpecScript
|
|||
config[:files] = []
|
||||
end
|
||||
|
||||
def options(argv=ARGV)
|
||||
def options(argv = ARGV)
|
||||
options = MSpecOptions.new "mspec run [options] (FILE|DIRECTORY|GLOB)+", 30, config
|
||||
|
||||
options.doc " Ask yourself:"
|
||||
|
|
|
@ -15,7 +15,7 @@ class MSpecTag < MSpecScript
|
|||
config[:ltags] = []
|
||||
end
|
||||
|
||||
def options(argv=ARGV)
|
||||
def options(argv = ARGV)
|
||||
options = MSpecOptions.new "mspec tag [options] (FILE|DIRECTORY|GLOB)+", 30, config
|
||||
|
||||
options.doc " Ask yourself:"
|
||||
|
|
|
@ -21,7 +21,7 @@ class MSpecMain < MSpecScript
|
|||
config[:launch] = []
|
||||
end
|
||||
|
||||
def options(argv=ARGV)
|
||||
def options(argv = ARGV)
|
||||
config[:command] = argv.shift if ["ci", "run", "tag"].include?(argv[0])
|
||||
|
||||
options = MSpecOptions.new "mspec [COMMAND] [options] (FILE|DIRECTORY|GLOB)+", 30, config
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#
|
||||
# Possible keys are:
|
||||
# :year, :month, :day, :hour, :minute, :second, :offset and :sg.
|
||||
def new_datetime(opts={})
|
||||
def new_datetime(opts = {})
|
||||
require 'date'
|
||||
|
||||
value = {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
def flunk(msg="This example is a failure")
|
||||
def flunk(msg = "This example is a failure")
|
||||
SpecExpectation.fail_with "Failed:", msg
|
||||
end
|
||||
|
|
|
@ -55,7 +55,7 @@ end
|
|||
|
||||
# Creates a file +name+. Creates the directory for +name+
|
||||
# if it does not exist.
|
||||
def touch(name, mode="w")
|
||||
def touch(name, mode = "w")
|
||||
mkdir_p File.dirname(name)
|
||||
|
||||
File.open(name, mode) do |f|
|
||||
|
|
|
@ -64,7 +64,7 @@ end
|
|||
# Creates a "bare" file descriptor (i.e. one that is not associated
|
||||
# with any Ruby object). The file descriptor can safely be passed
|
||||
# to IO.new without creating a Ruby object alias to the fd.
|
||||
def new_fd(name, mode="w:utf-8")
|
||||
def new_fd(name, mode = "w:utf-8")
|
||||
if mode.kind_of? Hash
|
||||
if mode.key? :mode
|
||||
mode = mode[:mode]
|
||||
|
|
|
@ -8,7 +8,7 @@ def infinity_value
|
|||
1/0.0
|
||||
end
|
||||
|
||||
def bignum_value(plus=0)
|
||||
def bignum_value(plus = 0)
|
||||
0x8000_0000_0000_0000 + plus
|
||||
end
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ all specs are cleaning up temporary files:
|
|||
end
|
||||
end
|
||||
|
||||
def tmp(name, uniquify=true)
|
||||
def tmp(name, uniquify = true)
|
||||
Dir.mkdir SPEC_TEMP_DIR unless Dir.exist? SPEC_TEMP_DIR
|
||||
|
||||
if uniquify and !name.empty?
|
||||
|
|
|
@ -18,7 +18,7 @@ class HaveInstanceMethodMatcher < MethodMatcher
|
|||
end
|
||||
|
||||
module MSpecMatchers
|
||||
private def have_instance_method(method, include_super=true)
|
||||
private def have_instance_method(method, include_super = true)
|
||||
HaveInstanceMethodMatcher.new method, include_super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class HaveMethodMatcher < MethodMatcher
|
|||
end
|
||||
|
||||
module MSpecMatchers
|
||||
private def have_method(method, include_super=true)
|
||||
private def have_method(method, include_super = true)
|
||||
HaveMethodMatcher.new method, include_super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class HavePrivateInstanceMethodMatcher < MethodMatcher
|
|||
end
|
||||
|
||||
module MSpecMatchers
|
||||
private def have_private_instance_method(method, include_super=true)
|
||||
private def have_private_instance_method(method, include_super = true)
|
||||
HavePrivateInstanceMethodMatcher.new method, include_super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class HavePrivateMethodMatcher < MethodMatcher
|
|||
end
|
||||
|
||||
module MSpecMatchers
|
||||
private def have_private_method(method, include_super=true)
|
||||
private def have_private_method(method, include_super = true)
|
||||
HavePrivateMethodMatcher.new method, include_super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class HaveProtectedInstanceMethodMatcher < MethodMatcher
|
|||
end
|
||||
|
||||
module MSpecMatchers
|
||||
private def have_protected_instance_method(method, include_super=true)
|
||||
private def have_protected_instance_method(method, include_super = true)
|
||||
HaveProtectedInstanceMethodMatcher.new method, include_super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class HavePublicInstanceMethodMatcher < MethodMatcher
|
|||
end
|
||||
|
||||
module MSpecMatchers
|
||||
private def have_public_instance_method(method, include_super=true)
|
||||
private def have_public_instance_method(method, include_super = true)
|
||||
HavePublicInstanceMethodMatcher.new method, include_super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class HaveSingletonMethodMatcher < MethodMatcher
|
|||
end
|
||||
|
||||
module MSpecMatchers
|
||||
private def have_singleton_method(method, include_super=true)
|
||||
private def have_singleton_method(method, include_super = true)
|
||||
HaveSingletonMethodMatcher.new method, include_super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class MethodMatcher
|
||||
def initialize(method, include_super=true)
|
||||
def initialize(method, include_super = true)
|
||||
@include_super = include_super
|
||||
@method = method.to_sym
|
||||
end
|
||||
|
|
|
@ -61,7 +61,7 @@ class OutputMatcher
|
|||
end
|
||||
|
||||
module MSpecMatchers
|
||||
private def output(stdout=nil, stderr=nil)
|
||||
private def output(stdout = nil, stderr = nil)
|
||||
OutputMatcher.new(stdout, stderr)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,7 +74,7 @@ class RaiseErrorMatcher
|
|||
end
|
||||
|
||||
module MSpecMatchers
|
||||
private def raise_error(exception=Exception, message=nil, &block)
|
||||
private def raise_error(exception = Exception, message = nil, &block)
|
||||
RaiseErrorMatcher.new(exception, message, &block)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,7 +48,7 @@ module Mock
|
|||
end
|
||||
end
|
||||
|
||||
def self.install_method(obj, sym, type=nil)
|
||||
def self.install_method(obj, sym, type = nil)
|
||||
meta = obj.singleton_class
|
||||
|
||||
key = replaced_key obj, sym
|
||||
|
|
|
@ -15,7 +15,7 @@ class Object
|
|||
end
|
||||
end
|
||||
|
||||
def mock(name, options={})
|
||||
def mock(name, options = {})
|
||||
MockObject.new name, options
|
||||
end
|
||||
|
||||
|
@ -23,6 +23,6 @@ def mock_int(val)
|
|||
MockIntObject.new(val)
|
||||
end
|
||||
|
||||
def mock_numeric(name, options={})
|
||||
def mock_numeric(name, options = {})
|
||||
NumericMockObject.new name, options
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class MockObject
|
||||
def initialize(name, options={})
|
||||
def initialize(name, options = {})
|
||||
@name = name
|
||||
@null = options[:null_object]
|
||||
end
|
||||
|
@ -11,7 +11,7 @@ class MockObject
|
|||
end
|
||||
|
||||
class NumericMockObject < Numeric
|
||||
def initialize(name, options={})
|
||||
def initialize(name, options = {})
|
||||
@name = name
|
||||
@null = options[:null_object]
|
||||
end
|
||||
|
@ -50,7 +50,7 @@ end
|
|||
class MockProxy
|
||||
attr_reader :raising, :yielding
|
||||
|
||||
def initialize(type=nil)
|
||||
def initialize(type = nil)
|
||||
@multiple_returns = nil
|
||||
@returning = nil
|
||||
@raising = nil
|
||||
|
|
|
@ -10,7 +10,7 @@ require 'mspec/runner/filters/match'
|
|||
# trigger the action.
|
||||
|
||||
class ActionFilter
|
||||
def initialize(tags=nil, descs=nil)
|
||||
def initialize(tags = nil, descs = nil)
|
||||
@tags = Array(tags)
|
||||
descs = Array(descs)
|
||||
@sfilter = descs.empty? ? nil : MatchFilter.new(nil, *descs)
|
||||
|
|
|
@ -141,7 +141,7 @@ class LeakChecker
|
|||
end
|
||||
end
|
||||
|
||||
def find_tempfiles(prev_count=-1)
|
||||
def find_tempfiles(prev_count = -1)
|
||||
return [prev_count, []] unless defined? Tempfile
|
||||
extend_tempfile_counter
|
||||
count = TempfileCounter.count
|
||||
|
|
60
spec/mspec/lib/mspec/runner/actions/profile.rb
Normal file
60
spec/mspec/lib/mspec/runner/actions/profile.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
class ProfileAction
|
||||
def initialize
|
||||
@describe_name = nil
|
||||
@describe_time = nil
|
||||
@describes = []
|
||||
@its = []
|
||||
end
|
||||
|
||||
def register
|
||||
MSpec.register :enter, self
|
||||
MSpec.register :before,self
|
||||
MSpec.register :after, self
|
||||
MSpec.register :finish,self
|
||||
end
|
||||
|
||||
def enter(describe)
|
||||
if @describe_time
|
||||
@describes << [@describe_name, now - @describe_time]
|
||||
end
|
||||
|
||||
@describe_name = describe
|
||||
@describe_time = now
|
||||
end
|
||||
|
||||
def before(state)
|
||||
@it_name = state.it
|
||||
@it_time = now
|
||||
end
|
||||
|
||||
def after(state = nil)
|
||||
@its << [@describe_name, @it_name, now - @it_time]
|
||||
end
|
||||
|
||||
def finish
|
||||
puts "\nProfiling info:"
|
||||
|
||||
desc = @describes.sort { |a,b| b.last <=> a.last }
|
||||
desc.delete_if { |a| a.last <= 0.001 }
|
||||
show = desc[0, 100]
|
||||
|
||||
puts "Top #{show.size} describes:"
|
||||
|
||||
show.each do |des, time|
|
||||
printf "%3.3f - %s\n", time, des
|
||||
end
|
||||
|
||||
its = @its.sort { |a,b| b.last <=> a.last }
|
||||
its.delete_if { |a| a.last <= 0.001 }
|
||||
show = its[0, 100]
|
||||
|
||||
puts "\nTop #{show.size} its:"
|
||||
show.each do |des, it, time|
|
||||
printf "%3.3f - %s %s\n", time, des, it
|
||||
end
|
||||
end
|
||||
|
||||
def now
|
||||
Time.now.to_f
|
||||
end
|
||||
end
|
|
@ -22,7 +22,7 @@ require 'mspec/runner/actions/filter'
|
|||
# spec description strings
|
||||
|
||||
class TagAction < ActionFilter
|
||||
def initialize(action, outcome, tag, comment, tags=nil, descs=nil)
|
||||
def initialize(action, outcome, tag, comment, tags = nil, descs = nil)
|
||||
super tags, descs
|
||||
@action = action
|
||||
@outcome = outcome
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'mspec/runner/actions/filter'
|
|||
# tagged with +tags+. If +tags+ is an empty list, prints out
|
||||
# descriptions for any specs that are tagged.
|
||||
class TagListAction
|
||||
def initialize(tags=nil)
|
||||
def initialize(tags = nil)
|
||||
@tags = tags.nil? || tags.empty? ? nil : Array(tags)
|
||||
@filter = nil
|
||||
end
|
||||
|
|
|
@ -5,31 +5,31 @@ class Tally
|
|||
@files = @examples = @expectations = @failures = @errors = @guards = @tagged = 0
|
||||
end
|
||||
|
||||
def files!(add=1)
|
||||
def files!(add = 1)
|
||||
@files += add
|
||||
end
|
||||
|
||||
def examples!(add=1)
|
||||
def examples!(add = 1)
|
||||
@examples += add
|
||||
end
|
||||
|
||||
def expectations!(add=1)
|
||||
def expectations!(add = 1)
|
||||
@expectations += add
|
||||
end
|
||||
|
||||
def failures!(add=1)
|
||||
def failures!(add = 1)
|
||||
@failures += add
|
||||
end
|
||||
|
||||
def errors!(add=1)
|
||||
def errors!(add = 1)
|
||||
@errors += add
|
||||
end
|
||||
|
||||
def guards!(add=1)
|
||||
def guards!(add = 1)
|
||||
@guards += add
|
||||
end
|
||||
|
||||
def tagged!(add=1)
|
||||
def tagged!(add = 1)
|
||||
@tagged += add
|
||||
end
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class TimeoutAction
|
|||
end
|
||||
end
|
||||
|
||||
def before(state=nil)
|
||||
def before(state = nil)
|
||||
time = now
|
||||
@queue << -> do
|
||||
@current_state = state
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
class ContextState
|
||||
attr_reader :state, :parent, :parents, :children, :examples, :to_s
|
||||
|
||||
def initialize(mod, options=nil)
|
||||
def initialize(mod, options = nil)
|
||||
@to_s = mod.to_s
|
||||
if options.is_a? Hash
|
||||
@options = options
|
||||
|
@ -174,7 +174,7 @@ class ContextState
|
|||
# so that exceptions are handled and tallied. Returns true and does
|
||||
# NOT evaluate any blocks if +check+ is true and
|
||||
# <tt>MSpec.mode?(:pretend)</tt> is true.
|
||||
def protect(what, blocks, check=true)
|
||||
def protect(what, blocks, check = true)
|
||||
return true if check and MSpec.mode? :pretend
|
||||
Array(blocks).all? { |block| MSpec.protect what, &block }
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ class SpecEvaluate
|
|||
# single quotes to set if off from the rest of the description string. If
|
||||
# the source does contain newline characters, sets the indent level to four
|
||||
# characters.
|
||||
def format(ruby, newline=true)
|
||||
def format(ruby, newline = true)
|
||||
if ruby.include?("\n")
|
||||
lines = ruby.each_line.to_a
|
||||
if /( *)/ =~ lines.first
|
||||
|
@ -49,6 +49,6 @@ class SpecEvaluate
|
|||
end
|
||||
end
|
||||
|
||||
def evaluate(str, desc=nil, &block)
|
||||
def evaluate(str, desc = nil, &block)
|
||||
SpecEvaluate.new(str, desc).define(&block)
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'mspec/runner/mspec'
|
|||
class ExampleState
|
||||
attr_reader :context, :it, :example
|
||||
|
||||
def initialize(context, it, example=nil)
|
||||
def initialize(context, it, example = nil)
|
||||
@context = context
|
||||
@it = it
|
||||
@example = example
|
||||
|
|
128
spec/mspec/lib/mspec/runner/formatters/base.rb
Normal file
128
spec/mspec/lib/mspec/runner/formatters/base.rb
Normal file
|
@ -0,0 +1,128 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/actions/timer'
|
||||
require 'mspec/runner/actions/tally'
|
||||
|
||||
if ENV['CHECK_LEAKS']
|
||||
require 'mspec/runner/actions/leakchecker'
|
||||
require 'mspec/runner/actions/constants_leak_checker'
|
||||
end
|
||||
|
||||
class BaseFormatter
|
||||
attr_reader :exceptions, :timer, :tally
|
||||
|
||||
def initialize(out = nil)
|
||||
@current_state = nil
|
||||
@exception = false
|
||||
@failure = false
|
||||
@exceptions = []
|
||||
|
||||
@count = 0 # For subclasses
|
||||
|
||||
if out.nil?
|
||||
@out = $stdout
|
||||
else
|
||||
@out = File.open out, "w"
|
||||
end
|
||||
end
|
||||
|
||||
# Creates the +TimerAction+ and +TallyAction+ instances and registers them.
|
||||
def register
|
||||
(@timer = TimerAction.new).register
|
||||
(@tally = TallyAction.new).register
|
||||
@counter = @tally.counter
|
||||
|
||||
if ENV['CHECK_LEAKS']
|
||||
save = ENV['CHECK_LEAKS'] == 'save'
|
||||
LeakCheckerAction.new.register
|
||||
ConstantsLeakCheckerAction.new(save).register
|
||||
end
|
||||
|
||||
MSpec.register :abort, self
|
||||
MSpec.register :before, self
|
||||
MSpec.register :after, self
|
||||
MSpec.register :exception, self
|
||||
MSpec.register :finish, self
|
||||
end
|
||||
|
||||
def abort
|
||||
if @current_state
|
||||
puts "\naborting example: #{@current_state.description}"
|
||||
end
|
||||
end
|
||||
|
||||
# Returns true if any exception is raised while running
|
||||
# an example. This flag is reset before each example
|
||||
# is evaluated.
|
||||
def exception?
|
||||
@exception
|
||||
end
|
||||
|
||||
# Returns true if all exceptions during the evaluation
|
||||
# of an example are failures rather than errors. See
|
||||
# <tt>ExceptionState#failure</tt>. This flag is reset
|
||||
# before each example is evaluated.
|
||||
def failure?
|
||||
@failure
|
||||
end
|
||||
|
||||
# Callback for the MSpec :before event. Resets the
|
||||
# +#exception?+ and +#failure+ flags.
|
||||
def before(state = nil)
|
||||
@current_state = state
|
||||
@failure = @exception = false
|
||||
end
|
||||
|
||||
# Callback for the MSpec :exception event. Stores the
|
||||
# +ExceptionState+ object to generate the list of backtraces
|
||||
# after all the specs are run. Also updates the internal
|
||||
# +#exception?+ and +#failure?+ flags.
|
||||
def exception(exception)
|
||||
@count += 1
|
||||
@failure = @exception ? @failure && exception.failure? : exception.failure?
|
||||
@exception = true
|
||||
@exceptions << exception
|
||||
end
|
||||
|
||||
# Callback for the MSpec :after event.
|
||||
def after(state = nil)
|
||||
@current_state = nil
|
||||
end
|
||||
|
||||
# Callback for the MSpec :start event. Calls :after event.
|
||||
# Defined here, in the base class, and used by MultiFormatter.
|
||||
def start
|
||||
after
|
||||
end
|
||||
|
||||
# Callback for the MSpec :unload event. Calls :after event.
|
||||
# Defined here, in the base class, and used by MultiFormatter.
|
||||
def unload
|
||||
after
|
||||
end
|
||||
|
||||
# Callback for the MSpec :finish event. Prints a description
|
||||
# and backtrace for every exception that occurred while
|
||||
# evaluating the examples.
|
||||
def finish
|
||||
print "\n"
|
||||
count = 0
|
||||
@exceptions.each do |exc|
|
||||
count += 1
|
||||
print_exception(exc, count)
|
||||
end
|
||||
print "\n#{@timer.format}\n\n#{@tally.format}\n"
|
||||
end
|
||||
|
||||
def print_exception(exc, count)
|
||||
outcome = exc.failure? ? "FAILED" : "ERROR"
|
||||
print "\n#{count})\n#{exc.description} #{outcome}\n"
|
||||
print exc.message, "\n"
|
||||
print exc.backtrace, "\n"
|
||||
end
|
||||
|
||||
# A convenience method to allow printing to different outputs.
|
||||
def print(*args)
|
||||
@out.print(*args)
|
||||
@out.flush
|
||||
end
|
||||
end
|
|
@ -1,5 +1,4 @@
|
|||
require 'mspec/runner/formatters/dotted'
|
||||
require 'mspec/runner/actions/tally'
|
||||
|
||||
class DescribeFormatter < DottedFormatter
|
||||
# Callback for the MSpec :finish event. Prints a summary of
|
||||
|
|
|
@ -1,85 +1,9 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/actions/timer'
|
||||
require 'mspec/runner/actions/tally'
|
||||
require 'mspec/runner/formatters/base'
|
||||
|
||||
if ENV['CHECK_LEAKS']
|
||||
require 'mspec/runner/actions/leakchecker'
|
||||
require 'mspec/runner/actions/constants_leak_checker'
|
||||
end
|
||||
|
||||
class DottedFormatter
|
||||
attr_reader :exceptions, :timer, :tally
|
||||
|
||||
def initialize(out=nil)
|
||||
@exception = @failure = false
|
||||
@exceptions = []
|
||||
@count = 0 # For subclasses
|
||||
if out.nil?
|
||||
@out = $stdout
|
||||
else
|
||||
@out = File.open out, "w"
|
||||
end
|
||||
|
||||
@current_state = nil
|
||||
end
|
||||
|
||||
# Creates the +TimerAction+ and +TallyAction+ instances and
|
||||
# registers them. Registers +self+ for the +:exception+,
|
||||
# +:before+, +:after+, and +:finish+ actions.
|
||||
class DottedFormatter < BaseFormatter
|
||||
def register
|
||||
(@timer = TimerAction.new).register
|
||||
(@tally = TallyAction.new).register
|
||||
if ENV['CHECK_LEAKS']
|
||||
save = ENV['CHECK_LEAKS'] == 'save'
|
||||
LeakCheckerAction.new.register
|
||||
ConstantsLeakCheckerAction.new(save).register
|
||||
end
|
||||
@counter = @tally.counter
|
||||
|
||||
MSpec.register :exception, self
|
||||
MSpec.register :before, self
|
||||
MSpec.register :after, self
|
||||
MSpec.register :finish, self
|
||||
MSpec.register :abort, self
|
||||
end
|
||||
|
||||
def abort
|
||||
if @current_state
|
||||
puts "\naborting example: #{@current_state.description}"
|
||||
end
|
||||
end
|
||||
|
||||
# Returns true if any exception is raised while running
|
||||
# an example. This flag is reset before each example
|
||||
# is evaluated.
|
||||
def exception?
|
||||
@exception
|
||||
end
|
||||
|
||||
# Returns true if all exceptions during the evaluation
|
||||
# of an example are failures rather than errors. See
|
||||
# <tt>ExceptionState#failure</tt>. This flag is reset
|
||||
# before each example is evaluated.
|
||||
def failure?
|
||||
@failure
|
||||
end
|
||||
|
||||
# Callback for the MSpec :before event. Resets the
|
||||
# +#exception?+ and +#failure+ flags.
|
||||
def before(state=nil)
|
||||
@current_state = state
|
||||
@failure = @exception = false
|
||||
end
|
||||
|
||||
# Callback for the MSpec :exception event. Stores the
|
||||
# +ExceptionState+ object to generate the list of backtraces
|
||||
# after all the specs are run. Also updates the internal
|
||||
# +#exception?+ and +#failure?+ flags.
|
||||
def exception(exception)
|
||||
@count += 1
|
||||
@failure = @exception ? @failure && exception.failure? : exception.failure?
|
||||
@exception = true
|
||||
@exceptions << exception
|
||||
super
|
||||
MSpec.register :after, self
|
||||
end
|
||||
|
||||
# Callback for the MSpec :after event. Prints an indicator
|
||||
|
@ -88,48 +12,12 @@ class DottedFormatter
|
|||
# F = An SpecExpectationNotMetError was raised
|
||||
# E = Any exception other than SpecExpectationNotMetError
|
||||
def after(state = nil)
|
||||
@current_state = nil
|
||||
super(state)
|
||||
|
||||
unless exception?
|
||||
print "."
|
||||
else
|
||||
if exception?
|
||||
print failure? ? "F" : "E"
|
||||
else
|
||||
print "."
|
||||
end
|
||||
end
|
||||
|
||||
# Callback for the MSpec :start event. Calls :after event.
|
||||
def start
|
||||
after
|
||||
end
|
||||
|
||||
# Callback for the MSpec :unload event. Calls :after event.
|
||||
def unload
|
||||
after
|
||||
end
|
||||
|
||||
# Callback for the MSpec :finish event. Prints a description
|
||||
# and backtrace for every exception that occurred while
|
||||
# evaluating the examples.
|
||||
def finish
|
||||
print "\n"
|
||||
count = 0
|
||||
@exceptions.each do |exc|
|
||||
count += 1
|
||||
print_exception(exc, count)
|
||||
end
|
||||
print "\n#{@timer.format}\n\n#{@tally.format}\n"
|
||||
end
|
||||
|
||||
def print_exception(exc, count)
|
||||
outcome = exc.failure? ? "FAILED" : "ERROR"
|
||||
print "\n#{count})\n#{exc.description} #{outcome}\n"
|
||||
print exc.message, "\n"
|
||||
print exc.backtrace, "\n"
|
||||
end
|
||||
|
||||
# A convenience method to allow printing to different outputs.
|
||||
def print(*args)
|
||||
@out.print(*args)
|
||||
@out.flush
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,11 @@ class FileFormatter < DottedFormatter
|
|||
MSpec.register :unload, self
|
||||
end
|
||||
|
||||
alias_method :load, :before
|
||||
alias_method :unload, :after
|
||||
def load(state = nil)
|
||||
before(state)
|
||||
end
|
||||
|
||||
def unload(state = nil)
|
||||
after(state)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/formatters/dotted'
|
||||
require 'mspec/runner/formatters/base'
|
||||
|
||||
class HtmlFormatter < DottedFormatter
|
||||
class HtmlFormatter < BaseFormatter
|
||||
def register
|
||||
super
|
||||
MSpec.register :start, self
|
||||
|
@ -44,13 +43,14 @@ EOH
|
|||
end
|
||||
|
||||
def exception(exception)
|
||||
super
|
||||
super(exception)
|
||||
outcome = exception.failure? ? "FAILED" : "ERROR"
|
||||
print %[<li class="fail">- #{exception.it} (<a href="#details-#{@count}">]
|
||||
print %[#{outcome} - #{@count}</a>)</li>\n]
|
||||
end
|
||||
|
||||
def after(state = nil)
|
||||
super(state)
|
||||
print %[<li class="pass">- #{state.it}</li>\n] unless exception?
|
||||
end
|
||||
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/formatters/yaml'
|
||||
|
||||
class JUnitFormatter < YamlFormatter
|
||||
def initialize(out=nil)
|
||||
super
|
||||
def initialize(out = nil)
|
||||
super(out)
|
||||
@tests = []
|
||||
end
|
||||
|
||||
def after(state = nil)
|
||||
super
|
||||
super(state)
|
||||
@tests << {:test => state, :exception => false} unless exception?
|
||||
end
|
||||
|
||||
def exception(exception)
|
||||
super
|
||||
super(exception)
|
||||
@tests << {:test => exception, :exception => true}
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'mspec/runner/formatters/dotted'
|
||||
require 'mspec/runner/formatters/base'
|
||||
|
||||
class MethodFormatter < DottedFormatter
|
||||
class MethodFormatter < BaseFormatter
|
||||
attr_accessor :methods
|
||||
|
||||
def initialize(out=nil)
|
||||
super
|
||||
def initialize(out = nil)
|
||||
super(out)
|
||||
@methods = Hash.new do |h, k|
|
||||
hash = {}
|
||||
hash[:examples] = 0
|
||||
|
@ -34,7 +34,7 @@ class MethodFormatter < DottedFormatter
|
|||
# Resets the tallies so the counts are only for this
|
||||
# example.
|
||||
def before(state)
|
||||
super
|
||||
super(state)
|
||||
|
||||
# The pattern for a method name is not correctly
|
||||
# restrictive but it is simplistic and useful
|
||||
|
@ -61,6 +61,8 @@ class MethodFormatter < DottedFormatter
|
|||
# Callback for the MSpec :after event. Sets or adds to
|
||||
# tallies for the example block.
|
||||
def after(state = nil)
|
||||
super(state)
|
||||
|
||||
h = methods[@key]
|
||||
h[:examples] += tally.counter.examples
|
||||
h[:expectations] += tally.counter.expectations
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/formatters/dotted'
|
||||
require 'mspec/runner/actions/profile'
|
||||
|
||||
class ProfileFormatter < DottedFormatter
|
||||
def initialize(out=nil)
|
||||
super
|
||||
def initialize(out = nil)
|
||||
super(out)
|
||||
|
||||
@describe_name = nil
|
||||
@describe_time = nil
|
||||
|
@ -12,59 +12,7 @@ class ProfileFormatter < DottedFormatter
|
|||
end
|
||||
|
||||
def register
|
||||
super
|
||||
MSpec.register :enter, self
|
||||
end
|
||||
|
||||
# Callback for the MSpec :enter event. Prints the
|
||||
# +describe+ block string.
|
||||
def enter(describe)
|
||||
if @describe_time
|
||||
@describes << [@describe_name, Time.now.to_f - @describe_time]
|
||||
end
|
||||
|
||||
@describe_name = describe
|
||||
@describe_time = Time.now.to_f
|
||||
end
|
||||
|
||||
# Callback for the MSpec :before event. Prints the
|
||||
# +it+ block string.
|
||||
def before(state)
|
||||
super
|
||||
|
||||
@it_name = state.it
|
||||
@it_time = Time.now.to_f
|
||||
end
|
||||
|
||||
# Callback for the MSpec :after event. Prints a
|
||||
# newline to finish the description string output.
|
||||
def after(state = nil)
|
||||
@its << [@describe_name, @it_name, Time.now.to_f - @it_time]
|
||||
super
|
||||
end
|
||||
|
||||
def finish
|
||||
puts "\nProfiling info:"
|
||||
|
||||
desc = @describes.sort { |a,b| b.last <=> a.last }
|
||||
desc.delete_if { |a| a.last <= 0.001 }
|
||||
show = desc[0, 100]
|
||||
|
||||
puts "Top #{show.size} describes:"
|
||||
|
||||
show.each do |des, time|
|
||||
printf "%3.3f - %s\n", time, des
|
||||
end
|
||||
|
||||
its = @its.sort { |a,b| b.last <=> a.last }
|
||||
its.delete_if { |a| a.last <= 0.001 }
|
||||
show = its[0, 100]
|
||||
|
||||
puts "\nTop #{show.size} its:"
|
||||
show.each do |des, it, time|
|
||||
printf "%3.3f - %s %s\n", time, des, it
|
||||
end
|
||||
|
||||
(@profile = ProfileAction.new).register
|
||||
super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/formatters/dotted'
|
||||
require 'mspec/runner/formatters/base'
|
||||
|
||||
class SpecdocFormatter < DottedFormatter
|
||||
class SpecdocFormatter < BaseFormatter
|
||||
def register
|
||||
super
|
||||
MSpec.register :enter, self
|
||||
|
@ -16,7 +15,7 @@ class SpecdocFormatter < DottedFormatter
|
|||
# Callback for the MSpec :before event. Prints the
|
||||
# +it+ block string.
|
||||
def before(state)
|
||||
super
|
||||
super(state)
|
||||
print "- #{state.it}"
|
||||
end
|
||||
|
||||
|
@ -29,13 +28,14 @@ class SpecdocFormatter < DottedFormatter
|
|||
# string has an associated 'ERROR' or 'FAILED'
|
||||
def exception(exception)
|
||||
print "\n- #{exception.it}" if exception?
|
||||
super
|
||||
super(exception)
|
||||
print " (#{exception.failure? ? 'FAILED' : 'ERROR'} - #{@count})"
|
||||
end
|
||||
|
||||
# Callback for the MSpec :after event. Prints a
|
||||
# newline to finish the description string output.
|
||||
def after(state = nil)
|
||||
super(state)
|
||||
print "\n"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/formatters/dotted'
|
||||
require 'mspec/runner/formatters/base'
|
||||
|
||||
class SpinnerFormatter < DottedFormatter
|
||||
class SpinnerFormatter < BaseFormatter
|
||||
attr_reader :length
|
||||
|
||||
Spins = %w!| / - \\!
|
||||
HOUR = 3600
|
||||
MIN = 60
|
||||
|
||||
def initialize(out=nil)
|
||||
def initialize(out = nil)
|
||||
super(nil)
|
||||
|
||||
@which = 0
|
||||
|
@ -28,7 +27,6 @@ class SpinnerFormatter < DottedFormatter
|
|||
|
||||
MSpec.register :start, self
|
||||
MSpec.register :unload, self
|
||||
MSpec.unregister :before, self
|
||||
end
|
||||
|
||||
def length=(length)
|
||||
|
@ -107,6 +105,7 @@ class SpinnerFormatter < DottedFormatter
|
|||
|
||||
# Callback for the MSpec :after event. Updates the spinner.
|
||||
def after(state = nil)
|
||||
super(state)
|
||||
print progress_line
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/formatters/dotted'
|
||||
require 'mspec/runner/formatters/base'
|
||||
|
||||
class SummaryFormatter < DottedFormatter
|
||||
# Callback for the MSpec :after event. Overrides the
|
||||
# callback provided by +DottedFormatter+ and does not
|
||||
# print any output for each example evaluated.
|
||||
def after(state = nil)
|
||||
# do nothing
|
||||
end
|
||||
class SummaryFormatter < BaseFormatter
|
||||
end
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/formatters/dotted'
|
||||
|
||||
class UnitdiffFormatter < DottedFormatter
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/runner/formatters/dotted'
|
||||
require 'mspec/runner/formatters/base'
|
||||
|
||||
class YamlFormatter < DottedFormatter
|
||||
def initialize(out=nil)
|
||||
class YamlFormatter < BaseFormatter
|
||||
def initialize(out = nil)
|
||||
super(nil)
|
||||
|
||||
if out.nil?
|
||||
|
@ -16,9 +15,6 @@ class YamlFormatter < DottedFormatter
|
|||
@out = @finish
|
||||
end
|
||||
|
||||
def after(state = nil)
|
||||
end
|
||||
|
||||
def finish
|
||||
switch
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ module MSpec
|
|||
@expectation = nil
|
||||
@expectations = false
|
||||
|
||||
def self.describe(mod, options=nil, &block)
|
||||
def self.describe(mod, options = nil, &block)
|
||||
state = ContextState.new mod, options
|
||||
state.parent = current
|
||||
|
||||
|
@ -259,7 +259,7 @@ module MSpec
|
|||
end
|
||||
end
|
||||
|
||||
def self.randomize(flag=true)
|
||||
def self.randomize(flag = true)
|
||||
@randomize = flag
|
||||
end
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
class Object
|
||||
private def before(at=:each, &block)
|
||||
private def before(at = :each, &block)
|
||||
MSpec.current.before at, &block
|
||||
end
|
||||
|
||||
private def after(at=:each, &block)
|
||||
private def after(at = :each, &block)
|
||||
MSpec.current.after at, &block
|
||||
end
|
||||
|
||||
private def describe(mod, msg=nil, options=nil, &block)
|
||||
private def describe(mod, msg = nil, options = nil, &block)
|
||||
MSpec.describe mod, msg, &block
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'mspec/runner/mspec'
|
||||
|
||||
def it_behaves_like(desc, meth, obj=nil)
|
||||
def it_behaves_like(desc, meth, obj = nil)
|
||||
send :before, :all do
|
||||
@method = meth
|
||||
@object = obj
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class SpecTag
|
||||
attr_accessor :tag, :comment, :description
|
||||
|
||||
def initialize(string=nil)
|
||||
def initialize(string = nil)
|
||||
parse(string) if string
|
||||
end
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class NameMap
|
|||
SpecVersion
|
||||
]
|
||||
|
||||
def initialize(filter=false)
|
||||
def initialize(filter = false)
|
||||
@seen = {}
|
||||
@filter = filter
|
||||
end
|
||||
|
@ -73,7 +73,7 @@ class NameMap
|
|||
"#{mod}::#{const}"
|
||||
end
|
||||
|
||||
def map(hash, constants, mod=nil)
|
||||
def map(hash, constants, mod = nil)
|
||||
@seen = {} unless mod
|
||||
|
||||
constants.each do |const|
|
||||
|
|
|
@ -34,7 +34,7 @@ class MSpecOptions
|
|||
|
||||
attr_accessor :config, :banner, :width, :options
|
||||
|
||||
def initialize(banner="", width=30, config=nil)
|
||||
def initialize(banner = "", width = 30, config = nil)
|
||||
@banner = banner
|
||||
@config = config
|
||||
@width = width
|
||||
|
@ -123,7 +123,7 @@ class MSpecOptions
|
|||
|
||||
# Parses an array of command line entries, calling blocks for
|
||||
# registered options.
|
||||
def parse(argv=ARGV)
|
||||
def parse(argv = ARGV)
|
||||
argv = Array(argv).dup
|
||||
|
||||
while entry = argv.shift
|
||||
|
|
|
@ -149,7 +149,10 @@ class MSpecScript
|
|||
if config[:formatter].nil?
|
||||
config[:formatter] = STDOUT.tty? ? SpinnerFormatter : @files.size < 50 ? DottedFormatter : FileFormatter
|
||||
end
|
||||
config[:formatter].new(config[:output])
|
||||
|
||||
if config[:formatter]
|
||||
config[:formatter].new(config[:output])
|
||||
end
|
||||
end
|
||||
|
||||
# Callback for enabling custom actions, etc. This version is a
|
||||
|
|
|
@ -37,8 +37,14 @@ EOS
|
|||
ret.success?.should == false
|
||||
end
|
||||
|
||||
it "runs the specs in parallel with -j" do
|
||||
it "runs the specs in parallel with -j using the dotted formatter" do
|
||||
out, ret = run_mspec("run", "-j #{fixtures}/a_spec.rb #{fixtures}/b_spec.rb")
|
||||
out.should == "RUBY_DESCRIPTION\n...\n#{a_spec_output}\n#{ab_stats}"
|
||||
ret.success?.should == false
|
||||
end
|
||||
|
||||
it "runs the specs in parallel with -j -fa" do
|
||||
out, ret = run_mspec("run", "-j -fa #{fixtures}/a_spec.rb #{fixtures}/b_spec.rb")
|
||||
progress_bar =
|
||||
"\r[/ | 0% | 00:00:00] \e[0;32m 0F \e[0;32m 0E\e[0m " +
|
||||
"\r[- | ==================50% | 00:00:00] \e[0;32m 0F \e[0;32m 0E\e[0m " +
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
require 'mspec/runner/formatters/dotted'
|
||||
require 'mspec/runner/formatters/multi'
|
||||
require 'mspec/runner/example'
|
||||
require 'yaml'
|
||||
|
||||
describe MultiFormatter, "#aggregate_results" do
|
||||
before :each do
|
||||
|
@ -14,7 +16,7 @@ describe MultiFormatter, "#aggregate_results" do
|
|||
@hash = { "files"=>1, "examples"=>1, "expectations"=>2, "failures"=>0, "errors"=>0 }
|
||||
YAML.stub(:load).and_return(@hash)
|
||||
|
||||
@formatter = MultiFormatter.new
|
||||
@formatter = DottedFormatter.new.extend(MultiFormatter)
|
||||
@formatter.timer.stub(:format).and_return("Finished in 42 seconds")
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue