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.
22 23 24 25 26 |
# File 'lib/merb-core/test/run_specs.rb', line 22 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.
21 22 23 |
# File 'lib/merb-core/test/run_specs.rb', line 21 def time @time end |
Instance Method Details
#add(spec, out, err) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/merb-core/test/run_specs.rb', line 32 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
28 29 30 |
# File 'lib/merb-core/test/run_specs.rb', line 28 def failed? @failures > 0 end |
#report ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/merb-core/test/run_specs.rb', line 54 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 |