Class: DottedFormatter
- Defined in:
- lib/extensions/mspec/mspec/runner/formatters/dotted.rb
Direct Known Subclasses
DescribeFormatter, FileFormatter, HtmlFormatter, JasmineLikeFormatter, MethodFormatter, ProfileFormatter, SpecdocFormatter, SpinnerFormatter, SummaryFormatter, UnitdiffFormatter, YamlFormatter
Instance Attribute Summary collapse
-
#exceptions ⇒ Object
readonly
Returns the value of attribute exceptions.
-
#tally ⇒ Object
readonly
Returns the value of attribute tally.
-
#timer ⇒ Object
readonly
Returns the value of attribute timer.
Instance Method Summary collapse
- #abort ⇒ Object
-
#after(state = nil) ⇒ Object
Callback for the MSpec :after event.
-
#before(state = nil) ⇒ Object
Callback for the MSpec :before event.
-
#exception(exception) ⇒ Object
Callback for the MSpec :exception event.
-
#exception? ⇒ Boolean
Returns true if any exception is raised while running an example.
-
#failure? ⇒ Boolean
Returns true if all exceptions during the evaluation of an example are failures rather than errors.
-
#finish ⇒ Object
Callback for the MSpec :finish event.
-
#initialize(out = nil) ⇒ DottedFormatter
constructor
A new instance of DottedFormatter.
-
#print(*args) ⇒ Object
A convenience method to allow printing to different outputs.
- #print_exception(exc, count) ⇒ Object
-
#register ⇒ Object
Creates the
TimerActionandTallyActioninstances and registers them.
Constructor Details
#initialize(out = nil) ⇒ DottedFormatter
Returns a new instance of DottedFormatter.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 9 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 |
Instance Attribute Details
#exceptions ⇒ Object (readonly)
Returns the value of attribute exceptions.
7 8 9 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 7 def exceptions @exceptions end |
#tally ⇒ Object (readonly)
Returns the value of attribute tally.
7 8 9 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 7 def tally @tally end |
#timer ⇒ Object (readonly)
Returns the value of attribute timer.
7 8 9 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 7 def timer @timer end |
Instance Method Details
#abort ⇒ Object
38 39 40 41 42 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 38 def abort if @current_state puts "\naborting example: #{@current_state.description}" end end |
#after(state = nil) ⇒ Object
Callback for the MSpec :after event. Prints an indicator for the result of evaluating this example as follows:
. = No failure or error
F = An SpecExpectationNotMetError was raised
E = Any exception other than SpecExpectationNotMetError
82 83 84 85 86 87 88 89 90 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 82 def after(state = nil) @current_state = nil unless exception? print "." else print failure? ? "F" : "E" end end |
#before(state = nil) ⇒ Object
Callback for the MSpec :before event. Resets the #exception? and #failure flags.
61 62 63 64 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 61 def before(state=nil) @current_state = state @failure = @exception = false end |
#exception(exception) ⇒ Object
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.
70 71 72 73 74 75 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 70 def exception(exception) @count += 1 @failure = @exception ? @failure && exception.failure? : exception.failure? @exception = true @exceptions << exception end |
#exception? ⇒ Boolean
Returns true if any exception is raised while running an example. This flag is reset before each example is evaluated.
47 48 49 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 47 def exception? @exception end |
#failure? ⇒ Boolean
Returns true if all exceptions during the evaluation of an example are failures rather than errors. See ExceptionState#failure. This flag is reset before each example is evaluated.
55 56 57 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 55 def failure? @failure end |
#finish ⇒ Object
Callback for the MSpec :finish event. Prints a description and backtrace for every exception that occurred while evaluating the examples.
95 96 97 98 99 100 101 102 103 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 95 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 |
#print(*args) ⇒ Object
A convenience method to allow printing to different outputs.
113 114 115 116 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 113 def print(*args) @out.print(*args) @out.flush end |
#print_exception(exc, count) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 105 def print_exception(exc, count) outcome = exc.failure? ? "FAILED" : "ERROR" print "\n#{count})\n#{exc.description} #{outcome}\n" print exc., "\n" print exc.backtrace, "\n" end |
#register ⇒ Object
Creates the TimerAction and TallyAction instances and registers them. Registers self for the :exception, :before, :after, and :finish actions.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/extensions/mspec/mspec/runner/formatters/dotted.rb', line 25 def register (@timer = TimerAction.new).register (@tally = TallyAction.new).register LeakCheckerAction.new.register if ENV['CHECK_LEAKS'] @counter = @tally.counter MSpec.register :exception, self MSpec.register :before, self MSpec.register :after, self MSpec.register :finish, self MSpec.register :abort, self end |