Class: CukeParser::ReportEngine::ReporterUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/report_engine/reporter_utils.rb

Instance Method Summary collapse

Constructor Details

#initializeReporterUtils

Returns a new instance of ReporterUtils.



5
6
7
# File 'lib/report_engine/reporter_utils.rb', line 5

def initialize
	#I might eventually use this!
end

Instance Method Details

#find_cuke_metrics(cuke) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/report_engine/reporter_utils.rb', line 47

def find_cuke_metrics(cuke)
	cuke_metrics = {:scenarios_passed_total => 0, :scenarios_failed_total => 0, :steps_passed_total => 0,:steps_failed_total => 0,:steps_skipped_total => 0}
	cuke.features.each do |feature|
		cuke_metrics[feature.name.to_sym] = get_scenario_metrics(feature)
		cuke_metrics[:scenarios_failed_total] += cuke_metrics[feature.name.to_sym][:feature_metrics][:failed]
		cuke_metrics[:scenarios_passed_total] += cuke_metrics[feature.name.to_sym][:feature_metrics][:passed]
		cuke_metrics[:steps_skipped_total] += cuke_metrics[feature.name.to_sym][:scenario_metrics][:skipped]
		cuke_metrics[:steps_failed_total] += cuke_metrics[feature.name.to_sym][:scenario_metrics][:failed]
		cuke_metrics[:steps_passed_total] += cuke_metrics[feature.name.to_sym][:scenario_metrics][:passed]
	end
	return cuke_metrics
end

#get_scenario_metrics(feature) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/report_engine/reporter_utils.rb', line 27

def get_scenario_metrics(feature)
	feature_metrics = {:scenario_count => 0, :passed => 0, :failed => 0}
	scenario_metrics = {:step_count => 0, :passed => 0, :failed => 0, :skipped => 0}
	#don't want to count background!
	feature_metrics[:scenario_count] = feature.scenarios.count - 1
	feature.scenarios.each do |scenario|
		scenario.status.eql?("passed") ? (scenario.keyword.eql?("Background") ? (feature_metrics[:passed] += 0) : (feature_metrics[:passed] += 1)) : (scenario.keyword.eql?("Background") ? (feature_metrics[:failed] += 0) : (feature_metrics[:failed] += 1))
		scenario_metrics = get_step_metrics(scenario,scenario_metrics)
	end
	return {:feature_metrics => feature_metrics, :scenario_metrics => scenario_metrics}
end

#get_step_metrics(scenario, scenario_metrics) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/report_engine/reporter_utils.rb', line 39

def get_step_metrics(scenario,scenario_metrics)
	scenario_metrics[:step_count] += scenario.steps.count
	scenario.steps.each do |step|
		step.status.eql?("passed") ? (scenario_metrics[:passed] += 1) : (step.status.eql?("failed") ? (scenario_metrics[:failed] += 1) : (scenario_metrics[:skipped] += 1))
	end
	return scenario_metrics
end

#model_status_display(status) ⇒ Object



23
24
25
# File 'lib/report_engine/reporter_utils.rb', line 23

def model_status_display(status)
	status == "failed" ? {:class => "failed"} : (status == "passed" ? {:class => "passed"} : {:class => "skipped"})
end

#time_to_words(duration) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/report_engine/reporter_utils.rb', line 9

def time_to_words(duration)
	#need to determine if it has hours or minutes for output string!
	t = Time.at(duration / 1000000000.00).gmtime
	if !t.strftime('%H').eql?("00")
		t.strftime('%H hours and %M mins and %S secs and %L ms')
	elsif !t.strftime('%M').eql?("00")
		t.strftime('%M mins and %S secs and %L ms')
	elsif !t.strftime('%S').eql?("00")
		t.strftime('%S secs and %L ms')
	else
		t.strftime('%L ms')
	end
end