codewars-pretty-print 0.0.1
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 +7 -0
- data/.gitignore +2 -0
- data/README.md +4 -0
- data/lib/codewars-pretty-print.rb +52 -0
- data/spec/codewars_pretty_print_spec.rb +54 -0
- data/spec/spec_helper.rb +13 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9af499a077441bea6971ebd37d1aeaa3ac2be027
|
4
|
+
data.tar.gz: c396b0c88e9c752f905c423bf9e05821d1c413bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3ac7eff0d483f15171903607ade6ac9d24c770eda4f74d46fb0c3a22b17d94f4faf168241ed0737f40e13c13183615461ab3265c5fe313c8fe3f473cc569e03
|
7
|
+
data.tar.gz: 72fe004f9be99dc2f885579791bf9cc5cc12a44cbced1ac4dd8c1e1a779c2530adf7be57d373f080737ff73af1e92a78029893eb96e11fc5d0586d56c45961a0
|
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
class TestBuilder
|
3
|
+
|
4
|
+
attr_reader :html, :passed_tests, :failed_tests
|
5
|
+
|
6
|
+
def initialize(output)
|
7
|
+
@html = []
|
8
|
+
@passed_tests = 0
|
9
|
+
@failed_tests = 0
|
10
|
+
to_html(output)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def to_html(output)
|
16
|
+
raise 'No test results to show' if output.nil?
|
17
|
+
output.split("<:LF:>").each do |value|
|
18
|
+
tag = value.split("::>")
|
19
|
+
message = tag[1]
|
20
|
+
x = if tag[0].start_with?("<DESCRIBE")
|
21
|
+
write_desribe(message)
|
22
|
+
elsif tag[0].start_with?("<PASSED")
|
23
|
+
@passed_tests += 1
|
24
|
+
write_it(:'it.passed', message)
|
25
|
+
elsif tag[0].start_with?("<FAILED")
|
26
|
+
@failed_tests += 1
|
27
|
+
write_it(:'it.failed', message)
|
28
|
+
else
|
29
|
+
''
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def write_it(symbol, message)
|
35
|
+
block = []
|
36
|
+
tag = symbol.to_s == 'it.passed' ? 'Passed:' : 'Failed:'
|
37
|
+
block << "<br>"
|
38
|
+
block << "<div class=\"#{symbol}\">"
|
39
|
+
block << "<h3>#{tag} </h3> #{message}"
|
40
|
+
block << '</div>'
|
41
|
+
@html << block
|
42
|
+
end
|
43
|
+
|
44
|
+
def write_desribe(message)
|
45
|
+
block = []
|
46
|
+
block << "<br>"
|
47
|
+
block << '<div class="description-level">'
|
48
|
+
block << "<h3>#{message}</h3>"
|
49
|
+
block << '</div>'
|
50
|
+
@html << block
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/codewars-pretty-print'
|
3
|
+
|
4
|
+
RSpec.describe 'test_builder' do
|
5
|
+
let(:mock_results) { mock_test_result }
|
6
|
+
let(:builder) { TestBuilder.new(mock_results) }
|
7
|
+
|
8
|
+
context 'when results exist' do
|
9
|
+
it 'should access elements as hash' do
|
10
|
+
expect(builder.html).to_not be_nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when no results exist' do
|
15
|
+
let(:mock_results) { nil }
|
16
|
+
|
17
|
+
it 'should render page with no results' do
|
18
|
+
expect { builder }.to raise_error('No test results to show')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'building html' do
|
23
|
+
context 'when all pass exist' do
|
24
|
+
context 'when no nested #describes exists' do
|
25
|
+
it 'should print first line of results with describe' do
|
26
|
+
complete_html = builder.html[0].join("\n")
|
27
|
+
expect(complete_html).to eq("<br>\n<div class=\"description-level\">\n<h3>Basic tests</h3>\n</div>")
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should count all #it tests' do
|
31
|
+
expect(builder.passed_tests).to eq(3)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should count all #failed tests' do
|
35
|
+
expect(builder.failed_tests).to eq(7)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should have 11 blocks in the results html array' do
|
39
|
+
expect(builder.html.size).to eq(11)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should print a #passed test in a passed div' do
|
43
|
+
complete_html = builder.html[1].join("\n")
|
44
|
+
expect(complete_html).to eq("<br>\n<div class=\"it.passed\">\n<h3>Passed: </h3> Test Passed: Value == 3\n</div>")
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should print a #failed test in a failed div' do
|
48
|
+
complete_html = builder.html[2].join("\n")
|
49
|
+
expect(complete_html).to eq("<br>\n<div class=\"it.failed\">\n<h3>Failed: </h3> Expected: 1, instead got: 3\n</div>")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.expect_with :rspec do |expectations|
|
3
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
4
|
+
end
|
5
|
+
config.mock_with :rspec do |mocks|
|
6
|
+
mocks.verify_partial_doubles = true
|
7
|
+
end
|
8
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
9
|
+
end
|
10
|
+
|
11
|
+
def mock_test_result
|
12
|
+
"<DESCRIBE::>Basic tests<:LF:><PASSED::>Test Passed: Value == 3<:LF:><FAILED::>Expected: 1, instead got: 3<:LF:><FAILED::>Expected: 4, instead got: 3<:LF:><FAILED::>Expected: 2, instead got: 3<:LF:><PASSED::>Test Passed: Value == 3<:LF:><FAILED::>Expected: 2, instead got: 3<:LF:><FAILED::>Expected: 26, instead got: 3<:LF:><FAILED::>Expected: 48, instead got: 3<:LF:><PASSED::>Test Passed:Value == 3<:LF:><FAILED::>Expected: 32, instead got: 3<:LF:><COMPLETEDIN::>"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codewars-pretty-print
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Hender
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: henderjm@tcd.ie
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- README.md
|
21
|
+
- lib/codewars-pretty-print.rb
|
22
|
+
- spec/codewars_pretty_print_spec.rb
|
23
|
+
- spec/spec_helper.rb
|
24
|
+
homepage: http://rubygems.org/gems/codewars-pretty-print
|
25
|
+
licenses:
|
26
|
+
- Nonstandard
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.5.2
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Pretty print codewars cli output
|
48
|
+
test_files: []
|