lib/guard/rspec_formatter.rb in guard-rspec-4.5.0 vs lib/guard/rspec_formatter.rb in guard-rspec-4.5.1

- old
+ new

@@ -1,9 +1,10 @@ # NOTE: This class only exists for RSpec and should not be used by # other classes in this project! require "pathname" +require "fileutils" require "rspec" require "rspec/core/formatters/base_formatter" module Guard @@ -57,55 +58,56 @@ path = Pathname.new(path).cleanpath.to_s File.fnmatch(pattern, path, flags) end def dump_summary(*args) - if self.class.rspec_3? - notification = args[0] - write_summary( - notification.duration, - notification.example_count, - notification.failure_count, - notification.pending_count - ) - else - write_summary(*args) - end - rescue - # nothing really we can do, at least don"t kill the test runner + return write_summary(*args) unless self.class.rspec_3? + + notification = args[0] + write_summary( + notification.duration, + notification.example_count, + notification.failure_count, + notification.pending_count + ) end + private + # Write summary to temporary file for runner def write_summary(duration, total, failures, pending) _write do |f| f.puts _message(total, failures, pending, duration) f.puts _failed_paths.join("\n") if failures > 0 end end - private - def _write(&block) file = File.expand_path(TEMPORARY_FILE_PATH) FileUtils.mkdir_p(File.dirname(file)) File.open(file, "w", &block) end def _failed_paths - failed = examples.select do |e| - e.execution_result[:status].to_s == "failed" - end - klass = self.class + failed = examples.select { |example| _status_failed?(example) } failed.map { |e| klass.extract_spec_location(e.metadata) }.sort.uniq end def _message(example_count, failure_count, pending_count, duration) message = "#{example_count} examples, #{failure_count} failures" if pending_count > 0 message << " (#{pending_count} pending)" end message << " in #{duration.round(4)} seconds" message + end + + def _status_failed?(example) + if self.class.rspec_3? + example.execution_result.status.to_s == "failed" + else + example.execution_result[:status].to_s == "failed" + end end end end