lib/guard/rspec/formatter.rb in guard-rspec-4.2.8 vs lib/guard/rspec/formatter.rb in guard-rspec-4.2.9
- old
+ new
@@ -2,11 +2,11 @@
require 'rspec/core/formatters/base_formatter'
module Guard
class RSpec
class Formatter < ::RSpec::Core::Formatters::BaseFormatter
- TEMPORARY_FILE_PATH = File.expand_path('./tmp/rspec_guard_result')
+ TEMPORARY_FILE_PATH ||= File.expand_path('./tmp/rspec_guard_result')
def self.rspec_3?
::RSpec::Core::Version::STRING.split('.').first == "3"
end
@@ -40,32 +40,36 @@
flags |= File::FNM_EXTGLOB
end
File.fnmatch(::RSpec.configuration.pattern, path.sub(/:\d+\z/, ''), flags)
end
- # Write summary to temporary file for runner
def dump_summary(*args)
if self.class.rspec_3?
notification = args[0]
- duration = notification.duration
- total = notification.example_count
- failures = notification.failure_count
- pending = notification.pending_count
+ write_summary(
+ notification.duration,
+ notification.example_count,
+ notification.failure_count,
+ notification.pending_count
+ )
else
- duration, total, failures, pending = args
+ write_summary(*args)
end
+ rescue
+ # nothing really we can do, at least don't kill the test runner
+ end
- write do |f|
+ # 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
- rescue
- # nothing really we can do, at least don't kill the test runner
end
private
- def write(&block)
+ def _write(&block)
FileUtils.mkdir_p(File.dirname(TEMPORARY_FILE_PATH))
File.open(TEMPORARY_FILE_PATH, 'w', &block)
end
def _failed_paths