Class: CucumberCharacteristics::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber_characteristics/exporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile) ⇒ Exporter

Returns a new instance of Exporter.



9
10
11
12
# File 'lib/cucumber_characteristics/exporter.rb', line 9

def initialize(profile)
  @profile = profile
  @config  = CucumberCharacteristics.configuration
end

Instance Attribute Details

#profileObject (readonly)

Returns the value of attribute profile.



8
9
10
# File 'lib/cucumber_characteristics/exporter.rb', line 8

def profile
  @profile
end

Instance Method Details

#exportObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cucumber_characteristics/exporter.rb', line 14

def export
  filename = @config.full_target_filename
  if @config.export_html
    File.open(filename+'.html', 'w') { |file| file.write(to_html) }
    puts "Step characteristics report written to #{filename}.html"
  end
  if @config.export_json
    File.open(filename+'.json', 'w') { |file| file.write(to_json) }
    puts "Step characteristics report written to #{filename}.json"
  end
end

#format_step_usage(step_feature_data) ⇒ Object



42
43
44
45
46
# File 'lib/cucumber_characteristics/exporter.rb', line 42

def format_step_usage(step_feature_data)
  step_feature_data[:feature_location].map do |location, timings|
    "#{location}" + (timings.count > 1 ? " (x#{timings.count})" : '')
  end.join("\n")
end

#format_ts(t) ⇒ Object

HELPERS



38
39
40
# File 'lib/cucumber_characteristics/exporter.rb', line 38

def format_ts(t)
  t ? sprintf("%0.#{@config.precision}f", t) : '-'
end

#step_status_summary(profile) ⇒ Object



48
49
50
51
# File 'lib/cucumber_characteristics/exporter.rb', line 48

def step_status_summary(profile)
  status = profile.step_count_by_status
  status.keys.sort.map{|s| status[s]> 0 ? "#{s.capitalize}: #{status[s]}" : nil}.compact.join(', ')
end

#to_htmlObject



26
27
28
29
30
# File 'lib/cucumber_characteristics/exporter.rb', line 26

def to_html
  template = File.read(File.expand_path('../view/step_report.html.haml', __FILE__))
  haml_engine = Haml::Engine.new(template)
  haml_engine.render(self)
end

#to_jsonObject



32
33
34
# File 'lib/cucumber_characteristics/exporter.rb', line 32

def to_json
  @profile.step_profiles.to_json
end