Class: Guard::RSpecFormatter

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

Defined Under Namespace

Classes: Error

Constant Summary collapse

UNSUPPORTED_PATTERN =
"Your RSpec.configuration.pattern uses characters "\
"unsupported by your Ruby version (File::FNM_EXTGLOB is undefined)".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extract_spec_location(metadata) ⇒ Object



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

def extract_spec_location()
   = 
  location = [:location]

  until spec_path?(location)
    unless ( = _extract_group())
      STDERR.puts "no spec file location in #{.inspect}"
      return [:location]
    end

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

  location
end

.rspec_3?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/guard/rspec_formatter.rb', line 26

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

.spec_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

def spec_path?(path)
  pattern = ::RSpec.configuration.pattern

  flags = supported_fnmatch_flags(pattern)
  path ||= ""
  path = path.sub(/:\d+\z/, "")
  path = Pathname.new(path).cleanpath.to_s
  stripped = "{#{pattern.gsub(/\s*,\s*/, ',')}}"
  File.fnmatch(stripped, path, flags)
end

Instance Method Details

#dump_summary(*args) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/guard/rspec_formatter.rb', line 94

def dump_summary(*args)
  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

#example_failed(failure) ⇒ Object



33
34
35
# File 'lib/guard/rspec_formatter.rb', line 33

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

#examplesObject



37
38
39
# File 'lib/guard/rspec_formatter.rb', line 37

def examples
  @examples ||= []
end