amazing_print 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +38 -54
- data/CHANGELOG.md +36 -2
- data/Gemfile.lock +48 -50
- data/README.md +20 -11
- data/lib/amazing_print/colorize.rb +1 -3
- data/lib/amazing_print/core_ext/awesome_method_array.rb +4 -4
- data/lib/amazing_print/core_ext/class.rb +1 -1
- data/lib/amazing_print/core_ext/logger.rb +10 -5
- data/lib/amazing_print/core_ext/object.rb +1 -1
- data/lib/amazing_print/custom_defaults.rb +10 -3
- data/lib/amazing_print/ext/action_view.rb +1 -1
- data/lib/amazing_print/ext/active_record.rb +12 -27
- data/lib/amazing_print/ext/active_support.rb +1 -3
- data/lib/amazing_print/ext/mongo_mapper.rb +5 -8
- data/lib/amazing_print/ext/mongoid.rb +2 -6
- data/lib/amazing_print/ext/nobrainer.rb +7 -5
- data/lib/amazing_print/ext/nokogiri.rb +1 -3
- data/lib/amazing_print/ext/ostruct.rb +1 -3
- data/lib/amazing_print/ext/ripple.rb +4 -5
- data/lib/amazing_print/formatter.rb +5 -6
- data/lib/amazing_print/formatters/array_formatter.rb +6 -5
- data/lib/amazing_print/formatters/base_formatter.rb +20 -25
- data/lib/amazing_print/formatters/class_formatter.rb +1 -0
- data/lib/amazing_print/formatters/dir_formatter.rb +1 -0
- data/lib/amazing_print/formatters/file_formatter.rb +1 -0
- data/lib/amazing_print/formatters/hash_formatter.rb +5 -4
- data/lib/amazing_print/formatters/method_formatter.rb +1 -0
- data/lib/amazing_print/formatters/object_formatter.rb +2 -1
- data/lib/amazing_print/formatters/simple_formatter.rb +1 -0
- data/lib/amazing_print/formatters/struct_formatter.rb +2 -1
- data/lib/amazing_print/inspector.rb +29 -5
- data/lib/amazing_print/version.rb +1 -1
- data/lib/amazing_print.rb +2 -6
- data/spec/active_record_helper.rb +11 -0
- data/spec/colors_spec.rb +38 -46
- data/spec/core_ext/logger_spec.rb +42 -18
- data/spec/core_ext/string_spec.rb +2 -2
- data/spec/ext/action_controller_spec.rb +4 -4
- data/spec/ext/action_view_spec.rb +6 -1
- data/spec/ext/active_model_spec.rb +37 -0
- data/spec/ext/active_record_spec.rb +44 -23
- data/spec/ext/active_support_spec.rb +13 -4
- data/spec/ext/mongo_mapper_spec.rb +16 -12
- data/spec/ext/mongoid_spec.rb +7 -3
- data/spec/ext/nobrainer_spec.rb +6 -2
- data/spec/ext/nokogiri_spec.rb +3 -3
- data/spec/ext/ripple_spec.rb +6 -2
- data/spec/formats_spec.rb +24 -18
- data/spec/methods_spec.rb +12 -4
- data/spec/misc_spec.rb +15 -10
- data/spec/objects_spec.rb +4 -0
- data/spec/spec_helper.rb +4 -8
- data/spec/support/active_record_data/6_1_diana.txt +109 -0
- data/spec/support/active_record_data/6_1_multi.txt +220 -0
- data/spec/support/ext_verifier.rb +2 -4
- data/spec/support/rails_versions.rb +5 -0
- metadata +80 -60
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Style/HashTransformValues
|
4
|
+
|
3
5
|
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
4
6
|
#
|
5
7
|
# AmazingPrint is freely distributable under the terms of MIT license.
|
@@ -30,9 +32,9 @@ module AmazingPrint
|
|
30
32
|
#------------------------------------------------------------------------------
|
31
33
|
def awesome_nobrainer_class(object)
|
32
34
|
name = "#{awesome_simple(object, :class)} < #{awesome_simple(object.superclass, :class)}"
|
33
|
-
data =
|
35
|
+
data = object.fields.map do |field, options|
|
34
36
|
[field, (options[:type] || Object).to_s.underscore.to_sym]
|
35
|
-
end
|
37
|
+
end.to_h
|
36
38
|
|
37
39
|
name = "class #{awesome_simple(object.to_s, :class)}"
|
38
40
|
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
@@ -44,12 +46,12 @@ module AmazingPrint
|
|
44
46
|
#------------------------------------------------------------------------------
|
45
47
|
def awesome_nobrainer_document(object)
|
46
48
|
data = object.inspectable_attributes.symbolize_keys
|
47
|
-
if object.errors.present?
|
48
|
-
data = { errors: object.errors, attributes: data }
|
49
|
-
end
|
49
|
+
data = { errors: object.errors, attributes: data } if object.errors.present?
|
50
50
|
"#{object} #{awesome_hash(data)}"
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
AmazingPrint::Formatter.include AmazingPrint::NoBrainer
|
56
|
+
|
57
|
+
# rubocop:enable Style/HashTransformValues
|
@@ -34,9 +34,7 @@ module AmazingPrint
|
|
34
34
|
xml.gsub!(%r{(<)(/?[A-Za-z1-9]+)}) { |_tag| "#{Regexp.last_match(1)}#{colorize(Regexp.last_match(2), :keyword)}" }
|
35
35
|
xml.gsub!(/(id|class)="[^"]+"/i) { |id| colorize(id, :class) }
|
36
36
|
xml.gsub!(/>([^<]+)</) do |contents|
|
37
|
-
if contents && !contents.empty?
|
38
|
-
contents = colorize(Regexp.last_match(1), :trueclass)
|
39
|
-
end
|
37
|
+
contents = colorize(Regexp.last_match(1), :trueclass) if contents && !contents.empty?
|
40
38
|
">#{contents}<"
|
41
39
|
end
|
42
40
|
xml
|
@@ -14,9 +14,7 @@ module AmazingPrint
|
|
14
14
|
|
15
15
|
def cast_with_ostruct(object, type)
|
16
16
|
cast = cast_without_ostruct(object, type)
|
17
|
-
if defined?(::OpenStruct) && object.is_a?(::OpenStruct)
|
18
|
-
cast = :open_struct_instance
|
19
|
-
end
|
17
|
+
cast = :open_struct_instance if defined?(::OpenStruct) && object.is_a?(::OpenStruct)
|
20
18
|
cast
|
21
19
|
end
|
22
20
|
|
@@ -18,9 +18,10 @@ module AmazingPrint
|
|
18
18
|
cast = cast_without_ripple(object, type)
|
19
19
|
return cast unless defined?(::Ripple)
|
20
20
|
|
21
|
-
|
21
|
+
case object
|
22
|
+
when ::Ripple::AttributeMethods # Module used to access attributes across documents and embedded documents
|
22
23
|
cast = :ripple_document_instance
|
23
|
-
|
24
|
+
when ::Ripple::Properties # Used to access property metadata on Ripple classes
|
24
25
|
cast = :ripple_document_class
|
25
26
|
end
|
26
27
|
cast
|
@@ -58,9 +59,7 @@ module AmazingPrint
|
|
58
59
|
# Format Ripple class object.
|
59
60
|
#------------------------------------------------------------------------------
|
60
61
|
def awesome_ripple_document_class(object)
|
61
|
-
if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:properties)
|
62
|
-
return object.inspect
|
63
|
-
end
|
62
|
+
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:properties)
|
64
63
|
|
65
64
|
name = "class #{awesome_simple(object.to_s, :class)}"
|
66
65
|
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
|
@@ -24,12 +24,11 @@ module AmazingPrint
|
|
24
24
|
#------------------------------------------------------------------------------
|
25
25
|
def format(object, type = nil)
|
26
26
|
core_class = cast(object, type)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
awesome
|
27
|
+
if core_class == :self
|
28
|
+
awesome_self(object, type) # Catch all that falls back to object.inspect.
|
29
|
+
else
|
30
|
+
send(:"awesome_#{core_class}", object) # Core formatters.
|
31
|
+
end
|
33
32
|
end
|
34
33
|
|
35
34
|
# Hook this when adding custom formatters. Check out lib/amazing_print/ext
|
@@ -8,6 +8,7 @@ module AmazingPrint
|
|
8
8
|
attr_reader :array, :inspector, :options
|
9
9
|
|
10
10
|
def initialize(array, inspector)
|
11
|
+
super()
|
11
12
|
@array = array
|
12
13
|
@inspector = inspector
|
13
14
|
@options = inspector.options
|
@@ -33,7 +34,7 @@ module AmazingPrint
|
|
33
34
|
if options[:multiline]
|
34
35
|
multiline_array
|
35
36
|
else
|
36
|
-
|
37
|
+
"[ #{array.map { |item| inspector.awesome(item) }.join(', ')} ]"
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -114,14 +115,14 @@ module AmazingPrint
|
|
114
115
|
|
115
116
|
meth = begin
|
116
117
|
object.method(name)
|
117
|
-
|
118
|
-
|
118
|
+
rescue NameError, ArgumentError
|
119
|
+
nil
|
119
120
|
end
|
120
121
|
|
121
122
|
meth || begin
|
122
123
|
object.instance_method(name)
|
123
|
-
|
124
|
-
|
124
|
+
rescue NameError
|
125
|
+
nil
|
125
126
|
end
|
126
127
|
end
|
127
128
|
|
@@ -30,7 +30,7 @@ module AmazingPrint
|
|
30
30
|
# ]
|
31
31
|
#------------------------------------------------------------------------------
|
32
32
|
def should_be_limited?
|
33
|
-
options[:limit] || (options[:limit].is_a?(Integer) &&
|
33
|
+
options[:limit] || (options[:limit].is_a?(Integer) && options[:limit].positive?)
|
34
34
|
end
|
35
35
|
|
36
36
|
def get_limit_size
|
@@ -42,14 +42,14 @@ module AmazingPrint
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def limited(data, width, is_hash
|
45
|
+
def limited(data, width, is_hash: false)
|
46
46
|
limit = get_limit_size
|
47
47
|
if data.length <= limit
|
48
48
|
data
|
49
49
|
else
|
50
50
|
# Calculate how many elements to be displayed above and below the separator.
|
51
51
|
head = limit / 2
|
52
|
-
tail = head - (limit - 1) % 2
|
52
|
+
tail = head - ((limit - 1) % 2)
|
53
53
|
|
54
54
|
# Add the proper elements to the temp array and format the separator.
|
55
55
|
temp = data[0, head] + [nil] + data[-tail, tail]
|
@@ -65,23 +65,18 @@ module AmazingPrint
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def method_tuple(method)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
else # See http://ruby-doc.org/core/classes/Method.html#M001902
|
83
|
-
args = (1..method.arity.abs).map { |i| "arg#{i}" }
|
84
|
-
args[-1] = "*#{args[-1]}" if method.arity < 0
|
68
|
+
# See http://readruby.chengguangnan.com/methods#method-objects-parameters
|
69
|
+
# (mirror: http://archive.is/XguCA#selection-3381.1-3381.11)
|
70
|
+
args = method.parameters.inject([]) do |arr, (type, name)|
|
71
|
+
name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
|
72
|
+
arr << case type
|
73
|
+
when :req then name.to_s
|
74
|
+
when :keyreq then "#{name}:"
|
75
|
+
when :key then "*#{name}:"
|
76
|
+
when :opt, :rest then "*#{name}"
|
77
|
+
when :block then "&#{name}"
|
78
|
+
else '?'
|
79
|
+
end
|
85
80
|
end
|
86
81
|
|
87
82
|
# method.to_s formats to handle:
|
@@ -95,7 +90,7 @@ module AmazingPrint
|
|
95
90
|
# #<UnboundMethod: Hello#world>
|
96
91
|
# #<UnboundMethod: Hello#world() /home/hs/code/amazing_print/spec/methods_spec.rb:68>
|
97
92
|
#
|
98
|
-
if method.to_s =~ %r{(Unbound)*Method: ((#<)?[^/#]*)[
|
93
|
+
if method.to_s =~ %r{(Unbound)*Method: ((#<)?[^/#]*)[#.]}
|
99
94
|
unbound = Regexp.last_match(1) && '(unbound)'
|
100
95
|
klass = Regexp.last_match(2)
|
101
96
|
if klass && klass =~ /(\(\w+:\s.*?\))/ # Is this ActiveRecord-style class?
|
@@ -123,21 +118,21 @@ module AmazingPrint
|
|
123
118
|
INDENT_CACHE = (0..100).map { |i| ' ' * i }.map(&:freeze).freeze
|
124
119
|
|
125
120
|
def indent(n = indentation)
|
126
|
-
INDENT_CACHE[n] || ' ' * n
|
121
|
+
INDENT_CACHE[n] || (' ' * n)
|
127
122
|
end
|
128
123
|
|
129
124
|
def outdent
|
130
125
|
i = indentation - options[:indent].abs
|
131
126
|
|
132
|
-
INDENT_CACHE[i] || ' ' * i
|
127
|
+
INDENT_CACHE[i] || (' ' * i)
|
133
128
|
end
|
134
129
|
|
135
130
|
def align(value, width)
|
136
131
|
if options[:multiline]
|
137
132
|
indent_option = options[:indent]
|
138
|
-
if indent_option
|
133
|
+
if indent_option.positive?
|
139
134
|
value.rjust(width)
|
140
|
-
elsif indent_option
|
135
|
+
elsif indent_option.zero?
|
141
136
|
"#{indent}#{value.ljust(width)}"
|
142
137
|
else
|
143
138
|
"#{indent(indentation + indent_option)}#{value.ljust(width)}"
|
@@ -8,6 +8,7 @@ module AmazingPrint
|
|
8
8
|
attr_reader :hash, :inspector, :options
|
9
9
|
|
10
10
|
def initialize(hash, inspector)
|
11
|
+
super()
|
11
12
|
@hash = hash
|
12
13
|
@inspector = inspector
|
13
14
|
@options = inspector.options
|
@@ -55,12 +56,12 @@ module AmazingPrint
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
should_be_limited? ? limited(data, width,
|
59
|
+
should_be_limited? ? limited(data, width, is_hash: true) : data
|
59
60
|
end
|
60
61
|
|
61
62
|
def left_width(keys)
|
62
63
|
result = max_key_width(keys)
|
63
|
-
result += indentation if options[:indent]
|
64
|
+
result += indentation if options[:indent].positive?
|
64
65
|
result
|
65
66
|
end
|
66
67
|
|
@@ -86,11 +87,11 @@ module AmazingPrint
|
|
86
87
|
|
87
88
|
def ruby19_syntax(key, value, width)
|
88
89
|
key[0] = ''
|
89
|
-
align(key, width - 1)
|
90
|
+
"#{align(key, width - 1)}#{colorize(': ', :hash)}#{inspector.awesome(value)}"
|
90
91
|
end
|
91
92
|
|
92
93
|
def pre_ruby19_syntax(key, value, width)
|
93
|
-
align(key, width)
|
94
|
+
"#{align(key, width)}#{colorize(' => ', :hash)}#{inspector.awesome(value)}"
|
94
95
|
end
|
95
96
|
|
96
97
|
def plain_single_line
|
@@ -8,6 +8,7 @@ module AmazingPrint
|
|
8
8
|
attr_reader :object, :variables, :inspector, :options
|
9
9
|
|
10
10
|
def initialize(object, inspector)
|
11
|
+
super()
|
11
12
|
@object = object
|
12
13
|
@variables = object.instance_variables
|
13
14
|
@inspector = inspector
|
@@ -38,7 +39,7 @@ module AmazingPrint
|
|
38
39
|
key = if key =~ /(@\w+)/
|
39
40
|
key.sub(Regexp.last_match(1), colorize(Regexp.last_match(1), :variable))
|
40
41
|
else
|
41
|
-
key.sub(/(attr_\w+)\s(
|
42
|
+
key.sub(/(attr_\w+)\s(:\w+)/, "#{colorize('\\1', :keyword)} #{colorize('\\2', :method)}")
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -8,6 +8,7 @@ module AmazingPrint
|
|
8
8
|
attr_reader :struct, :variables, :inspector, :options
|
9
9
|
|
10
10
|
def initialize(struct, inspector)
|
11
|
+
super()
|
11
12
|
@struct = struct
|
12
13
|
@variables = struct.members
|
13
14
|
@inspector = inspector
|
@@ -38,7 +39,7 @@ module AmazingPrint
|
|
38
39
|
key = if key =~ /(@\w+)/
|
39
40
|
key.sub(Regexp.last_match(1), colorize(Regexp.last_match(1), :variable))
|
40
41
|
else
|
41
|
-
key.sub(/(attr_\w+)\s(
|
42
|
+
key.sub(/(attr_\w+)\s(:\w+)/, "#{colorize('\\1', :keyword)} #{colorize('\\2', :method)}")
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -5,6 +5,9 @@
|
|
5
5
|
# AmazingPrint is freely distributable under the terms of MIT license.
|
6
6
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
7
7
|
#------------------------------------------------------------------------------
|
8
|
+
|
9
|
+
# rubocop:disable Metrics/ClassLength
|
10
|
+
|
8
11
|
require_relative 'indentator'
|
9
12
|
|
10
13
|
module AmazingPrint
|
@@ -13,6 +16,15 @@ module AmazingPrint
|
|
13
16
|
|
14
17
|
AP = :__amazing_print__
|
15
18
|
|
19
|
+
##
|
20
|
+
# Unload the cached dotfile and load it again.
|
21
|
+
#
|
22
|
+
def self.reload_dotfile
|
23
|
+
@@dotfile = nil
|
24
|
+
new.send :load_dotfile
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
16
28
|
def initialize(options = {})
|
17
29
|
@options = {
|
18
30
|
indent: 4, # Number of spaces for indenting.
|
@@ -91,7 +103,7 @@ module AmazingPrint
|
|
91
103
|
if defined? @colorize_stdout
|
92
104
|
@colorize_stdout
|
93
105
|
else
|
94
|
-
@colorize_stdout =
|
106
|
+
@colorize_stdout = $stdout.tty? && (
|
95
107
|
(
|
96
108
|
ENV['TERM'] &&
|
97
109
|
ENV['TERM'] != 'dumb'
|
@@ -147,18 +159,28 @@ module AmazingPrint
|
|
147
159
|
@options.merge!(options)
|
148
160
|
end
|
149
161
|
|
162
|
+
def find_dotfile
|
163
|
+
xdg_config_home = File.expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config'))
|
164
|
+
xdg_config_path = File.join(xdg_config_home, 'aprc') # ${XDG_CONFIG_HOME}/aprc
|
165
|
+
|
166
|
+
return xdg_config_path if File.exist?(xdg_config_path)
|
167
|
+
|
168
|
+
# default to ~/.aprc
|
169
|
+
File.join(ENV['HOME'], '.aprc')
|
170
|
+
end
|
171
|
+
|
150
172
|
# This method needs to be mocked during testing so that it always loads
|
151
173
|
# predictable values
|
152
174
|
#---------------------------------------------------------------------------
|
153
175
|
def load_dotfile
|
154
|
-
dotfile
|
176
|
+
return if @@dotfile # Load the dotfile only once.
|
177
|
+
|
178
|
+
dotfile = find_dotfile
|
155
179
|
load dotfile if dotfile_readable?(dotfile)
|
156
180
|
end
|
157
181
|
|
158
182
|
def dotfile_readable?(dotfile)
|
159
|
-
if @@dotfile_readable.nil? || @@dotfile != dotfile
|
160
|
-
@@dotfile_readable = File.readable?(@@dotfile = dotfile)
|
161
|
-
end
|
183
|
+
@@dotfile_readable = File.readable?(@@dotfile = dotfile) if @@dotfile_readable.nil? || @@dotfile != dotfile
|
162
184
|
@@dotfile_readable
|
163
185
|
end
|
164
186
|
@@dotfile_readable = @@dotfile = nil
|
@@ -173,3 +195,5 @@ module AmazingPrint
|
|
173
195
|
end
|
174
196
|
end
|
175
197
|
end
|
198
|
+
|
199
|
+
# rubocop:enable Metrics/ClassLength
|
data/lib/amazing_print.rb
CHANGED
@@ -23,12 +23,8 @@ unless defined?(AmazingPrint::Inspector)
|
|
23
23
|
# Load the following under normal circumstances as well as in Rails
|
24
24
|
# console when required from ~/.irbrc or ~/.pryrc.
|
25
25
|
#
|
26
|
-
if defined?(ActiveRecord) || AmazingPrint.rails_console?
|
27
|
-
|
28
|
-
end
|
29
|
-
if defined?(ActiveSupport) || AmazingPrint.rails_console?
|
30
|
-
require_relative 'amazing_print/ext/active_support'
|
31
|
-
end
|
26
|
+
require_relative 'amazing_print/ext/active_record' if defined?(ActiveRecord) || AmazingPrint.rails_console?
|
27
|
+
require_relative 'amazing_print/ext/active_support' if defined?(ActiveSupport) || AmazingPrint.rails_console?
|
32
28
|
#
|
33
29
|
# Load remaining extensions.
|
34
30
|
#
|
@@ -27,6 +27,17 @@ if ExtVerifier.has_rails?
|
|
27
27
|
|
28
28
|
# Create models
|
29
29
|
class User < ActiveRecord::Base; has_many :emails; end
|
30
|
+
|
30
31
|
class SubUser < User; end
|
32
|
+
|
31
33
|
class Email < ActiveRecord::Base; belongs_to :user; end
|
34
|
+
|
35
|
+
class TableFreeModel
|
36
|
+
include ::ActiveModel::Validations
|
37
|
+
attr_reader(:name)
|
38
|
+
|
39
|
+
def attributes
|
40
|
+
{ 'name' => name }
|
41
|
+
end
|
42
|
+
end
|
32
43
|
end
|
data/spec/colors_spec.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock, Style/OptionalBooleanParameter
|
4
|
+
|
3
5
|
require 'spec_helper'
|
4
6
|
|
5
7
|
RSpec.describe 'AmazingPrint' do
|
6
|
-
def stub_tty!(output = true, stream =
|
8
|
+
def stub_tty!(output = true, stream = $stdout)
|
7
9
|
if output
|
8
10
|
stream.instance_eval do
|
9
11
|
def tty?
|
@@ -31,7 +33,7 @@ RSpec.describe 'AmazingPrint' do
|
|
31
33
|
|
32
34
|
describe 'default settings (no forced colors)' do
|
33
35
|
before do
|
34
|
-
AmazingPrint.force_colors! false
|
36
|
+
AmazingPrint.force_colors! colors: false
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'colorizes tty processes by default' do
|
@@ -40,34 +42,28 @@ RSpec.describe 'AmazingPrint' do
|
|
40
42
|
end
|
41
43
|
|
42
44
|
it "colorizes processes with ENV['ANSICON'] by default" do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
ENV['ANSICON'] = term
|
50
|
-
end
|
45
|
+
stub_tty!
|
46
|
+
term = ENV['ANSICON']
|
47
|
+
ENV['ANSICON'] = '1'
|
48
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
49
|
+
ensure
|
50
|
+
ENV['ANSICON'] = term
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'does not colorize tty processes running in dumb terminals by default' do
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
ENV['TERM'] = term
|
61
|
-
end
|
54
|
+
stub_tty!
|
55
|
+
term = ENV['TERM']
|
56
|
+
ENV['TERM'] = 'dumb'
|
57
|
+
expect(@arr.ai(multiline: false)).to eq(PLAIN)
|
58
|
+
ensure
|
59
|
+
ENV['TERM'] = term
|
62
60
|
end
|
63
61
|
|
64
62
|
it 'does not colorize subprocesses by default' do
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
stub_tty!
|
70
|
-
end
|
63
|
+
stub_tty! false
|
64
|
+
expect(@arr.ai(multiline: false)).to eq(PLAIN)
|
65
|
+
ensure
|
66
|
+
stub_tty!
|
71
67
|
end
|
72
68
|
end
|
73
69
|
|
@@ -82,34 +78,28 @@ RSpec.describe 'AmazingPrint' do
|
|
82
78
|
end
|
83
79
|
|
84
80
|
it "colorizes processes with ENV['ANSICON'] set to 0" do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
ENV['ANSICON'] = term
|
92
|
-
end
|
81
|
+
stub_tty!
|
82
|
+
term = ENV['ANSICON']
|
83
|
+
ENV['ANSICON'] = '1'
|
84
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
85
|
+
ensure
|
86
|
+
ENV['ANSICON'] = term
|
93
87
|
end
|
94
88
|
|
95
89
|
it 'colorizes dumb terminals' do
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
ENV['TERM'] = term
|
103
|
-
end
|
90
|
+
stub_tty!
|
91
|
+
term = ENV['TERM']
|
92
|
+
ENV['TERM'] = 'dumb'
|
93
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
94
|
+
ensure
|
95
|
+
ENV['TERM'] = term
|
104
96
|
end
|
105
97
|
|
106
98
|
it 'colorizes subprocess' do
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
stub_tty!
|
112
|
-
end
|
99
|
+
stub_tty! false
|
100
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
101
|
+
ensure
|
102
|
+
stub_tty!
|
113
103
|
end
|
114
104
|
end
|
115
105
|
|
@@ -121,3 +111,5 @@ RSpec.describe 'AmazingPrint' do
|
|
121
111
|
end
|
122
112
|
end
|
123
113
|
end
|
114
|
+
|
115
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock, Style/OptionalBooleanParameter
|