Class: Guard::RSpecFormatter

Inherits:
RSpec::Core::Formatters::BaseFormatter
  • Object
show all
Defined in:
lib/guard/rspec_formatter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extract_spec_location(metadata) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/guard/rspec_formatter.rb', line 30

def self.extract_spec_location()
   = 
  location = [:location]

  until spec_path?(location)
     = [:example_group]

    unless 
      STDERR.puts "no spec file found for #{root_metadata[:location]}"
      return [:location]
    end

    # rspec issue https://github.com/rspec/rspec-core/issues/1243
    location = ([:location] || "").split(":").first
  end

  location
end

.rspec_3?Boolean


13
14
15
# File 'lib/guard/rspec_formatter.rb', line 13

def self.rspec_3?
  ::RSpec::Core::Version::STRING.split(".").first == "3"
end

.spec_path?(path) ⇒ Boolean


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/guard/rspec_formatter.rb', line 49

def self.spec_path?(path)
  path ||= ""
  flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
  if File.const_defined?(:FNM_EXTGLOB) # ruby >= 2
    flags |= File::FNM_EXTGLOB
  end
  pattern = ::RSpec.configuration.pattern
  path = path.sub(/:\d+\z/, "")
  path = Pathname.new(path).cleanpath.to_s
  File.fnmatch(pattern, path, flags)
end

Instance Method Details

#dump_summary(*args) ⇒ Object


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/guard/rspec_formatter.rb', line 61

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
end

#example_failed(failure) ⇒ Object


20
21
22
# File 'lib/guard/rspec_formatter.rb', line 20

def example_failed(failure)
  examples.push failure.example
end

#examplesObject


24
25
26
# File 'lib/guard/rspec_formatter.rb', line 24

def examples
  @examples ||= []
end

#write_summary(duration, total, failures, pending) ⇒ Object

Write summary to temporary file for runner


78
79
80
81
82
83
# File 'lib/guard/rspec_formatter.rb', line 78

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