Class: Beagle::TimedFormatter

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TimedFormatter

Returns a new instance of TimedFormatter.



8
9
10
11
# File 'lib/beagle/timed_formatter.rb', line 8

def initialize(options)
  super
  @metrics = Hash.new{|h,k| h[k] = Beagle::Examples.new}
end

Instance Method Details

#example_failed(example) ⇒ Object



27
28
29
30
# File 'lib/beagle/timed_formatter.rb', line 27

def example_failed(example)
  super
  set_time(example)
end

#example_passed(example) ⇒ Object



22
23
24
25
# File 'lib/beagle/timed_formatter.rb', line 22

def example_passed(example)
  super
  set_time(example)
end

#example_started(example) ⇒ Object



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

def example_started(example)
  super
  parts = example.file_path.split('/spec/')
  @out_dir ||= "#{parts(example).first}/reports/beagle"
  @type = type(example)
  @metrics[@type].add(example)
  @start_time = Time.now
end

#start_dumpObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/beagle/timed_formatter.rb', line 32

def start_dump
  template = File.read(File.expand_path('../templates/index.rhtml', File.dirname(__FILE__)))
  rhtml = ERB.new(template, nil, ">")
  metrics = Beagle::Metrics.new(@metrics)
  FileUtils.mkdir_p @out_dir
  outfile = "#{@out_dir}/index.html"
  FileUtils.rm_rf outfile
  File.open(outfile, 'w') {|f| f.write(rhtml.result(metrics.get_binding)) }
  copy_javascript_files
end