amazing_print 1.2.0 → 1.4.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +38 -54
  3. data/CHANGELOG.md +36 -2
  4. data/Gemfile.lock +48 -50
  5. data/README.md +20 -11
  6. data/lib/amazing_print/colorize.rb +1 -3
  7. data/lib/amazing_print/core_ext/awesome_method_array.rb +4 -4
  8. data/lib/amazing_print/core_ext/class.rb +1 -1
  9. data/lib/amazing_print/core_ext/logger.rb +10 -5
  10. data/lib/amazing_print/core_ext/object.rb +1 -1
  11. data/lib/amazing_print/custom_defaults.rb +10 -3
  12. data/lib/amazing_print/ext/action_view.rb +1 -1
  13. data/lib/amazing_print/ext/active_record.rb +12 -27
  14. data/lib/amazing_print/ext/active_support.rb +1 -3
  15. data/lib/amazing_print/ext/mongo_mapper.rb +5 -8
  16. data/lib/amazing_print/ext/mongoid.rb +2 -6
  17. data/lib/amazing_print/ext/nobrainer.rb +7 -5
  18. data/lib/amazing_print/ext/nokogiri.rb +1 -3
  19. data/lib/amazing_print/ext/ostruct.rb +1 -3
  20. data/lib/amazing_print/ext/ripple.rb +4 -5
  21. data/lib/amazing_print/formatter.rb +5 -6
  22. data/lib/amazing_print/formatters/array_formatter.rb +6 -5
  23. data/lib/amazing_print/formatters/base_formatter.rb +20 -25
  24. data/lib/amazing_print/formatters/class_formatter.rb +1 -0
  25. data/lib/amazing_print/formatters/dir_formatter.rb +1 -0
  26. data/lib/amazing_print/formatters/file_formatter.rb +1 -0
  27. data/lib/amazing_print/formatters/hash_formatter.rb +5 -4
  28. data/lib/amazing_print/formatters/method_formatter.rb +1 -0
  29. data/lib/amazing_print/formatters/object_formatter.rb +2 -1
  30. data/lib/amazing_print/formatters/simple_formatter.rb +1 -0
  31. data/lib/amazing_print/formatters/struct_formatter.rb +2 -1
  32. data/lib/amazing_print/inspector.rb +29 -5
  33. data/lib/amazing_print/version.rb +1 -1
  34. data/lib/amazing_print.rb +2 -6
  35. data/spec/active_record_helper.rb +11 -0
  36. data/spec/colors_spec.rb +38 -46
  37. data/spec/core_ext/logger_spec.rb +42 -18
  38. data/spec/core_ext/string_spec.rb +2 -2
  39. data/spec/ext/action_controller_spec.rb +4 -4
  40. data/spec/ext/action_view_spec.rb +6 -1
  41. data/spec/ext/active_model_spec.rb +37 -0
  42. data/spec/ext/active_record_spec.rb +44 -23
  43. data/spec/ext/active_support_spec.rb +13 -4
  44. data/spec/ext/mongo_mapper_spec.rb +16 -12
  45. data/spec/ext/mongoid_spec.rb +7 -3
  46. data/spec/ext/nobrainer_spec.rb +6 -2
  47. data/spec/ext/nokogiri_spec.rb +3 -3
  48. data/spec/ext/ripple_spec.rb +6 -2
  49. data/spec/formats_spec.rb +24 -18
  50. data/spec/methods_spec.rb +12 -4
  51. data/spec/misc_spec.rb +15 -10
  52. data/spec/objects_spec.rb +4 -0
  53. data/spec/spec_helper.rb +4 -8
  54. data/spec/support/active_record_data/6_1_diana.txt +109 -0
  55. data/spec/support/active_record_data/6_1_multi.txt +220 -0
  56. data/spec/support/ext_verifier.rb +2 -4
  57. data/spec/support/rails_versions.rb +5 -0
  58. 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 = Hash[object.fields.map do |field, options|
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
- if object.is_a?(::Ripple::AttributeMethods) # Module used to access attributes across documents and embedded documents
21
+ case object
22
+ when ::Ripple::AttributeMethods # Module used to access attributes across documents and embedded documents
22
23
  cast = :ripple_document_instance
23
- elsif object.is_a?(::Ripple::Properties) # Used to access property metadata on Ripple classes
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
- awesome = if core_class != :self
28
- send(:"awesome_#{core_class}", object) # Core formatters.
29
- else
30
- awesome_self(object, type) # Catch all that falls back to object.inspect.
31
- end
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
- '[ ' + array.map { |item| inspector.awesome(item) }.join(', ') + ' ]'
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
- rescue NameError, ArgumentError
118
- nil
118
+ rescue NameError, ArgumentError
119
+ nil
119
120
  end
120
121
 
121
122
  meth || begin
122
123
  object.instance_method(name)
123
- rescue NameError
124
- nil
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) && (options[:limit] > 0))
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 = false)
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
- if method.respond_to?(:parameters) # Ruby 1.9.2+
69
- # See http://readruby.chengguangnan.com/methods#method-objects-parameters
70
- # (mirror: http://archive.is/XguCA#selection-3381.1-3381.11)
71
- args = method.parameters.inject([]) do |arr, (type, name)|
72
- name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
73
- arr << case type
74
- when :req then name.to_s
75
- when :keyreq then "#{name}:"
76
- when :key then "*#{name}:"
77
- when :opt, :rest then "*#{name}"
78
- when :block then "&#{name}"
79
- else '?'
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 > 0
133
+ if indent_option.positive?
139
134
  value.rjust(width)
