rspec_pacman 0.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 +7 -0
- data/lib/rspec_pacman/version.rb +5 -0
- data/lib/rspec_pacman.rb +97 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e5a325a7866d53da44c81adf62b0f8f3ee195b5e1953376264624b4dbc95c787
|
4
|
+
data.tar.gz: 2535f05d466176c822c73643fcfa1a8b9ff255a2ecea58800ffc3b0d3a35096f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 69391596c90b224cf7a2eed1648b6bcec4cec8b258601805cbdffeb3a3289a056550e6ff9f1875ecda55d5cfb604df9d290667ad442ffdb7f8554bc51fc3ceb0
|
7
|
+
data.tar.gz: 66df5a53ea5cfe18aa5fbd1eb5424f6c65fad76bd39e948e51f0a79a5a3ae5a1c7a1a4e10783e92cf8c1ddb9d6aa9f0dd46bdda01065a1f2ae00f48ad5ee0808
|
data/lib/rspec_pacman.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "rspec_pacman/version"
|
4
|
+
require 'rspec/core/formatters/base_text_formatter'
|
5
|
+
require 'io/console'
|
6
|
+
|
7
|
+
module RspecPacman
|
8
|
+
class PacmanFormatter < RSpec::Core::Formatters::BaseTextFormatter
|
9
|
+
RSpec::Core::Formatters.register self, :example_started, :example_passed, :example_failed, :example_pending, :dump_summary, :start
|
10
|
+
|
11
|
+
FULL_WIDTH_SPACE = "γ"
|
12
|
+
CURRENT_EXECUTION_MARK = "π‘"
|
13
|
+
|
14
|
+
def initialize(output)
|
15
|
+
super
|
16
|
+
@total_examples = 0
|
17
|
+
@completed_examples = 0
|
18
|
+
@progress_bar = []
|
19
|
+
@terminal_width = IO.console.winsize[1] rescue 80
|
20
|
+
@last_printed_lines = 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def start(notification)
|
24
|
+
@total_examples = notification.count
|
25
|
+
@progress_bar = Array.new(@total_examples) { "γ»" }
|
26
|
+
update_progress
|
27
|
+
end
|
28
|
+
|
29
|
+
def display_width(str)
|
30
|
+
str.each_char.map { |char| char.bytesize == 1 ? 1 : 2 }.sum
|
31
|
+
end
|
32
|
+
|
33
|
+
def update_progress
|
34
|
+
completed_bar = @progress_bar[0...@completed_examples].join
|
35
|
+
rest_bar = RSpec::Core::Formatters::ConsoleCodes.wrap(@progress_bar[@completed_examples..-1].join, :yellow)
|
36
|
+
all_bar = "#{completed_bar}#{rest_bar}"
|
37
|
+
|
38
|
+
prefix = "total: #{@total_examples} |"
|
39
|
+
suffix = "|"
|
40
|
+
extra_length = display_width(prefix) + display_width(suffix)
|
41
|
+
|
42
|
+
max_bar_length = @terminal_width - extra_length
|
43
|
+
|
44
|
+
lines = []
|
45
|
+
current_line = prefix
|
46
|
+
all_bar.each_char do |char|
|
47
|
+
if display_width(current_line + char + suffix) > @terminal_width
|
48
|
+
lines << current_line
|
49
|
+
current_line = " " * display_width(prefix)
|
50
|
+
end
|
51
|
+
current_line += char
|
52
|
+
end
|
53
|
+
lines << current_line + suffix
|
54
|
+
|
55
|
+
output.print "\e[#{@last_printed_lines}F\e[J" if @last_printed_lines > 0
|
56
|
+
|
57
|
+
lines.each do |line|
|
58
|
+
output.puts line
|
59
|
+
end
|
60
|
+
|
61
|
+
@last_printed_lines = lines.size
|
62
|
+
output.flush
|
63
|
+
end
|
64
|
+
|
65
|
+
def example_started(notification)
|
66
|
+
@progress_bar[@completed_examples] = CURRENT_EXECUTION_MARK
|
67
|
+
update_progress
|
68
|
+
end
|
69
|
+
|
70
|
+
def example_passed(notification)
|
71
|
+
@progress_bar[@completed_examples] = FULL_WIDTH_SPACE
|
72
|
+
@completed_examples += 1
|
73
|
+
update_progress
|
74
|
+
end
|
75
|
+
|
76
|
+
def example_failed(notification)
|
77
|
+
@progress_bar[@completed_examples] = RSpec::Core::Formatters::ConsoleCodes.wrap("γ»", :red)
|
78
|
+
@completed_examples += 1
|
79
|
+
update_progress
|
80
|
+
end
|
81
|
+
|
82
|
+
def example_pending(notification)
|
83
|
+
@progress_bar[@completed_examples] = RSpec::Core::Formatters::ConsoleCodes.wrap("γ»", :yellow)
|
84
|
+
@completed_examples += 1
|
85
|
+
update_progress
|
86
|
+
end
|
87
|
+
|
88
|
+
def dump_summary(summary)
|
89
|
+
output.puts "\n"
|
90
|
+
output.puts "Result"
|
91
|
+
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("β
Success: #{summary.example_count - summary.failure_count - summary.pending_count}", :blue)
|
92
|
+
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("β Failed: #{summary.failure_count}", :red)
|
93
|
+
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("βΈοΈ Pending: #{summary.pending_count}", :yellow)
|
94
|
+
output.puts "Total Time: #{summary.duration.round(2)}η§"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_pacman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- topi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: This is a Gem that makes the display while running RSpec look like Pacman.
|
28
|
+
email:
|
29
|
+
- karubona.ra247@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/rspec_pacman.rb
|
35
|
+
- lib/rspec_pacman/version.rb
|
36
|
+
homepage: https://github.com/topi0247
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
allowed_push_host: https://rubygems.org
|
41
|
+
homepage_uri: https://github.com/topi0247
|
42
|
+
source_code_uri: https://github.com/topi0247/rspec_pacman
|
43
|
+
changelog_uri: https://github.com/topi0247/rspec_pacman/blob/main/CHANGELOG.md
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.6.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.5.3
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Gem that makes RSpec execution display look like Pacman
|
63
|
+
test_files: []
|