betterp 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/.rubocop.yml +4 -14
- data/Gemfile +9 -0
- data/Gemfile.lock +107 -0
- data/LICENSE +1 -1
- data/Makefile +1 -0
- data/betterp.gemspec +9 -11
- data/doc/testp.rb +1 -1
- data/lib/betterp/configuration.rb +48 -0
- data/lib/betterp/output.rb +40 -53
- data/lib/betterp/source.rb +1 -0
- data/lib/betterp/timed_block.rb +20 -0
- data/lib/betterp/version.rb +1 -1
- data/lib/betterp.rb +16 -2
- data/lib/kernel.rb +16 -8
- data/rspec-documentation/pages/000-Introduction.md +16 -0
- data/rspec-documentation/pages/010-Usage.md +43 -0
- data/rspec-documentation/pages/500-License.md +11 -0
- data/rspec-documentation/spec_helper.rb +33 -0
- metadata +27 -88
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ea0ef4e30131dd17a73ccf0a81c9597b78f5d7538bbaf17e5aae17eae0216d6
|
4
|
+
data.tar.gz: 3546052c741f0687e386488a4e6e435344dffb8d725ec6d9270006434b453d44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2776e06b838c9f24a3a62828cb1a0994ebb1971bc86ca1e551d7833cd5617a97e7da7ba196982767248a7916214336ef759ad16ff9a222b69d74a9ad9c1908da
|
7
|
+
data.tar.gz: 71c3479e6eabe34c9bacefb184a58dec62e7c5e68cb2e0ec426ff985ad180a0b404a82c3b1b7cd35507fbc06b398fae2a30fe44e39a963db9a675913028a09cb
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,18 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Style/StringLiterals:
|
5
|
-
Exclude:
|
6
|
-
- 'lib/betterp/output.rb'
|
7
|
-
|
8
|
-
Style/FormatString:
|
9
|
-
Exclude:
|
10
|
-
- 'lib/betterp/output.rb'
|
11
|
-
|
12
|
-
Style/FormatStringToken:
|
13
|
-
Exclude:
|
14
|
-
- 'lib/betterp/output.rb'
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
15
4
|
|
16
5
|
AllCops:
|
6
|
+
NewCops: enable
|
17
7
|
Exclude:
|
18
8
|
- 'bin/**/*'
|
data/Gemfile
CHANGED
@@ -6,3 +6,12 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
6
6
|
|
7
7
|
# Specify your gem's dependencies in betterp.gemspec
|
8
8
|
gemspec
|
9
|
+
|
10
|
+
gem 'rake', '~> 13.0'
|
11
|
+
gem 'rspec', '~> 3.12'
|
12
|
+
gem 'rspec-documentation', '~> 0.0.11'
|
13
|
+
gem 'rspec-its', '~> 1.3'
|
14
|
+
gem 'rubocop', '~> 1.57'
|
15
|
+
gem 'rubocop-rake', '~> 0.6.0'
|
16
|
+
gem 'rubocop-rspec', '~> 2.24'
|
17
|
+
gem 'strong_versions', '~> 0.4.5'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
betterp (0.1.8)
|
5
|
+
paintbrush (~> 0.1.3)
|
6
|
+
rouge (~> 4.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
base64 (0.1.1)
|
13
|
+
concurrent-ruby (1.2.2)
|
14
|
+
diff-lcs (1.5.0)
|
15
|
+
htmlbeautifier (1.4.2)
|
16
|
+
i18n (1.14.1)
|
17
|
+
concurrent-ruby (~> 1.0)
|
18
|
+
json (2.6.3)
|
19
|
+
kramdown (2.4.0)
|
20
|
+
rexml
|
21
|
+
kramdown-parser-gfm (1.1.0)
|
22
|
+
kramdown (~> 2.0)
|
23
|
+
language_server-protocol (3.17.0.3)
|
24
|
+
nokogiri (1.15.4-x86_64-linux)
|
25
|
+
racc (~> 1.4)
|
26
|
+
paint (2.3.0)
|
27
|
+
paintbrush (0.1.3)
|
28
|
+
parallel (1.23.0)
|
29
|
+
parser (3.2.2.4)
|
30
|
+
ast (~> 2.4.1)
|
31
|
+
racc
|
32
|
+
racc (1.7.1)
|
33
|
+
rainbow (3.1.1)
|
34
|
+
rake (13.0.6)
|
35
|
+
regexp_parser (2.8.2)
|
36
|
+
rexml (3.2.6)
|
37
|
+
rouge (4.2.0)
|
38
|
+
rspec (3.12.0)
|
39
|
+
rspec-core (~> 3.12.0)
|
40
|
+
rspec-expectations (~> 3.12.0)
|
41
|
+
rspec-mocks (~> 3.12.0)
|
42
|
+
rspec-core (3.12.2)
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-documentation (0.0.11)
|
45
|
+
htmlbeautifier (~> 1.4)
|
46
|
+
kramdown (~> 2.4)
|
47
|
+
kramdown-parser-gfm (~> 1.1)
|
48
|
+
nokogiri (~> 1.15)
|
49
|
+
paintbrush (~> 0.1.3)
|
50
|
+
rouge (~> 4.1)
|
51
|
+
rspec (~> 3.12)
|
52
|
+
rspec-expectations (3.12.3)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.12.0)
|
55
|
+
rspec-its (1.3.0)
|
56
|
+
rspec-core (>= 3.0.0)
|
57
|
+
rspec-expectations (>= 3.0.0)
|
58
|
+
rspec-mocks (3.12.6)
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
+
rspec-support (~> 3.12.0)
|
61
|
+
rspec-support (3.12.1)
|
62
|
+
rubocop (1.57.1)
|
63
|
+
base64 (~> 0.1.1)
|
64
|
+
json (~> 2.3)
|
65
|
+
language_server-protocol (>= 3.17.0)
|
66
|
+
parallel (~> 1.10)
|
67
|
+
parser (>= 3.2.2.4)
|
68
|
+
rainbow (>= 2.2.2, < 4.0)
|
69
|
+
regexp_parser (>= 1.8, < 3.0)
|
70
|
+
rexml (>= 3.2.5, < 4.0)
|
71
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
72
|
+
ruby-progressbar (~> 1.7)
|
73
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
74
|
+
rubocop-ast (1.29.0)
|
75
|
+
parser (>= 3.2.1.0)
|
76
|
+
rubocop-capybara (2.19.0)
|
77
|
+
rubocop (~> 1.41)
|
78
|
+
rubocop-factory_bot (2.24.0)
|
79
|
+
rubocop (~> 1.33)
|
80
|
+
rubocop-rake (0.6.0)
|
81
|
+
rubocop (~> 1.0)
|
82
|
+
rubocop-rspec (2.24.1)
|
83
|
+
rubocop (~> 1.33)
|
84
|
+
rubocop-capybara (~> 2.17)
|
85
|
+
rubocop-factory_bot (~> 2.22)
|
86
|
+
ruby-progressbar (1.13.0)
|
87
|
+
strong_versions (0.4.5)
|
88
|
+
i18n (>= 0.5)
|
89
|
+
paint (~> 2.0)
|
90
|
+
unicode-display_width (2.5.0)
|
91
|
+
|
92
|
+
PLATFORMS
|
93
|
+
x86_64-linux
|
94
|
+
|
95
|
+
DEPENDENCIES
|
96
|
+
betterp!
|
97
|
+
rake (~> 13.0)
|
98
|
+
rspec (~> 3.12)
|
99
|
+
rspec-documentation (~> 0.0.11)
|
100
|
+
rspec-its (~> 1.3)
|
101
|
+
rubocop (~> 1.57)
|
102
|
+
rubocop-rake (~> 0.6.0)
|
103
|
+
rubocop-rspec (~> 2.24)
|
104
|
+
strong_versions (~> 0.4.5)
|
105
|
+
|
106
|
+
BUNDLED WITH
|
107
|
+
2.4.14
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright 2018 Robert Farrell
|
1
|
+
Copyright 2018-2023 Robert Farrell
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
4
|
|
data/Makefile
CHANGED
data/betterp.gemspec
CHANGED
@@ -9,13 +9,15 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.licenses = ['MIT']
|
10
10
|
spec.version = Betterp::VERSION
|
11
11
|
spec.authors = ['Bob Farrell']
|
12
|
-
spec.email = ['bob
|
12
|
+
spec.email = ['git@bob.frl']
|
13
13
|
|
14
|
-
spec.summary = 'Enhanced debug output'
|
15
|
-
spec.description = '
|
14
|
+
spec.summary = 'Enhanced colorized debug output'
|
15
|
+
spec.description = 'Overwrites Kernel#p to provide output with file path, line numbers, and profiling. '
|
16
16
|
spec.homepage = 'https://github.com/bobf/betterp'
|
17
17
|
|
18
|
-
spec.
|
18
|
+
spec.required_ruby_version = '>= 3.2'
|
19
|
+
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
21
|
`git ls-files -z`.split("\x0").reject do |f|
|
20
22
|
f.match(%r{^(test|spec|features)/})
|
21
23
|
end
|
@@ -24,12 +26,8 @@ Gem::Specification.new do |spec|
|
|
24
26
|
spec.executables = []
|
25
27
|
spec.require_paths = ['lib']
|
26
28
|
|
27
|
-
spec.add_runtime_dependency '
|
29
|
+
spec.add_runtime_dependency 'paintbrush', '~> 0.1.3'
|
30
|
+
spec.add_runtime_dependency 'rouge', '~> 4.2'
|
28
31
|
|
29
|
-
spec.
|
30
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
-
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
33
|
-
spec.add_development_dependency 'rubocop', '~> 0.77.0'
|
34
|
-
spec.add_development_dependency 'strong_versions', '~> 0.3.2'
|
32
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
35
33
|
end
|
data/doc/testp.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Betterp
|
4
|
+
# Misc. configuration options for Betterp library.
|
5
|
+
class Configuration
|
6
|
+
attr_accessor :test_mode
|
7
|
+
attr_writer :profiling_thresholds
|
8
|
+
|
9
|
+
# Configures colors to use for different profiling durations, defines low, medium, and high
|
10
|
+
# colors.
|
11
|
+
class ProfilingThreshold
|
12
|
+
attr_writer :low, :high
|
13
|
+
|
14
|
+
def color(duration)
|
15
|
+
return :green if low?(duration)
|
16
|
+
return :yellow if medium?(duration)
|
17
|
+
|
18
|
+
:red if high?(duration)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def low?(duration)
|
24
|
+
duration <= low
|
25
|
+
end
|
26
|
+
|
27
|
+
def medium?(duration)
|
28
|
+
duration.between?(low, high)
|
29
|
+
end
|
30
|
+
|
31
|
+
def high?(duration)
|
32
|
+
duration >= high
|
33
|
+
end
|
34
|
+
|
35
|
+
def low
|
36
|
+
@low || 10
|
37
|
+
end
|
38
|
+
|
39
|
+
def high
|
40
|
+
@high || 100
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def profiling_threshold
|
45
|
+
@profiling_threshold ||= ProfilingThreshold.new
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/betterp/output.rb
CHANGED
@@ -1,27 +1,48 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Betterp
|
4
|
+
# Transforms default output from `Kernel.p` into enhanced, colorized output with source
|
5
|
+
# filename, line number, method name, and duration when used with a block.
|
4
6
|
class Output
|
5
|
-
COLORS = %i[red green yellow blue
|
6
|
-
EFFECTS = [:bright, nil].freeze
|
7
|
+
COLORS = %i[red green yellow blue purple cyan red_b green_b yellow_b blue_b purple_b cyan_b].freeze
|
7
8
|
|
8
|
-
def initialize(raw, source, options = {})
|
9
|
+
def initialize(raw, source, duration, options = {})
|
9
10
|
@raw = raw
|
10
11
|
@source = source
|
12
|
+
@duration = duration
|
11
13
|
@color = color
|
12
|
-
@effect = effect
|
13
14
|
@pretty = options.fetch(:pretty, false)
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
+
def formatted(args)
|
17
18
|
(@pretty ? args : args.map(&:inspect)).map do |arg|
|
18
|
-
|
19
|
-
|
19
|
+
output = [
|
20
|
+
header, colorized_prefix, colorized_duration, caller_code, highlighted(pretty(arg))
|
21
|
+
].compact.join(' ').chomp
|
22
|
+
"#{output}\n"
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
26
|
private
|
24
27
|
|
28
|
+
def highlighted(output)
|
29
|
+
formatter = Rouge::Formatters::Terminal256.new
|
30
|
+
lexer = Rouge::Lexers::Ruby.new
|
31
|
+
formatter.format(lexer.lex(output))
|
32
|
+
end
|
33
|
+
|
34
|
+
def colorized_duration
|
35
|
+
return nil if @duration.nil?
|
36
|
+
|
37
|
+
duration = @duration * 1000
|
38
|
+
color = Betterp.configuration.profiling_threshold.color(duration)
|
39
|
+
Paintbrush.paintbrush { "[#{send color, "#{Float(format('%.2g', duration))}ms"}]" }
|
40
|
+
end
|
41
|
+
|
42
|
+
def colorized_pretty(arg)
|
43
|
+
Paintbrush.paintbrush { cyan pretty(arg) }
|
44
|
+
end
|
45
|
+
|
25
46
|
def pretty(arg)
|
26
47
|
return arg unless @pretty
|
27
48
|
|
@@ -29,22 +50,18 @@ module Betterp
|
|
29
50
|
PP.pp(arg, io)
|
30
51
|
return io.string unless io.string.include?("\n")
|
31
52
|
|
32
|
-
"\n
|
53
|
+
"\n#{io.string.split("\n").map { |line| " #{line}" }.join("\n")}"
|
33
54
|
end
|
34
55
|
|
35
56
|
def caller_code
|
36
|
-
return
|
57
|
+
return nil unless @raw.include?(':')
|
37
58
|
|
38
59
|
path, line, *_rest = @raw.split(':')
|
39
|
-
return
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
open: ['{ ', :white, :default],
|
45
|
-
code: [find_caller(line.to_i, path).to_s.strip, :cyan],
|
46
|
-
close: [' } ', :white, :default]
|
47
|
-
]
|
60
|
+
return nil unless Pathname.new(path).readable? && line.to_i.positive?
|
61
|
+
|
62
|
+
Paintbrush.paintbrush do
|
63
|
+
white "{ #{blue find_caller(line.to_i, path).to_s.strip} }"
|
64
|
+
end
|
48
65
|
end
|
49
66
|
|
50
67
|
def find_caller(line_number, path)
|
@@ -54,49 +71,19 @@ module Betterp
|
|
54
71
|
end
|
55
72
|
|
56
73
|
def header
|
57
|
-
|
58
|
-
+"%{standard}%{relevant}",
|
59
|
-
:default,
|
60
|
-
standard: [' ', :default],
|
61
|
-
relevant: ['•••• ', @color, @effect]
|
62
|
-
]
|
74
|
+
Paintbrush.paintbrush { send @color, '####' }
|
63
75
|
end
|
64
76
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
'%{line_no}',
|
70
|
-
'%{method_pointer}',
|
71
|
-
'%{method_name}',
|
72
|
-
'%{terminator}'
|
73
|
-
].join
|
74
|
-
end
|
75
|
-
|
76
|
-
def colorize(string)
|
77
|
-
Paint % [string, :default, mapping]
|
78
|
-
end
|
79
|
-
|
80
|
-
def mapping
|
81
|
-
{
|
82
|
-
path: [@source.path],
|
83
|
-
line_no: [@source.line_no],
|
84
|
-
method_name: [@source.method_name],
|
85
|
-
|
86
|
-
method_pointer: [' => ', :reset, :bright],
|
87
|
-
separator: [':', :reset],
|
88
|
-
terminator: [' :: ', :reset]
|
89
|
-
}
|
77
|
+
def colorized_prefix
|
78
|
+
Paintbrush.paintbrush do
|
79
|
+
"#{blue_b @source.path}:#{cyan_b @source.line_no} => [#{green "##{@source.method_name}"}]"
|
80
|
+
end
|
90
81
|
end
|
91
82
|
|
92
83
|
def color
|
93
84
|
COLORS[hash(@raw).hex % COLORS.size]
|
94
85
|
end
|
95
86
|
|
96
|
-
def effect
|
97
|
-
EFFECTS[hash(hash(@raw)).hex % EFFECTS.size]
|
98
|
-
end
|
99
|
-
|
100
87
|
def hash(input)
|
101
88
|
Digest::MD5.hexdigest(input)
|
102
89
|
end
|
data/lib/betterp/source.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Betterp
|
4
|
+
# Executes a block and returns the block result and duration.
|
5
|
+
class TimedBlock
|
6
|
+
def initialize(block:)
|
7
|
+
@block = block
|
8
|
+
end
|
9
|
+
|
10
|
+
def result
|
11
|
+
start = Time.now.utc
|
12
|
+
block_result = block.call
|
13
|
+
[block_result, Time.now.utc - start]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :block
|
19
|
+
end
|
20
|
+
end
|
data/lib/betterp/version.rb
CHANGED
data/lib/betterp.rb
CHANGED
@@ -2,18 +2,32 @@
|
|
2
2
|
|
3
3
|
require 'digest'
|
4
4
|
require 'pathname'
|
5
|
-
require 'pp'
|
5
|
+
require 'pp' # rubocop:disable Lint/RedundantRequireStatement
|
6
6
|
require 'stringio'
|
7
|
+
require 'time'
|
7
8
|
|
8
|
-
require '
|
9
|
+
require 'paintbrush'
|
10
|
+
require 'rouge'
|
9
11
|
|
10
12
|
require 'kernel'
|
13
|
+
require 'betterp/configuration'
|
11
14
|
require 'betterp/output'
|
12
15
|
require 'betterp/source'
|
16
|
+
require 'betterp/timed_block'
|
13
17
|
require 'betterp/version'
|
14
18
|
|
19
|
+
# Enhanced debug output library.
|
15
20
|
module Betterp
|
16
21
|
def self.root
|
17
22
|
Pathname.new(File.dirname(__dir__))
|
18
23
|
end
|
24
|
+
|
25
|
+
def self.configuration
|
26
|
+
@configuration || Configuration.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.configure
|
30
|
+
@configuration = Configuration.new
|
31
|
+
yield @configuration
|
32
|
+
end
|
19
33
|
end
|
data/lib/kernel.rb
CHANGED
@@ -1,23 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Overrides for `p` and `pp` Kernel methods.
|
3
4
|
module Kernel
|
4
|
-
def p(*args)
|
5
|
+
def p(*args, &block)
|
5
6
|
raw = caller(1..1).first
|
6
|
-
_betterp(raw, args)
|
7
|
+
_betterp(raw, args, block)
|
7
8
|
end
|
8
9
|
|
9
|
-
def pp(*args)
|
10
|
+
def pp(*args, &block)
|
10
11
|
raw = caller(1..1).first
|
11
|
-
_betterp(raw, args, pretty: true)
|
12
|
+
_betterp(raw, args, block, pretty: true)
|
12
13
|
end
|
13
14
|
|
14
|
-
def _betterp(raw, args, options = {})
|
15
|
+
def _betterp(raw, args, block, options = {}) # rubocop:disable Metrics/AbcSize
|
15
16
|
source = Betterp::Source.new(raw, Dir.pwd)
|
16
17
|
pretty = options.fetch(:pretty, false)
|
17
18
|
|
18
|
-
Betterp::
|
19
|
-
|
20
|
-
|
19
|
+
block_result, duration = Betterp::TimedBlock.new(block:).result unless block.nil?
|
20
|
+
|
21
|
+
output = Betterp::Output.new(raw, source, duration, pretty:)
|
22
|
+
formatted_output = output.formatted(block.nil? ? args : [block_result]).join("\n")
|
23
|
+
|
24
|
+
return formatted_output if Betterp.configuration.test_mode
|
25
|
+
|
26
|
+
$stdout.write(formatted_output)
|
27
|
+
|
28
|
+
return block_result unless block.nil?
|
21
29
|
|
22
30
|
args.size > 1 ? args : args.first
|
23
31
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Introduction
|
2
|
+
|
3
|
+
_Betterp_ overwrites the default `p` and `pp` _Kernel_ methods to provide enhanced debug output including:
|
4
|
+
|
5
|
+
* Source file and line number of invocation.
|
6
|
+
* Colorized tags to help track debug output in noisy server logs.
|
7
|
+
* Profiling information (pass a block to `p` or `pp` to output call duration).
|
8
|
+
|
9
|
+
|
10
|
+
```rspec:ansi
|
11
|
+
require 'betterp'
|
12
|
+
|
13
|
+
subject { p 'hello' }
|
14
|
+
|
15
|
+
it { is_expected.to include 'hello' }
|
16
|
+
```
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Usage
|
2
|
+
|
3
|
+
Typical usage of _Betterp_ is identical to usage of `Kernel.p` and `Kernel.pp`, simply require `betterp` somewhere in your project and call `#p` or `#pp` as normal.
|
4
|
+
|
5
|
+
```rspec:ansi
|
6
|
+
subject { p 'hi' }
|
7
|
+
|
8
|
+
it { is_expected.to include 'hi' }
|
9
|
+
```
|
10
|
+
|
11
|
+
```rspec:ansi
|
12
|
+
subject { pp({ foo: 'bar', baz: 'qux' }) }
|
13
|
+
|
14
|
+
it { is_expected.to include 'qux' }
|
15
|
+
```
|
16
|
+
|
17
|
+
## Profiling
|
18
|
+
|
19
|
+
Both `#p` and `#pp` can receive a block. If a block is received, the block will be timed and the execution time will be included in the output. The result of the block is returned to the caller.
|
20
|
+
|
21
|
+
```rspec:ansi
|
22
|
+
subject do
|
23
|
+
p { sleep(0.1); 'some return value' }
|
24
|
+
end
|
25
|
+
|
26
|
+
it { is_expected.to match /\dms/ }
|
27
|
+
```
|
28
|
+
|
29
|
+
The execution time is highlighted in `green`, `yellow`, or `red` depending on execution time.
|
30
|
+
|
31
|
+
The default thresholds are:
|
32
|
+
|
33
|
+
* `low`: `< 10ms`.
|
34
|
+
* `high`: `> 100ms`.
|
35
|
+
|
36
|
+
The thresholds can be modified:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
Betterp.configure do |config|
|
40
|
+
config.profiling_threshold.low = 100
|
41
|
+
config.profiling_threshold.high = 1000
|
42
|
+
end
|
43
|
+
```
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# License
|
2
|
+
|
3
|
+
## MIT
|
4
|
+
|
5
|
+
Copyright 2018-2023 Robert Farrell
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'betterp'
|
4
|
+
|
5
|
+
Betterp.configure do |config|
|
6
|
+
config.test_mode = true
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec::Documentation.configure do |config|
|
10
|
+
# Force example tabs to have a consistent height to prevent content jumping.
|
11
|
+
# config.consistent_height = false
|
12
|
+
|
13
|
+
# Set a maximum height for example tabs. Tabs will scroll if content exceeds this value.
|
14
|
+
# config.max_height = "30rem"
|
15
|
+
|
16
|
+
# Enable or disable the table of contents for each page. This renders a list of all headings in
|
17
|
+
# the page, except the main heading.
|
18
|
+
# config.table_of_contents = true
|
19
|
+
|
20
|
+
# Enable or disable the index search above the navigation tree.
|
21
|
+
# config.index_search = true
|
22
|
+
|
23
|
+
config.context do
|
24
|
+
# Define global context here, e.g. add some `let` blocks to make them available in every example.
|
25
|
+
#
|
26
|
+
# let(:foo) { 'bar' }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
# Define RSpec configuration here.
|
32
|
+
# Note that your main `spec/spec_helper.rb` is not loaded unless you require it in this file.
|
33
|
+
end
|
metadata
CHANGED
@@ -1,116 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betterp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Farrell
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: paintbrush
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.1.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.1.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rouge
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.16'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '10.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '10.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec-its
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.2'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.2'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.77.0
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.77.0
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: strong_versions
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.3.2
|
104
|
-
type: :development
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
105
35
|
prerelease: false
|
106
36
|
version_requirements: !ruby/object:Gem::Requirement
|
107
37
|
requirements:
|
108
38
|
- - "~>"
|
109
39
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
111
|
-
description:
|
40
|
+
version: '4.2'
|
41
|
+
description: 'Overwrites Kernel#p to provide output with file path, line numbers,
|
42
|
+
and profiling. '
|
112
43
|
email:
|
113
|
-
- bob
|
44
|
+
- git@bob.frl
|
114
45
|
executables: []
|
115
46
|
extensions: []
|
116
47
|
extra_rdoc_files: []
|
@@ -119,6 +50,7 @@ files:
|
|
119
50
|
- ".rspec"
|
120
51
|
- ".rubocop.yml"
|
121
52
|
- Gemfile
|
53
|
+
- Gemfile.lock
|
122
54
|
- LICENSE
|
123
55
|
- Makefile
|
124
56
|
- README.md
|
@@ -132,15 +64,22 @@ files:
|
|
132
64
|
- doc/images/screenshot.png
|
133
65
|
- doc/testp.rb
|
134
66
|
- lib/betterp.rb
|
67
|
+
- lib/betterp/configuration.rb
|
135
68
|
- lib/betterp/output.rb
|
136
69
|
- lib/betterp/source.rb
|
70
|
+
- lib/betterp/timed_block.rb
|
137
71
|
- lib/betterp/version.rb
|
138
72
|
- lib/kernel.rb
|
73
|
+
- rspec-documentation/pages/000-Introduction.md
|
74
|
+
- rspec-documentation/pages/010-Usage.md
|
75
|
+
- rspec-documentation/pages/500-License.md
|
76
|
+
- rspec-documentation/spec_helper.rb
|
139
77
|
homepage: https://github.com/bobf/betterp
|
140
78
|
licenses:
|
141
79
|
- MIT
|
142
|
-
metadata:
|
143
|
-
|
80
|
+
metadata:
|
81
|
+
rubygems_mfa_required: 'true'
|
82
|
+
post_install_message:
|
144
83
|
rdoc_options: []
|
145
84
|
require_paths:
|
146
85
|
- lib
|
@@ -148,15 +87,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
87
|
requirements:
|
149
88
|
- - ">="
|
150
89
|
- !ruby/object:Gem::Version
|
151
|
-
version: '
|
90
|
+
version: '3.2'
|
152
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
92
|
requirements:
|
154
93
|
- - ">="
|
155
94
|
- !ruby/object:Gem::Version
|
156
95
|
version: '0'
|
157
96
|
requirements: []
|
158
|
-
rubygems_version: 3.
|
159
|
-
signing_key:
|
97
|
+
rubygems_version: 3.4.10
|
98
|
+
signing_key:
|
160
99
|
specification_version: 4
|
161
|
-
summary: Enhanced debug output
|
100
|
+
summary: Enhanced colorized debug output
|
162
101
|
test_files: []
|