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.
13
14
15
16
17
18
19
20
21
|
# File 'lib/cucumber/formatter/json.rb', line 13
def initialize(config)
config.on_event :before_test_case, &method(:on_before_test_case)
config.on_event :after_test_case, &method(:on_after_test_case)
config.on_event :before_test_step, &method(:on_before_test_step)
config.on_event :after_test_step, &method(:on_after_test_step)
config.on_event :finished_testing, &method(:on_finished_testing)
@io = ensure_io(config.out_stream)
@feature_hashes = []
end
|
Instance Method Details
#embed(src, mime_type, _label) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/cucumber/formatter/json.rb', line 80
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_after_test_case(event) ⇒ Object
67
68
69
70
|
# File 'lib/cucumber/formatter/json.rb', line 67
def on_after_test_case(event)
result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
add_failed_around_hook(result) if result.failed? && !@any_step_failed
end
|
#on_after_test_step(event) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/cucumber/formatter/json.rb', line 59
def on_after_test_step(event)
test_step = event.test_step
result = event.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_before_test_case(event) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/cucumber/formatter/json.rb', line 23
def on_before_test_case(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_before_test_step(event) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/cucumber/formatter/json.rb', line 41
def on_before_test_step(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
|
#on_finished_testing(event) ⇒ Object
72
73
74
|
# File 'lib/cucumber/formatter/json.rb', line 72
def on_finished_testing(event)
@io.write(MultiJson.dump(@feature_hashes, pretty: true))
end
|
#puts(message) ⇒ Object
76
77
78
|
# File 'lib/cucumber/formatter/json.rb', line 76
def puts(message)
test_step_output << message
end
|