Class: Barthes::Reporter::Default

Inherits:
Object
  • Object
show all
Includes:
Term::ANSIColor
Defined in:
lib/barthes/reporter/default.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Default

Returns a new instance of Default.



8
9
10
# File 'lib/barthes/reporter/default.rb', line 8

def initialize(opts={})
	@opts = opts
end

Instance Method Details

#after_action(name, action, scenarios) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/barthes/reporter/default.rb', line 24

def after_action(name, action, scenarios)
	if Barthes::Config[:quiet] == 0 && Barthes::Config[:dryrun] == 0
		puts indent scenarios.size + 1, "request:"
		puts indent scenarios.size + 2, JSON.pretty_generate(action['request']) if action['request']
		if %w(success failure).include?(action['status']) && action['response']
			puts indent scenarios.size + 1, "response:"
			puts indent scenarios.size + 2, JSON.pretty_generate(action['response'])
		elsif action['status'] == 'error'
			puts indent scenarios.size + 1, "error:"
			puts indent scenarios.size + 2, "class: #{action['error']['class']}"
			puts indent scenarios.size + 2, "message: #{action['error']['message']}"
			puts indent scenarios.size + 2, "backtrace:"
			puts indent scenarios.size + 3, action['error']['backtrace'].join("\n")
		end
	end
	expectations = action['expectations'] || []
	expectations.each do |expectation|
		if expectation['result'] == false
			puts indent scenarios.size + 1, "failed expectation:"
			puts indent scenarios.size + 2, JSON.pretty_generate(expectation)
		end
	end
	flag = ''
	if Barthes::Config[:dryrun] > 0
		flag = 'skipped'
	elsif action['status'] == 'success'
		flag = green { action['status'] }
	else
		flag = red { action['status'] }
	end
	puts indent(scenarios.size + 1, "result: #{flag}")
end

#after_run(features) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/barthes/reporter/default.rb', line 63

def after_run(features)
	@count = Hash.new(0)
	walk_json(features)
	puts '-' * 80
	puts [
		"all: #{@count['all'].to_s }",
		"success: #{@count['success'] > 0 ? green { @count['success'].to_s } : @count['success'].to_s }",
		"failure: #{@count['failure'] > 0 ? red { @count['failure'].to_s }   : @count['failure'].to_s }",
		"error: #{@count['error'] > 0 ? red { @count['error'].to_s } : @count['error'].to_s }",
		"skipped: #{@count['skipped'].to_s }"
	].join(", ")
end

#before_action(name, action, scenarios) ⇒ Object



20
21
22
# File 'lib/barthes/reporter/default.rb', line 20

def before_action(name, action, scenarios)
	puts ("\t" * scenarios.size) + "##{action['number']} #{name}"
end

#before_feature(name) ⇒ Object



12
13
14
# File 'lib/barthes/reporter/default.rb', line 12

def before_feature(name)
	puts name
end

#before_scenario(name, scenario, scenarios) ⇒ Object



16
17
18
# File 'lib/barthes/reporter/default.rb', line 16

def before_scenario(name, scenario, scenarios)
	puts ("\t" * scenarios.size) + name
end

#indent(num, string) ⇒ Object



57
58
59
60
61
# File 'lib/barthes/reporter/default.rb', line 57

def indent(num, string)
	string.split("\n").map do |line|
		("\t" * num) + line
	end.join("\n")
end

#walk_json(obj) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/barthes/reporter/default.rb', line 76

def walk_json(obj)
	case obj.first
	when 'feature', 'scenario'
		walk_json(obj.last)
	when 'action'
		@count['all'] += 1
		@count[obj.last['status']] += 1
	else
		obj.each {|obj2| walk_json(obj2) }
	end
end