aboutsummaryrefslogtreecommitdiffstats
path: root/spec/mspec/lib/mspec/runner/formatters
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mspec/lib/mspec/runner/formatters')
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/base.rb128
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/describe.rb1
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/dotted.rb128
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/file.rb9
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/html.rb8
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/junit.rb9
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/method.rb12
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/profile.rb60
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/specdoc.rb10
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/spinner.rb9
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/summary.rb11
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/unit.rb1
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/yaml.rb10
13 files changed, 176 insertions, 220 deletions
diff --git a/spec/mspec/lib/mspec/runner/formatters/base.rb b/spec/mspec/lib/mspec/runner/formatters/base.rb
new file mode 100644
index 0000000000..6c075c4d0a
--- /dev/null
+++ b/spec/mspec/lib/mspec/runner/formatters/base.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/describe.rb b/spec/mspec/lib/mspec/runner/formatters/describe.rb
index 176bd79279..fc4122d13b 100644
--- a/spec/mspec/lib/mspec/runner/formatters/describe.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/describe.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/dotted.rb b/spec/mspec/lib/mspec/runner/formatters/dotted.rb
index 7e30a22e8d..672cdf81dc 100644
--- a/spec/mspec/lib/mspec/runner/formatters/dotted.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/dotted.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/file.rb b/spec/mspec/lib/mspec/runner/formatters/file.rb
index 6db72af4ff..65cfb1f75b 100644
--- a/spec/mspec/lib/mspec/runner/formatters/file.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/file.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/html.rb b/spec/mspec/lib/mspec/runner/formatters/html.rb
index f79c7161f9..e37e89a088 100644
--- a/spec/mspec/lib/mspec/runner/formatters/html.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/html.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/junit.rb b/spec/mspec/lib/mspec/runner/formatters/junit.rb
index 76d46c2414..12e43a3263 100644
--- a/spec/mspec/lib/mspec/runner/formatters/junit.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/junit.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/method.rb b/spec/mspec/lib/mspec/runner/formatters/method.rb
index 8a460665ff..8fe02575c4 100644
--- a/spec/mspec/lib/mspec/runner/formatters/method.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/method.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/profile.rb b/spec/mspec/lib/mspec/runner/formatters/profile.rb
index 6d15a56349..38ef5b12ed 100644
--- a/spec/mspec/lib/mspec/runner/formatters/profile.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/profile.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/specdoc.rb b/spec/mspec/lib/mspec/runner/formatters/specdoc.rb
index 06ac7702df..35092018f6 100644
--- a/spec/mspec/lib/mspec/runner/formatters/specdoc.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/specdoc.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/spinner.rb b/spec/mspec/lib/mspec/runner/formatters/spinner.rb
index f9101aece3..8815e1a48a 100644
--- a/spec/mspec/lib/mspec/runner/formatters/spinner.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/spinner.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/summary.rb b/spec/mspec/lib/mspec/runner/formatters/summary.rb
index 2dfa751b57..41819d2158 100644
--- a/spec/mspec/lib/mspec/runner/formatters/summary.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/summary.rb
@@ -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
diff --git a/spec/mspec/lib/mspec/runner/formatters/unit.rb b/spec/mspec/lib/mspec/runner/formatters/unit.rb
index cebc18a49b..d03ae79e9f 100644
--- a/spec/mspec/lib/mspec/runner/formatters/unit.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/unit.rb
@@ -1,4 +1,3 @@
-require 'mspec/expectations/expectations'
require 'mspec/runner/formatters/dotted'
class UnitdiffFormatter < DottedFormatter
diff --git a/spec/mspec/lib/mspec/runner/formatters/yaml.rb b/spec/mspec/lib/mspec/runner/formatters/yaml.rb
index bb98f7931e..6c05cc902f 100644
--- a/spec/mspec/lib/mspec/runner/formatters/yaml.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/yaml.rb
@@ -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