Skip to content

Commit

Permalink
Improve Ctrl-C handling of spec (#5719)
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and Serdar Dogruyol committed Apr 13, 2018
1 parent 90c3a7a commit 68575de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/spec/context.cr
Expand Up @@ -42,15 +42,15 @@ module Spec
@results[result.kind] << result
end

def self.print_results(elapsed_time)
@@instance.print_results(elapsed_time)
def self.print_results(elapsed_time, aborted = false)
@@instance.print_results(elapsed_time, aborted)
end

def self.succeeded
@@instance.succeeded
end

def print_results(elapsed_time)
def print_results(elapsed_time, aborted = false)
Spec.formatters.each(&.finish)

pendings = @results[:pending]
Expand Down Expand Up @@ -124,11 +124,13 @@ module Spec
total = pendings.size + failures.size + errors.size + success.size

final_status = case
when aborted then :error
when (failures.size + errors.size) > 0 then :fail
when pendings.size > 0 then :pending
else :success
end

puts "Aborted!".colorize.red if aborted
puts "Finished in #{Spec.to_human(elapsed_time)}"
puts Spec.color("#{total} examples, #{failures.size} failures, #{errors.size} errors, #{pendings.size} pending", final_status)

Expand Down
5 changes: 3 additions & 2 deletions src/spec/dsl.cr
Expand Up @@ -52,6 +52,7 @@ module Spec

# :nodoc:
def self.abort!
@@aborted = true
exit
end

Expand Down Expand Up @@ -169,8 +170,8 @@ module Spec
start_time = Time.monotonic
at_exit do
elapsed_time = Time.monotonic - start_time
Spec::RootContext.print_results(elapsed_time)
exit 1 unless Spec::RootContext.succeeded
Spec::RootContext.print_results(elapsed_time, @@aborted)
exit 1 unless Spec::RootContext.succeeded && !@@aborted
end
end
end
Expand Down

0 comments on commit 68575de

Please sign in to comment.