cucumber-html-formatter 21.0.0 → 21.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/cucumber-html-formatter +2 -1
- data/lib/cucumber/html_formatter/assets_loader.rb +2 -1
- data/lib/cucumber/html_formatter/formatter.rb +71 -0
- data/lib/cucumber/html_formatter/template_writer.rb +3 -3
- data/lib/cucumber/html_formatter.rb +4 -67
- data/spec/acceptance_spec.rb +2 -1
- data/spec/html_formatter/assets_loader_spec.rb +33 -0
- data/spec/html_formatter/formatter_spec.rb +87 -0
- data/spec/html_formatter/template_writer_spec.rb +31 -0
- data/spec/spec_helper.rb +1 -0
- metadata +14 -13
- data/spec/capture_warnings.rb +0 -74
- data/spec/html-formatter/assets_loader_spec.rb +0 -30
- data/spec/html-formatter/template_writer_spec.rb +0 -30
- data/spec/html_formatter_spec.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f34cc3f6521d85b2da0bef2ced3a3b77f382caac0cac9467f6fad96a1b68e09
|
4
|
+
data.tar.gz: fc71dc0cea23cc00873d5ad2ab13ec1e7e26bc4c317adef092b1b2843839c216
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9853ab9218ac5417c6dd5e32011914d66ce2d1d787a90c58ec3001339771e26b26087b3bccdcb8b7c6e817f761385b1439063148fd5b3631e64b583bc24d6db8
|
7
|
+
data.tar.gz: a572697d7893c6859132cdc62d5a3591dd2618a04038fd2f235055abcc63c4f353b47b8a1998397492d113f2cb444799013d4ca90265af5b5b9e4bc8d734c59b
|
data/bin/cucumber-html-formatter
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'optparse'
|
4
5
|
require 'cucumber/messages'
|
@@ -7,7 +8,7 @@ require 'cucumber/html_formatter'
|
|
7
8
|
formatter = Cucumber::HTMLFormatter::Formatter.new(STDOUT)
|
8
9
|
|
9
10
|
option_parser = OptionParser.new do |opts|
|
10
|
-
opts.on_tail(
|
11
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
11
12
|
puts opts
|
12
13
|
exit
|
13
14
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cucumber/messages'
|
4
|
+
require 'cucumber/html_formatter/template_writer'
|
5
|
+
require 'cucumber/html_formatter/assets_loader'
|
6
|
+
|
7
|
+
module Cucumber
|
8
|
+
module HTMLFormatter
|
9
|
+
class Formatter
|
10
|
+
attr_reader :out
|
11
|
+
|
12
|
+
def initialize(out)
|
13
|
+
@out = out
|
14
|
+
@pre_message_written = false
|
15
|
+
@first_message = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_messages(messages)
|
19
|
+
write_pre_message
|
20
|
+
messages.each { |message| write_message(message) }
|
21
|
+
write_post_message
|
22
|
+
end
|
23
|
+
|
24
|
+
def write_message(message)
|
25
|
+
unless @first_message
|
26
|
+
out.puts(',')
|
27
|
+
end
|
28
|
+
out.print(message.to_json)
|
29
|
+
|
30
|
+
@first_message = false
|
31
|
+
end
|
32
|
+
|
33
|
+
def write_pre_message
|
34
|
+
return if @pre_message_written
|
35
|
+
|
36
|
+
out.puts(pre_message)
|
37
|
+
@pre_message_written = true
|
38
|
+
end
|
39
|
+
|
40
|
+
def write_post_message
|
41
|
+
out.print(post_message)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def assets_loader
|
47
|
+
@assets_loader ||= AssetsLoader.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def pre_message
|
51
|
+
[
|
52
|
+
template_writer.write_between(nil, '{{css}}'),
|
53
|
+
assets_loader.css,
|
54
|
+
template_writer.write_between('{{css}}', '{{messages}}')
|
55
|
+
].join("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
def post_message
|
59
|
+
[
|
60
|
+
template_writer.write_between('{{messages}}', '{{script}}'),
|
61
|
+
assets_loader.script,
|
62
|
+
template_writer.write_between('{{script}}', nil)
|
63
|
+
].join("\n")
|
64
|
+
end
|
65
|
+
|
66
|
+
def template_writer
|
67
|
+
@template_writer ||= TemplateWriter.new(assets_loader.template)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Cucumber
|
2
4
|
module HTMLFormatter
|
3
5
|
class TemplateWriter
|
@@ -11,9 +13,7 @@ module Cucumber
|
|
11
13
|
from_exists = !from.nil? && template.include?(from)
|
12
14
|
|
13
15
|
after_from = from_exists ? template.split(from)[1] : template
|
14
|
-
|
15
|
-
|
16
|
-
return before_to
|
16
|
+
to.nil? ? after_from : after_from.split(to)[0]
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -1,69 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cucumber/messages'
|
2
|
-
require 'cucumber/html_formatter/template_writer'
|
3
4
|
require 'cucumber/html_formatter/assets_loader'
|
4
|
-
|
5
|
-
|
6
|
-
module HTMLFormatter
|
7
|
-
class Formatter
|
8
|
-
attr_reader :out
|
9
|
-
|
10
|
-
def initialize(out)
|
11
|
-
@out = out
|
12
|
-
@pre_message_written = false
|
13
|
-
@first_message = true
|
14
|
-
end
|
15
|
-
|
16
|
-
def process_messages(messages)
|
17
|
-
write_pre_message
|
18
|
-
messages.each { |message| write_message(message) }
|
19
|
-
write_post_message
|
20
|
-
end
|
21
|
-
|
22
|
-
def write_pre_message
|
23
|
-
return if @pre_message_written
|
24
|
-
|
25
|
-
out.puts(pre_message)
|
26
|
-
@pre_message_written = true
|
27
|
-
end
|
28
|
-
|
29
|
-
def write_message(message)
|
30
|
-
unless @first_message
|
31
|
-
out.puts(',')
|
32
|
-
end
|
33
|
-
out.print(message.to_json)
|
34
|
-
|
35
|
-
@first_message = false
|
36
|
-
end
|
37
|
-
|
38
|
-
def write_post_message
|
39
|
-
out.print(post_message)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def assets_loader
|
45
|
-
@assets_loader ||= AssetsLoader.new
|
46
|
-
end
|
47
|
-
|
48
|
-
def pre_message
|
49
|
-
[
|
50
|
-
template_writer.write_between(nil, '{{css}}'),
|
51
|
-
assets_loader.css,
|
52
|
-
template_writer.write_between('{{css}}', '{{messages}}')
|
53
|
-
].join("\n")
|
54
|
-
end
|
55
|
-
|
56
|
-
def post_message
|
57
|
-
[
|
58
|
-
template_writer.write_between('{{messages}}', '{{script}}'),
|
59
|
-
assets_loader.script,
|
60
|
-
template_writer.write_between('{{script}}', nil)
|
61
|
-
].join("\n")
|
62
|
-
end
|
63
|
-
|
64
|
-
def template_writer
|
65
|
-
@template_writer ||= TemplateWriter.new(assets_loader.template)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
5
|
+
require 'cucumber/html_formatter/formatter'
|
6
|
+
require 'cucumber/html_formatter/template_writer'
|
data/spec/acceptance_spec.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Cucumber::HTMLFormatter::AssetsLoader do
|
4
|
+
subject(:assets_loader) { described_class.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
allow(File).to receive(:read).and_return('whatever content')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#template' do
|
11
|
+
it 'reads the content of assets/index.mustache.html' do
|
12
|
+
expect(File).to receive(:read).with(/.*\/assets\/index\.mustache\.html$/)
|
13
|
+
|
14
|
+
assets_loader.template
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#css' do
|
19
|
+
it 'reads the content of assets/main.css' do
|
20
|
+
expect(File).to receive(:read).with(/.*\/assets\/main\.css$/)
|
21
|
+
|
22
|
+
assets_loader.css
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#script' do
|
27
|
+
it 'reads the content of assets/main.js' do
|
28
|
+
expect(File).to receive(:read).with(/.*\/assets\/main\.js$/)
|
29
|
+
|
30
|
+
assets_loader.script
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cucumber/messages'
|
4
|
+
|
5
|
+
describe Cucumber::HTMLFormatter::Formatter do
|
6
|
+
subject(:formatter) do
|
7
|
+
formatter = Cucumber::HTMLFormatter::Formatter.new(out)
|
8
|
+
allow(formatter).to receive(:assets_loader).and_return(assets)
|
9
|
+
formatter
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:out) { StringIO.new }
|
13
|
+
let(:fake_assets) do
|
14
|
+
Class.new do
|
15
|
+
def template
|
16
|
+
'<html>{{css}}<body>{{messages}}</body>{{script}}</html>'
|
17
|
+
end
|
18
|
+
|
19
|
+
def css
|
20
|
+
'<style>div { color: red }</style>'
|
21
|
+
end
|
22
|
+
|
23
|
+
def script
|
24
|
+
"<script>alert('Hi')</script>"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
let(:assets) { fake_assets.new }
|
29
|
+
|
30
|
+
describe '#process_messages' do
|
31
|
+
let(:message) { Cucumber::Messages::Envelope.new(pickle: Cucumber::Messages::Pickle.new(id: 'some-random-uid')) }
|
32
|
+
|
33
|
+
it 'produces the full html report' do
|
34
|
+
formatter.process_messages([message])
|
35
|
+
expect(out.string).to eq(
|
36
|
+
[
|
37
|
+
'<html>',
|
38
|
+
'<style>div { color: red }</style>',
|
39
|
+
'<body>',
|
40
|
+
"#{message.to_json}</body>",
|
41
|
+
"<script>alert('Hi')</script>",
|
42
|
+
'</html>'
|
43
|
+
].join("\n")
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#write_pre_message' do
|
49
|
+
it 'outputs the content of the template up to {{messages}}' do
|
50
|
+
formatter.write_pre_message
|
51
|
+
|
52
|
+
expect(out.string).to eq("<html>\n<style>div { color: red }</style>\n<body>\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'does not write the content twice' do
|
56
|
+
formatter.write_pre_message
|
57
|
+
formatter.write_pre_message
|
58
|
+
|
59
|
+
expect(out.string).to eq("<html>\n<style>div { color: red }</style>\n<body>\n")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#write_message' do
|
64
|
+
let(:message) { Cucumber::Messages::Envelope.new(pickle: Cucumber::Messages::Pickle.new(id: 'some-random-uid')) }
|
65
|
+
|
66
|
+
it 'appends the message to out' do
|
67
|
+
formatter.write_message(message)
|
68
|
+
|
69
|
+
expect(out.string).to eq(message.to_json)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'adds commas between the messages' do
|
73
|
+
formatter.write_message(message)
|
74
|
+
formatter.write_message(message)
|
75
|
+
|
76
|
+
expect(out.string).to eq("#{message.to_json},\n#{message.to_json}")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#write_post_message' do
|
81
|
+
it 'outputs the template end' do
|
82
|
+
formatter.write_post_message
|
83
|
+
|
84
|
+
expect(out.string).to eq("</body>\n<script>alert('Hi')</script>\n</html>")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Cucumber::HTMLFormatter::TemplateWriter do
|
4
|
+
describe '#write_between' do
|
5
|
+
subject(:template_writer) { described_class.new(template) }
|
6
|
+
|
7
|
+
let(:template) { 'Some template {{here}} with content after' }
|
8
|
+
|
9
|
+
it 'outputs content of the template between the given words' do
|
10
|
+
expect(template_writer.write_between('Some', 'content')).to eq(' template {{here}} with ')
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when the `from` argument is `nil`' do
|
14
|
+
it 'outputs template from the beginning' do
|
15
|
+
expect(template_writer.write_between(nil, '{{here}}')).to eq('Some template ')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when the `to` argument is `nil`' do
|
20
|
+
it 'outputs content of template after the "from" argument value' do
|
21
|
+
expect(template_writer.write_between('{{here}}', nil)).to eq(' with content after')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when the `from` argument is not contained in the template' do
|
26
|
+
it 'renders the template from the beginning' do
|
27
|
+
expect(template_writer.write_between('Unknown start', '{{here}}')).to eq('Some template ')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cucumber/html_formatter'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-html-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 21.
|
4
|
+
version: 21.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Prêtre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cucumber-messages
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '19'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '25'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '19'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '25'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,12 +115,13 @@ files:
|
|
115
115
|
- bin/cucumber-html-formatter
|
116
116
|
- lib/cucumber/html_formatter.rb
|
117
117
|
- lib/cucumber/html_formatter/assets_loader.rb
|
118
|
+
- lib/cucumber/html_formatter/formatter.rb
|
118
119
|
- lib/cucumber/html_formatter/template_writer.rb
|
119
120
|
- spec/acceptance_spec.rb
|
120
|
-
- spec/
|
121
|
-
- spec/
|
122
|
-
- spec/
|
123
|
-
- spec/
|
121
|
+
- spec/html_formatter/assets_loader_spec.rb
|
122
|
+
- spec/html_formatter/formatter_spec.rb
|
123
|
+
- spec/html_formatter/template_writer_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
124
125
|
homepage: https://github.com/cucumber/html-formatter
|
125
126
|
licenses:
|
126
127
|
- MIT
|
@@ -150,10 +151,10 @@ requirements: []
|
|
150
151
|
rubygems_version: 3.4.10
|
151
152
|
signing_key:
|
152
153
|
specification_version: 4
|
153
|
-
summary: cucumber-html-formatter-21.
|
154
|
+
summary: cucumber-html-formatter-21.1.0
|
154
155
|
test_files:
|
155
156
|
- spec/acceptance_spec.rb
|
156
|
-
- spec/
|
157
|
-
- spec/
|
158
|
-
- spec/
|
159
|
-
- spec/
|
157
|
+
- spec/html_formatter/assets_loader_spec.rb
|
158
|
+
- spec/html_formatter/formatter_spec.rb
|
159
|
+
- spec/html_formatter/template_writer_spec.rb
|
160
|
+
- spec/spec_helper.rb
|
data/spec/capture_warnings.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# With thanks to @myronmarston
|
3
|
-
# https://github.com/vcr/vcr/blob/master/spec/capture_warnings.rb
|
4
|
-
|
5
|
-
module CaptureWarnings
|
6
|
-
def report_warnings(&block)
|
7
|
-
current_dir = Dir.pwd
|
8
|
-
warnings, errors = capture_error(&block).partition { |line| line.include?('warning') }
|
9
|
-
project_warnings, other_warnings = warnings.uniq.partition { |line| line.include?(current_dir) }
|
10
|
-
|
11
|
-
if errors.any?
|
12
|
-
puts errors.join("\n")
|
13
|
-
end
|
14
|
-
|
15
|
-
if other_warnings.any?
|
16
|
-
puts "#{ other_warnings.count } warnings detected, set VIEW_OTHER_WARNINGS=true to see them."
|
17
|
-
print_warnings('other', other_warnings) if ENV['VIEW_OTHER_WARNINGS']
|
18
|
-
end
|
19
|
-
|
20
|
-
# Until they fix https://bugs.ruby-lang.org/issues/10661
|
21
|
-
if RUBY_VERSION == "2.2.0"
|
22
|
-
project_warnings = project_warnings.reject { |w| w =~ /warning: possible reference to past scope/ }
|
23
|
-
end
|
24
|
-
|
25
|
-
if project_warnings.any?
|
26
|
-
puts "#{ project_warnings.count } warnings detected"
|
27
|
-
print_warnings('cucumber-expressions', project_warnings)
|
28
|
-
fail "Please remove all cucumber-expressions warnings."
|
29
|
-
end
|
30
|
-
|
31
|
-
ensure_system_exit_if_required
|
32
|
-
end
|
33
|
-
|
34
|
-
def capture_error(&block)
|
35
|
-
old_stderr = STDERR.clone
|
36
|
-
pipe_r, pipe_w = IO.pipe
|
37
|
-
pipe_r.sync = true
|
38
|
-
error = String.new
|
39
|
-
reader = Thread.new do
|
40
|
-
begin
|
41
|
-
loop do
|
42
|
-
error << pipe_r.readpartial(1024)
|
43
|
-
end
|
44
|
-
rescue EOFError
|
45
|
-
end
|
46
|
-
end
|
47
|
-
STDERR.reopen(pipe_w)
|
48
|
-
block.call
|
49
|
-
ensure
|
50
|
-
capture_system_exit
|
51
|
-
STDERR.reopen(old_stderr)
|
52
|
-
pipe_w.close
|
53
|
-
reader.join
|
54
|
-
return error.split("\n")
|
55
|
-
end
|
56
|
-
|
57
|
-
def print_warnings(type, warnings)
|
58
|
-
puts
|
59
|
-
puts "-" * 30 + " #{type} warnings: " + "-" * 30
|
60
|
-
puts
|
61
|
-
puts warnings.join("\n")
|
62
|
-
puts
|
63
|
-
puts "-" * 75
|
64
|
-
puts
|
65
|
-
end
|
66
|
-
|
67
|
-
def ensure_system_exit_if_required
|
68
|
-
raise @system_exit if @system_exit
|
69
|
-
end
|
70
|
-
|
71
|
-
def capture_system_exit
|
72
|
-
@system_exit = $!
|
73
|
-
end
|
74
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'cucumber/html_formatter/assets_loader'
|
2
|
-
|
3
|
-
describe Cucumber::HTMLFormatter::AssetsLoader do
|
4
|
-
let(:subject) { Cucumber::HTMLFormatter::AssetsLoader.new }
|
5
|
-
|
6
|
-
before do
|
7
|
-
allow(File).to receive(:read).and_return('whatever content')
|
8
|
-
end
|
9
|
-
|
10
|
-
context '.template' do
|
11
|
-
it 'reads the content of assets/index.mustache.html' do
|
12
|
-
expect(subject.template).to eq('whatever content')
|
13
|
-
expect(File).to have_received(:read).with(/.*\/assets\/index\.mustache\.html$/)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context '.css' do
|
18
|
-
it 'reads the content of assets/main.css' do
|
19
|
-
expect(subject.css).to eq('whatever content')
|
20
|
-
expect(File).to have_received(:read).with(/.*\/assets\/main\.css$/)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context '.script' do
|
25
|
-
it 'reads the content of assets/main.js' do
|
26
|
-
expect(subject.script).to eq('whatever content')
|
27
|
-
expect(File).to have_received(:read).with(/.*\/assets\/main\.js$/)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'cucumber/html_formatter/template_writer'
|
2
|
-
|
3
|
-
describe Cucumber::HTMLFormatter::TemplateWriter do
|
4
|
-
context 'write_between' do
|
5
|
-
let(:subject) { writer = Cucumber::HTMLFormatter::TemplateWriter.new(template) }
|
6
|
-
let(:template) { 'Some template {{here}} with content after' }
|
7
|
-
|
8
|
-
it 'outputs content of the template between the given words' do
|
9
|
-
expect(subject.write_between('Some', 'content')).to eq(' template {{here}} with ')
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when "from" argument is nil' do
|
13
|
-
it 'outputs template from the beginning' do
|
14
|
-
expect(subject.write_between(nil, '{{here}}')).to eq('Some template ')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when "to" argument is nil' do
|
19
|
-
it 'outputs content of template after the "from" argument value' do
|
20
|
-
expect(subject.write_between('{{here}}', nil)).to eq(' with content after')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when "from" argument is missing from the template' do
|
25
|
-
it 'renders the template from the beginning' do
|
26
|
-
expect(subject.write_between('Unknown start', '{{here}}')).to eq('Some template ')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/html_formatter_spec.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'cucumber/messages'
|
2
|
-
require 'cucumber/html_formatter'
|
3
|
-
|
4
|
-
class FakeAssets
|
5
|
-
def template
|
6
|
-
"<html>{{css}}<body>{{messages}}</body>{{script}}</html>"
|
7
|
-
end
|
8
|
-
|
9
|
-
def css
|
10
|
-
"<style>div { color: red }</style>"
|
11
|
-
end
|
12
|
-
|
13
|
-
def script
|
14
|
-
"<script>alert('Hi')</script>"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe Cucumber::HTMLFormatter::Formatter do
|
19
|
-
let(:subject) {
|
20
|
-
formatter = Cucumber::HTMLFormatter::Formatter.new(out)
|
21
|
-
allow(formatter).to receive(:assets_loader).and_return(assets)
|
22
|
-
formatter
|
23
|
-
}
|
24
|
-
let(:out) { StringIO.new }
|
25
|
-
let(:assets) { FakeAssets.new }
|
26
|
-
|
27
|
-
context '.write_pre_message' do
|
28
|
-
it 'outputs the content of the template up to {{messages}}' do
|
29
|
-
subject.write_pre_message()
|
30
|
-
expect(out.string).to eq("<html>\n<style>div { color: red }</style>\n<body>\n")
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'does not write the content twice' do
|
34
|
-
subject.write_pre_message()
|
35
|
-
subject.write_pre_message()
|
36
|
-
|
37
|
-
expect(out.string).to eq("<html>\n<style>div { color: red }</style>\n<body>\n")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context '.write_message' do
|
42
|
-
let(:message) do
|
43
|
-
::Cucumber::Messages::Envelope.new(
|
44
|
-
pickle: ::Cucumber::Messages::Pickle.new(id: 'some-random-uid')
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'appends the message to out' do
|
49
|
-
subject.write_message(message)
|
50
|
-
expect(out.string).to eq(message.to_json)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'adds commas between the messages' do
|
54
|
-
subject.write_message(message)
|
55
|
-
subject.write_message(message)
|
56
|
-
|
57
|
-
expect(out.string).to eq("#{message.to_json},\n#{message.to_json}")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context '.write_post_message' do
|
62
|
-
it 'outputs the template end' do
|
63
|
-
subject.write_post_message()
|
64
|
-
expect(out.string).to eq("</body>\n<script>alert('Hi')</script>\n</html>")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context '.process_messages' do
|
69
|
-
let(:message) do
|
70
|
-
::Cucumber::Messages::Envelope.new(
|
71
|
-
pickle: ::Cucumber::Messages::Pickle.new(id: 'some-random-uid')
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'produces the full html report' do
|
76
|
-
subject.process_messages([message])
|
77
|
-
expect(out.string).to eq([
|
78
|
-
'<html>',
|
79
|
-
'<style>div { color: red }</style>',
|
80
|
-
'<body>',
|
81
|
-
"#{message.to_json}</body>",
|
82
|
-
"<script>alert('Hi')</script>",
|
83
|
-
'</html>'
|
84
|
-
].join("\n"))
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|