140
- elsif indent_option == 0
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 :klass, :inspector, :options
9
9
 
10
10
  def initialize(klass, inspector)
11
+ super()
11
12
  @klass = klass
12
13
  @inspector = inspector
13
14
  @options = inspector.options
@@ -10,6 +10,7 @@ module AmazingPrint
10
10
  attr_reader :dir, :inspector, :options
11
11
 
12
12
  def initialize(dir, inspector)
13
+ super()
13
14
  @dir = dir
14
15
  @inspector = inspector
15
16
  @options = inspector.options
@@ -10,6 +10,7 @@ module AmazingPrint
10
10
  attr_reader :file, :inspector, :options
11
11
 
12
12
  def initialize(file, inspector)
13
+ super()
13
14
  @file = file
14
15
  @inspector = inspector
15
16
  @options = inspector.options
@@ -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, hash: true) : data
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] > 0
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) << colorize(': ', :hash) << inspector.awesome(value)
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) + colorize(' => ', :hash) + inspector.awesome(value)
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 :method, :inspector, :options
9
9
 
10
10
  def initialize(method, inspector)
11
+ super()
11
12
  @method = method
12
13
  @inspector = inspector
13
14
  @options = inspector.options
@@ -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(\:\w+)/, "#{colorize('\\1', :keyword)} #{colorize('\\2', :method)}")
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 :string, :type, :inspector, :options
9
9
 
10
10
  def initialize(string, type, inspector)
11
+ super()
11
12
  @string = string
12
13
  @type = type
13
14
  @inspector = inspector
@@ -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(\:\w+)/, "#{colorize('\\1', :keyword)} #{colorize('\\2', :method)}")
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 = STDOUT.tty? && (
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 = File.join(ENV['HOME'], '.aprc')
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
@@ -7,6 +7,6 @@
7
7
  #------------------------------------------------------------------------------
8
8
  module AmazingPrint
9
9
  def self.version
10
- '1.2.0'
10
+ '1.4.0'
11
11
  end
12
12
  end
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
- require_relative 'amazing_print/ext/active_record'
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 = STDOUT)
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
- begin
44
- stub_tty!
45
- term = ENV['ANSICON']
46
- ENV['ANSICON'] = '1'
47
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
48
- ensure
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
- begin
55
- stub_tty!
56
- term = ENV['TERM']
57
- ENV['TERM'] = 'dumb'
58
- expect(@arr.ai(multiline: false)).to eq(PLAIN)
59
- ensure
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
- begin
66
- stub_tty! false
67
- expect(@arr.ai(multiline: false)).to eq(PLAIN)
68
- ensure
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
- begin
86
- stub_tty!
87
- term = ENV['ANSICON']
88
- ENV['ANSICON'] = '1'
89
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
90
- ensure
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
- begin
97
- stub_tty!
98
- term = ENV['TERM']
99
- ENV['TERM'] = 'dumb'
100
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
101
- ensure
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
- begin
108
- stub_tty! false
109
- expect(@arr.ai(multiline: false)).to eq(COLORIZED)
110
- ensure
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