Skip to content

Commit

Permalink
Refactor on the default formatter
Browse files Browse the repository at this point in the history
attempt to make code climate happier.
  • Loading branch information
hopsoft committed Nov 13, 2014
1 parent 0acade7 commit a8f0f22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/micro_test/formatters/default_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def before_class(test_class)
end

def after_test(test)
duration = (test.duration * 10**4).round.to_f / 10**4
color = duration < 0.01 ? :yellow : :red
print send(color, " #{duration.to_s.ljust(6, "0")}")
print_duration test.duration

if test.passed?
print green(" #{test.desc}")
Expand All @@ -35,6 +33,11 @@ def after_suite(test_classes)

private

def print_duration(duration)
color = duration < 0.01 ? :yellow : :red
print send(color, " #{duration.to_s.ljust(6, "0")}")
end

def print_with_line(value)
puts "#{value} ".ljust(80, "-")
end
Expand Down
8 changes: 7 additions & 1 deletion lib/micro_test/test_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module MicroTest
# Exists for the purpose of isolating the test method so it can run in its own thread.
class TestWrapper
include MonitorMixin
attr_reader :test_class, :desc, :asserts, :duration
attr_reader :test_class, :desc, :asserts

# Constructor.
# @param [MicroTest::Test] test_class The test class that defines the test being wrapped.
Expand Down Expand Up @@ -98,6 +98,12 @@ def reset
@duration = nil
end

# Rounded duration with 4 decimal places.
def duration
return nil if @duration.nil?
(@duration.to_f * 10**4).round / 10**4
end

private

# Builds a Hash of assert information for the given call stack.
Expand Down

0 comments on commit a8f0f22

Please sign in to comment.