cucumber-html-formatter 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
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/cucumber-react.css' do
19
+ expect(subject.css).to eq('whatever content')
20
+ expect(File).to have_received(:read).with(/.*\/assets\/cucumber-react\.css$/)
21
+ end
22
+ end
23
+
24
+ context '.script' do
25
+ it 'reads the content of assets/cucumber-html\.js' do
26
+ expect(subject.script).to eq('whatever content')
27
+ expect(File).to have_received(:read).with(/.*\/assets\/cucumber-html\.js$/)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,95 @@
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({
45
+ id: 'some-random-uid'
46
+ })
47
+ })
48
+ end
49
+
50
+ it 'raises an exception if the message is not a Cucumber::Messages::Envelope instance' do
51
+ expect { subject.write_message('Ho hi !') }.to raise_exception(Cucumber::HTMLFormatter::MessageExpected)
52
+ end
53
+
54
+ it 'appends the message to out' do
55
+ subject.write_message(message)
56
+ expect(out.string).to eq(%|{"pickle":{"id":"some-random-uid"}}|)
57
+ end
58
+
59
+ it 'adds commas between the messages' do
60
+ subject.write_message(message)
61
+ subject.write_message(message)
62
+
63
+ expect(out.string).to eq(%|{"pickle":{"id":"some-random-uid"}},\n{"pickle":{"id":"some-random-uid"}}|)
64
+ end
65
+ end
66
+
67
+ context '.write_post_message' do
68
+ it 'outputs the template end' do
69
+ subject.write_post_message()
70
+ expect(out.string).to eq("</body>\n<script>alert('Hi')</script>\n</html>")
71
+ end
72
+ end
73
+
74
+ context '.process_messages' do
75
+ let(:message) do
76
+ Cucumber::Messages::Envelope.new({
77
+ pickle: Cucumber::Messages::Pickle.new({
78
+ id: 'some-random-uid'
79
+ })
80
+ })
81
+ end
82
+
83
+ it 'produces the full html report' do
84
+ subject.process_messages([message])
85
+ expect(out.string).to eq([
86
+ '<html>',
87
+ '<style>div { color: red }</style>',
88
+ '<body>',
89
+ '{"pickle":{"id":"some-random-uid"}}</body>',
90
+ "<script>alert('Hi')</script>",
91
+ '</html>'
92
+ ].join("\n"))
93
+ end
94
+ end
95
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-html-formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Vincent Prêtre
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cucumber-messages
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 10.0.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '10.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 10.0.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '13.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 13.0.1
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '13.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 13.0.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.9'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.9.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.9'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.9.0
73
+ description: HTML formatter for Cucumber
74
+ email: cukes@googlegroups.com
75
+ executables:
76
+ - cucumber-html-formatter
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - assets/cucumber-html.js
81
+ - assets/cucumber-react.css
82
+ - assets/index.mustache.html
83
+ - bin/cucumber-html-formatter
84
+ - lib/cucumber/html_formatter.rb
85
+ - lib/cucumber/html_formatter/assets_loader.rb
86
+ - lib/cucumber/html_formatter/template_writer.rb
87
+ - spec/capture_warnings.rb
88
+ - spec/html-formatter/assets_loader_spec.rb
89
+ - spec/html-formatter/template_writer_spec.rb
90
+ - spec/html_formatter_spec.rb
91
+ homepage: https://github.com/cucumber/html-formatter-ruby
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ bug_tracker_uri: https://github.com/cucumber/cucumber/issues
96
+ changelog_uri: https://github.com/cucumber/cucumber/blob/master/gherkin/CHANGELOG.md
97
+ documentation_uri: https://cucumber.io/docs/gherkin/
98
+ mailing_list_uri: https://groups.google.com/forum/#!forum/cukes
99
+ source_code_uri: https://github.com/cucumber/cucumber/blob/master/gherkin/ruby
100
+ post_install_message:
101
+ rdoc_options:
102
+ - "--charset=UTF-8"
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '2.3'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.7.6.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: cucumber-html-formatter-4.3.0
121
+ test_files:
122
+ - spec/html-formatter/template_writer_spec.rb
123
+ - spec/html-formatter/assets_loader_spec.rb
124
+ - spec/capture_warnings.rb
125
+ - spec/html_formatter_spec.rb