Class: Cucumber::Formatter::Json
- Inherits:
-
Object
- Object
- Cucumber::Formatter::Json
show all
- Includes:
- Io
- Defined in:
- lib/cucumber/formatter/json.rb
Overview
The formatter used for --format json
Defined Under Namespace
Classes: Builder
Instance Method Summary
collapse
Methods included from Io
ensure_dir, ensure_file, ensure_io
Constructor Details
#initialize(config) ⇒ Json
Returns a new instance of Json.
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/cucumber/formatter/json.rb', line 14
def initialize(config)
@io = ensure_io(config.out_stream)
@feature_hashes = []
@step_or_hook_hash = {}
config.on_event :test_case_started, &method(:on_test_case_started)
config.on_event :test_case_finished, &method(:on_test_case_finished)
config.on_event :test_step_started, &method(:on_test_step_started)
config.on_event :test_step_finished, &method(:on_test_step_finished)
config.on_event :test_run_finished, &method(:on_test_run_finished)
end
|
Instance Method Details
#embed(src, mime_type, _label) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/cucumber/formatter/json.rb', line 83
def embed(src, mime_type, _label)
if File.file?(src)
content = File.open(src, 'rb') { |f| f.read }
data = encode64(content)
else
if mime_type =~ /;base64$/
mime_type = mime_type[0..-8]
data = src
else
data = encode64(src)
end
end
test_step_embeddings << { mime_type: mime_type, data: data }
end
|
#on_test_case_finished(event) ⇒ Object
69
70
71
72
73
|
# File 'lib/cucumber/formatter/json.rb', line 69
def on_test_case_finished(event)
_test_case, result = *event.attributes
result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
add_failed_around_hook(result) if result.failed? && !@any_step_failed
end
|
#on_test_case_started(event) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cucumber/formatter/json.rb', line 25
def on_test_case_started(event)
test_case = event.test_case
builder = Builder.new(test_case)
unless same_feature_as_previous_test_case?(test_case.feature)
@feature_hash = builder.feature_hash
@feature_hashes << @feature_hash
end
@test_case_hash = builder.test_case_hash
if builder.background?
feature_elements << builder.background_hash
@element_hash = builder.background_hash
else
feature_elements << @test_case_hash
@element_hash = @test_case_hash
end
@any_step_failed = false
end
|
#on_test_run_finished(_event) ⇒ Object
75
76
77
|
# File 'lib/cucumber/formatter/json.rb', line 75
def on_test_run_finished(_event)
@io.write(MultiJson.dump(@feature_hashes, pretty: true))
end
|
#on_test_step_finished(event) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/cucumber/formatter/json.rb', line 61
def on_test_step_finished(event)
test_step, result = *event.attributes
result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
return if internal_hook?(test_step)
add_match_and_result(test_step, result)
@any_step_failed = true if result.failed?
end
|
#on_test_step_started(event) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/cucumber/formatter/json.rb', line 43
def on_test_step_started(event)
test_step = event.test_step
return if internal_hook?(test_step)
hook_query = HookQueryVisitor.new(test_step)
if hook_query.hook?
@step_or_hook_hash = {}
hooks_of_type(hook_query) << @step_or_hook_hash
return
end
if first_step_after_background?(test_step)
feature_elements << @test_case_hash
@element_hash = @test_case_hash
end
@step_or_hook_hash = create_step_hash(test_step.source.last)
steps << @step_or_hook_hash
@step_hash = @step_or_hook_hash
end
|
#puts(message) ⇒ Object
79
80
81
|
# File 'lib/cucumber/formatter/json.rb', line 79
def puts(message)
test_step_output << message
end
|