spec/mspec-opal/formatters.rb in opal-0.10.6 vs spec/mspec-opal/formatters.rb in opal-0.11.0.rc1

- old
+ new

@@ -1,6 +1,6 @@ -class BrowserFormatter +class BaseOpalFormatter def initialize(out=nil) @exception = @failure = false @exceptions = [] @count = 0 @examples = 0 @@ -16,16 +16,20 @@ MSpec.register :finish, self MSpec.register :abort, self MSpec.register :enter, self end + def red(str) + `console.error(str)` + end + def green(str) `console.info(str)` end - def red(str) - `console.error(str)` + def cyan(str) + `console.info(str)` end def log(str) `console.log(str)` end @@ -64,11 +68,11 @@ def finish time = Time.now.to_f - @start_time if @exceptions.empty? log "\nFinished" - green "#{@examples} examples, #{@count} failures (time taken: #{time})" + green "#{@examples} examples, #{@count} failures (time taken: #{time})\n" finish_with_code 0 else log "\nFailures:" @@ -79,28 +83,62 @@ end log "\nFinished" red "#{@examples} examples, #{@count} failures (time taken: #{time})" + log "\n\nFilters for failed examples:\n\n" + @exceptions.map do |exception| + ["#{exception.describe} #{exception.it}", exception.message.tr("\n", " ")] + end.sort.each do |(description, message)| + red "fails #{description.inspect}" + cyan " # #{message}\n" + end + log "\n" + finish_with_code(1) end end def finish_with_code(code) exit(code) end end -class PhantomFormatter < BrowserFormatter - def green(str) - `console.log('\u001b[32m' + str + '\u001b[0m')` +class BrowserFormatter < BaseOpalFormatter + def initialize(*args, &block) + $passed = 0 + $failed = 0 + $errored = 0 + super end + def print_example(state) + unless exception? + $passed += 1 + else + if failure? + $failed += 1 + else + $errored += 1 + end + end + end +end + +class PhantomFormatter < BaseOpalFormatter def red(str) `console.log('\u001b[31m' + str + '\u001b[0m')` end + def green(str) + `console.log('\u001b[32m' + str + '\u001b[0m')` + end + + def cyan(str) + `console.log('\u001b[36m' + str + '\u001b[0m')` + end + def log(str) `console.log(str)` end def after(state) @@ -111,19 +149,28 @@ print failure? ? 'F' : 'E' end end end -class NodeJSFormatter < BrowserFormatter - def green(str) - `process.stdout.write("\u001b[32m"+#{str}+"\u001b[0m")` +class NodeJSFormatter < BaseOpalFormatter + def initialize(*args, &block) + require 'nodejs/stacktrace' + super end def red(str) `process.stdout.write("\u001b[31m"+#{str}+"\u001b[0m")` end + def green(str) + `process.stdout.write("\u001b[32m"+#{str}+"\u001b[0m")` + end + + def cyan(str) + `process.stdout.write("\u001b[36m"+#{str}+"\u001b[0m")` + end + def log(str) puts str end def after(state) @@ -150,16 +197,20 @@ super end end class NodeJSDocFormatter < NodeJSFormatter + def before(example) + print example.description + end + def print_example(state) - (@exception && state) ? red(state.description+"\n") : green(state.description+"\n") + (@exception && state) ? red(" ✗\n") : green(" ✓\n") end end -class InvertedFormatter < DottedFormatter +module InvertedFormatter def initialize(out=nil) super @actually_passing = [] end @@ -169,18 +220,15 @@ MSpec.register :after, self MSpec.register :finish, self end def after(state=nil) - unless exception? - @actually_passing << @current_state - end - + @actually_passing << @current_state unless exception? super end def finish - puts "\n\nExpected to fail:\n" + puts "\n\nExpected #{@actually_passing.size} examples to fail:\n" @actually_passing.each_with_index do |example, idx| puts " #{idx + 1}) #{example.description.inspect}" end puts "\n" end