Class: Cadre::RSpec3::QuickfixFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/cadre/rspec3/quickfix-formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ QuickfixFormatter

TODO: vim-side function for printing progress (if that’s even possible)



12
13
14
15
# File 'lib/cadre/rspec3/quickfix-formatter.rb', line 12

def initialize(output)
  @config = Config.new(Valise, "quickfix")
  @output = File::open(@config.output_path, "w")
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/cadre/rspec3/quickfix-formatter.rb', line 16

def config
  @config
end

#outputObject (readonly)

Returns the value of attribute output.



16
17
18
# File 'lib/cadre/rspec3/quickfix-formatter.rb', line 16

def output
  @output
end

Instance Method Details

#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object



46
47
48
49
50
51
# File 'lib/cadre/rspec3/quickfix-formatter.rb', line 46

def dump_summary(duration, example_count, failure_count, pending_count)
  @duration = duration
  @example_count = example_count
  @failure_count = failure_count
  @pending_count = pending_count
end

#example_failed(notification) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cadre/rspec3/quickfix-formatter.rb', line 20

def example_failed(notification)
  example = notification.example

  exception = example.execution_result.exception
  exceptions = exception.respond_to?(:all_exceptions)  ? exception.all_exceptions : [exception]
  exceptions.each do |exception|
    paths = exception.backtrace.map do |frame|
      format_caller frame
    end.compact[0..config.backtrace_limit]

    message = "#{example.full_description}: #{format_message exception.message}"
    paths.each do |path|
      output.puts "#{path}: [FAIL] #{message}"
    end
  end
end

#example_pending(example) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/cadre/rspec3/quickfix-formatter.rb', line 37

def example_pending(example)
  return unless config.include_pending?
  example = notification.example

  message = format_message example.execution_result[:pending_message]
  path    = format_caller example.location
  output.puts "#{path}: [PEND] #{message}" if path
end

#stop(notification) ⇒ Object



53
54
55
# File 'lib/cadre/rspec3/quickfix-formatter.rb', line 53

def stop(notification)
  @output.close
end