Class: RspecNumberingFormatter

Inherits:
RSpec::Core::Formatters::BaseTextFormatter
  • Object
show all
Defined in:
lib/rspec_numbering_formatter.rb

Overview

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#run_countObject

Returns the value of attribute run_count.



10
11
12
# File 'lib/rspec_numbering_formatter.rb', line 10

def run_count
  @run_count
end

Instance Method Details

#dump_failures(notification) ⇒ Object



44
45
46
# File 'lib/rspec_numbering_formatter.rb', line 44

def dump_failures notification
  puts
end

#example_failed(notification) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/rspec_numbering_formatter.rb', line 31

def example_failed(notification)
  @run_count += 1
  output.puts "\r\e[K#{@run_count.to_s.rjust(10)} #{notification.example.full_description}"
  output.puts "           #{truncate_cwd notification.example.location}"
  output.puts notification.colorized_message_lines
  output.puts notification.colorized_formatted_backtrace
  output.puts
end

#example_passed(notification) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/rspec_numbering_formatter.rb', line 22

def example_passed(notification)
  elapsed = (Time.now - @start_time).to_i
  secs = elapsed % 60
  mins = elapsed / 60
  elapsed = "#{mins}:#{secs.to_s.rjust(2, '0')}"
  @run_count += 1
  output.print "\r\e[K#{elapsed.rjust(8)} #{@run_count.to_s.rjust(10)} #{notification.example.full_description[0..100].ljust(101)}  #{truncate_cwd(notification.example.location)[0..100]}"
end

#failure_color(*args) ⇒ Object



12
# File 'lib/rspec_numbering_formatter.rb', line 12

def failure_color(*args); red(*args); end

#start(notification) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/rspec_numbering_formatter.rb', line 14

def start(notification)
  super
  @cwd = `pwd`
  @start_time = Time.now
  @run_count = 0
  output.puts "#{notification.count} examples"
end

#truncate_cwd(str) ⇒ Object



40
41
42
# File 'lib/rspec_numbering_formatter.rb', line 40

def truncate_cwd str
  str.sub @cwd, ""
end