Class: Merb::Counter
Instance Attribute Summary collapse
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
- #add(spec, out, err) ⇒ Object
- #failed? ⇒ Boolean
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #report ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
29 30 31 32 33 |
# File 'lib/merb-core/test/run_specs.rb', line 29 def initialize @examples, @failures, @errors, @pending, @total_time = 0, 0, 0, 0, 0 @err = "" @mutex = Mutex.new end |
Instance Attribute Details
#time ⇒ Object
Returns the value of attribute time.
28 29 30 |
# File 'lib/merb-core/test/run_specs.rb', line 28 def time @time end |
Instance Method Details
#add(spec, out, err) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/merb-core/test/run_specs.rb', line 39 def add(spec, out, err) @mutex.synchronize do puts puts "Running #{spec}." STDOUT.puts out STDOUT.flush match = out.match(/(\d+) examples?, (\d+) failures?(?:, (\d+) errors?)?(?:, (\d+) pending?)?/m) time = out.match(/Finished in (\d+\.\d+) seconds/) @total_time += time[1].to_f if time if match e, f, errors, pending = match[1..-1] @examples += e.to_i @failures += f.to_i @errors += errors.to_i @pending += pending.to_i end unless err.chomp.empty? @err << err.chomp << "\n" end end end |
#failed? ⇒ Boolean
35 36 37 |
# File 'lib/merb-core/test/run_specs.rb', line 35 def failed? @failures > 0 end |
#report ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/merb-core/test/run_specs.rb', line 61 def report i = 0 @err.gsub!(/^\d*\)\s*/) do "#{i += 1})\n" end puts @err puts if @failures != 0 || @errors != 0 print "\e[31m" # Red elsif @pending != 0 print "\e[33m" # Yellow else print "\e[32m" # Green end puts "#{@examples} examples, #{@failures} failures, #{@errors} errors, #{@pending} pending, #{sprintf("suite run in %3.3f seconds", @time.real)}" # TODO: we need to report pending examples all together puts "\e[0m" end |