awesome_print 1.7.0 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +4 -0
  3. data/Appraisals +44 -34
  4. data/CHANGELOG.md +28 -0
  5. data/CONTRIBUTING.md +2 -1
  6. data/Gemfile.lock +25 -33
  7. data/LICENSE +16 -19
  8. data/README.md +88 -44
  9. data/Rakefile +5 -5
  10. data/awesome_print.gemspec +33 -0
  11. data/init.rb +1 -0
  12. data/lib/ap.rb +2 -2
  13. data/lib/awesome_print/colorize.rb +1 -1
  14. data/lib/awesome_print/core_ext/{array.rb → awesome_method_array.rb} +16 -18
  15. data/lib/awesome_print/core_ext/class.rb +3 -2
  16. data/lib/awesome_print/core_ext/kernel.rb +1 -1
  17. data/lib/awesome_print/core_ext/logger.rb +1 -1
  18. data/lib/awesome_print/core_ext/method.rb +2 -2
  19. data/lib/awesome_print/core_ext/object.rb +3 -2
  20. data/lib/awesome_print/core_ext/string.rb +3 -3
  21. data/lib/awesome_print/custom_defaults.rb +57 -0
  22. data/lib/awesome_print/ext/action_view.rb +8 -4
  23. data/lib/awesome_print/ext/active_record.rb +45 -12
  24. data/lib/awesome_print/ext/active_support.rb +1 -1
  25. data/lib/awesome_print/ext/mongo_mapper.rb +16 -13
  26. data/lib/awesome_print/ext/mongoid.rb +8 -6
  27. data/lib/awesome_print/ext/nobrainer.rb +8 -5
  28. data/lib/awesome_print/ext/nokogiri.rb +4 -4
  29. data/lib/awesome_print/ext/ostruct.rb +1 -1
  30. data/lib/awesome_print/ext/ripple.rb +5 -6
  31. data/lib/awesome_print/ext/sequel.rb +7 -6
  32. data/lib/awesome_print/formatter.rb +28 -28
  33. data/lib/awesome_print/formatters/array_formatter.rb +108 -42
  34. data/lib/awesome_print/formatters/base_formatter.rb +16 -14
  35. data/lib/awesome_print/formatters/class_formatter.rb +2 -1
  36. data/lib/awesome_print/formatters/dir_formatter.rb +1 -1
  37. data/lib/awesome_print/formatters/file_formatter.rb +1 -1
  38. data/lib/awesome_print/formatters/hash_formatter.rb +74 -22
  39. data/lib/awesome_print/formatters/object_formatter.rb +13 -15
  40. data/lib/awesome_print/formatters/struct_formatter.rb +71 -0
  41. data/lib/awesome_print/formatters.rb +15 -0
  42. data/lib/awesome_print/inspector.rb +83 -96
  43. data/lib/awesome_print/version.rb +2 -2
  44. data/lib/awesome_print.rb +18 -17
  45. data/spec/active_record_helper.rb +8 -2
  46. data/spec/colors_spec.rb +30 -30
  47. data/spec/core_ext/logger_spec.rb +43 -0
  48. data/spec/core_ext/string_spec.rb +20 -0
  49. data/spec/ext/action_view_spec.rb +21 -0
  50. data/spec/ext/active_record_spec.rb +260 -0
  51. data/spec/ext/active_support_spec.rb +30 -0
  52. data/spec/ext/mongo_mapper_spec.rb +261 -0
  53. data/spec/ext/mongoid_spec.rb +67 -0
  54. data/spec/ext/nobrainer_spec.rb +59 -0
  55. data/spec/ext/nokogiri_spec.rb +46 -0
  56. data/spec/ext/ostruct_spec.rb +22 -0
  57. data/spec/ext/ripple_spec.rb +48 -0
  58. data/spec/formats_spec.rb +193 -165
  59. data/spec/methods_spec.rb +125 -129
  60. data/spec/misc_spec.rb +95 -92
  61. data/spec/objects_spec.rb +119 -28
  62. data/spec/spec_helper.rb +29 -10
  63. data/spec/support/active_record_data/3_2_diana.txt +24 -0
  64. data/spec/support/active_record_data/3_2_diana_legacy.txt +24 -0
  65. data/spec/support/active_record_data/3_2_multi.txt +50 -0
  66. data/spec/support/active_record_data/3_2_multi_legacy.txt +50 -0
  67. data/spec/support/active_record_data/4_0_diana.txt +98 -0
  68. data/spec/support/active_record_data/4_0_multi.txt +198 -0
  69. data/spec/support/active_record_data/4_1_diana.txt +97 -0
  70. data/spec/support/active_record_data/4_1_multi.txt +196 -0
  71. data/spec/support/active_record_data/4_2_diana.txt +109 -0
  72. data/spec/support/active_record_data/4_2_diana_legacy.txt +109 -0
  73. data/spec/support/active_record_data/4_2_multi.txt +220 -0
  74. data/spec/support/active_record_data/4_2_multi_legacy.txt +220 -0
  75. data/spec/support/active_record_data/5_0_diana.txt +105 -0
  76. data/spec/support/active_record_data/5_0_multi.txt +212 -0
  77. data/spec/support/active_record_data/5_1_diana.txt +104 -0
  78. data/spec/support/active_record_data/5_1_multi.txt +210 -0
  79. data/spec/support/active_record_data/5_2_diana.txt +104 -0
  80. data/spec/support/active_record_data/5_2_multi.txt +210 -0
  81. data/spec/support/active_record_data/6_0_diana.txt +104 -0
  82. data/spec/support/active_record_data/6_0_multi.txt +210 -0
  83. data/spec/support/active_record_data/6_1_diana.txt +109 -0
  84. data/spec/support/active_record_data/6_1_multi.txt +220 -0
  85. data/spec/support/active_record_data.rb +20 -0
  86. data/spec/support/ext_verifier.rb +42 -0
  87. data/spec/support/mongoid_versions.rb +26 -0
  88. data/spec/support/rails_versions.rb +55 -0
  89. metadata +90 -26
@@ -1,89 +1,51 @@
1
- # Copyright (c) 2010-2013 Michael Dvorkin
1
+ # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
2
  #
3
3
  # Awesome Print is freely distributable under the terms of MIT license.
4
4
  # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
5
  #------------------------------------------------------------------------------
6
- require_relative "indentator"
6
+ require_relative 'indentator'
7
7
 
8
8
  module AwesomePrint
9
-
10
- class << self # Class accessors for custom defaults.
11
- attr_accessor :defaults, :force_colors
12
-
13
- # Class accessor to force colorized output (ex. forked subprocess where TERM
14
- # might be dumb).
15
- #------------------------------------------------------------------------------
16
- def force_colors!(value = true)
17
- @force_colors = value
18
- end
19
-
20
- def console?
21
- !!(defined?(IRB) || defined?(Pry))
22
- end
23
-
24
- def rails_console?
25
- console? && !!(defined?(Rails::Console) || ENV["RAILS_ENV"])
26
- end
27
-
28
- def irb!
29
- return unless defined?(IRB)
30
- unless IRB.version.include?("DietRB")
31
- IRB::Irb.class_eval do
32
- def output_value
33
- ap @context.last_value
34
- end
35
- end
36
- else # MacRuby
37
- IRB.formatter = Class.new(IRB::Formatter) do
38
- def inspect_object(object)
39
- object.ai
40
- end
41
- end.new
42
- end
43
- end
44
-
45
- def pry!
46
- if defined?(Pry)
47
- Pry.print = proc { |output, value| output.puts value.ai }
48
- end
49
- end
50
- end
51
-
52
9
  class Inspector
53
10
  attr_accessor :options, :indentator
54
11
 
55
12
  AP = :__awesome_print__
56
13
 
57
14
  def initialize(options = {})
58
- @options = {
59
- :indent => 4, # Indent using 4 spaces.
60
- :index => true, # Display array indices.
61
- :html => false, # Use ANSI color codes rather than HTML.
62
- :multiline => true, # Display in multiple lines.
63
- :plain => false, # Use colors.
64
- :raw => false, # Do not recursively format object instance variables.
65
- :sort_keys => false, # Do not sort hash keys.
66
- :limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer.
67
- :color => {
68
- :args => :pale,
69
- :array => :white,
70
- :bigdecimal => :blue,
71
- :class => :yellow,
72
- :date => :greenish,
73
- :falseclass => :red,
74
- :fixnum => :blue,
75
- :float => :blue,
76
- :hash => :pale,
77
- :keyword => :cyan,
78
- :method => :purpleish,
79
- :nilclass => :red,
80
- :rational => :blue,
81
- :string => :yellowish,
82
- :struct => :pale,
83
- :symbol => :cyanish,
84
- :time => :greenish,
85
- :trueclass => :green,
86
- :variable => :cyanish
15
+ @options = {
16
+ indent: 4, # Number of spaces for indenting.
17
+ index: true, # Display array indices.
18
+ html: false, # Use ANSI color codes rather than HTML.
19
+ multiline: true, # Display in multiple lines.
20
+ plain: false, # Use colors.
21
+ raw: false, # Do not recursively format instance variables.
22
+ sort_keys: false, # Do not sort hash keys.
23
+ sort_vars: true, # Sort instance variables.
24
+ limit: false, # Limit arrays & hashes. Accepts bool or int.
25
+ ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
26
+ class_name: :class, # Method used to get Instance class name.
27
+ object_id: true, # Show object_id.
28
+ color: {
29
+ args: :pale,
30
+ array: :white,
31
+ bigdecimal: :blue,
32
+ class: :yellow,
33
+ date: :greenish,
34
+ falseclass: :red,
35
+ fixnum: :blue,
36
+ integer: :blue,
37
+ float: :blue,
38
+ hash: :pale,
39
+ keyword: :cyan,
40
+ method: :purpleish,
41
+ nilclass: :red,
42
+ rational: :blue,
43
+ string: :yellowish,
44
+ struct: :pale,
45
+ symbol: :cyanish,
46
+ time: :greenish,
47
+ trueclass: :green,
48
+ variable: :cyanish
87
49
  }
88
50
  }
89
51
 
@@ -100,12 +62,12 @@ module AwesomePrint
100
62
  indentator.indentation
101
63
  end
102
64
 
103
- def increase_indentation
104
- indentator.indent(&Proc.new)
65
+ def increase_indentation(&block)
66
+ indentator.indent(&block)
105
67
  end
106
-
68
+
107
69
  # Dispatcher that detects data nesting and invokes object-aware formatter.
108
- #------------------------------------------------------------------------------
70
+ #---------------------------------------------------------------------------
109
71
  def awesome(object)
110
72
  if Thread.current[AP].include?(object.object_id)
111
73
  nested(object)
@@ -120,10 +82,18 @@ module AwesomePrint
120
82
  end
121
83
 
122
84
  # Return true if we are to colorize the output.
123
- #------------------------------------------------------------------------------
85
+ #---------------------------------------------------------------------------
124
86
  def colorize?
125
87
  AwesomePrint.force_colors ||= false
126
- AwesomePrint.force_colors || (STDOUT.tty? && ((ENV['TERM'] && ENV['TERM'] != 'dumb') || ENV['ANSICON']))
88
+ AwesomePrint.force_colors || (
89
+ STDOUT.tty? && (
90
+ (
91
+ ENV['TERM'] &&
92
+ ENV['TERM'] != 'dumb'
93
+ ) ||
94
+ ENV['ANSICON']
95
+ )
96
+ )
127
97
  end
128
98
 
129
99
  private
@@ -133,24 +103,25 @@ module AwesomePrint
133
103
  # => [1,2, [...]]
134
104
  # hash = { :a => 1 }; hash[:b] = hash
135
105
  # => { :a => 1, :b => {...} }
136
- #------------------------------------------------------------------------------
106
+ #---------------------------------------------------------------------------
137
107
  def nested(object)
138
108
  case printable(object)
139
- when :array then @formatter.colorize("[...]", :array)
140
- when :hash then @formatter.colorize("{...}", :hash)
141
- when :struct then @formatter.colorize("{...}", :struct)
142
- else @formatter.colorize("...#{object.class}...", :class)
109
+ when :array then @formatter.colorize('[...]', :array)
110
+ when :hash then @formatter.colorize('{...}', :hash)
111
+ when :struct then @formatter.colorize('{...}', :struct)
112
+ else @formatter.colorize("...#{object.class}...", :class)
143
113
  end
144
114
  end
145
115
 
146
- #------------------------------------------------------------------------------
116
+ #---------------------------------------------------------------------------
147
117
  def unnested(object)
148
118
  @formatter.format(object, printable(object))
149
119
  end
150
120
 
151
- # Turn class name into symbol, ex: Hello::World => :hello_world. Classes that
152
- # inherit from Array, Hash, File, Dir, and Struct are treated as the base class.
153
- #------------------------------------------------------------------------------
121
+ # Turn class name into symbol, ex: Hello::World => :hello_world. Classes
122
+ # that inherit from Array, Hash, File, Dir, and Struct are treated as the
123
+ # base class.
124
+ #---------------------------------------------------------------------------
154
125
  def printable(object)
155
126
  case object
156
127
  when Array then :array
@@ -158,25 +129,41 @@ module AwesomePrint
158
129
  when File then :file
159
130
  when Dir then :dir
160
131
  when Struct then :struct
161
- else object.class.to_s.gsub(/:+/, "_").downcase.to_sym
132
+ else object.class.to_s.gsub(/:+/, '_').downcase.to_sym
162
133
  end
163
134
  end
164
135
 
165
- # Update @options by first merging the :color hash and then the remaining keys.
166
- #------------------------------------------------------------------------------
136
+ # Update @options by first merging the :color hash and then the remaining
137
+ # keys.
138
+ #---------------------------------------------------------------------------
167
139
  def merge_options!(options = {})
168
140
  @options[:color].merge!(options.delete(:color) || {})
169
141
  @options.merge!(options)
170
142
  end
171
143
 
144
+ # This method needs to be mocked during testing so that it always loads
145
+ # predictable values
146
+ #---------------------------------------------------------------------------
147
+ def load_dotfile
148
+ dotfile = File.join(ENV['HOME'], '.aprc')
149
+ load dotfile if dotfile_readable?(dotfile)
150
+ end
151
+
152
+ def dotfile_readable? dotfile
153
+ if @@dotfile_readable.nil? || @@dotfile != dotfile
154
+ @@dotfile_readable = File.readable?(@@dotfile = dotfile)
155
+ end
156
+ @@dotfile_readable
157
+ end
158
+ @@dotfile_readable = @@dotfile = nil
159
+
172
160
  # Load ~/.aprc file with custom defaults that override default options.
173
- #------------------------------------------------------------------------------
161
+ #---------------------------------------------------------------------------
174
162
  def merge_custom_defaults!
175
- dotfile = File.join(ENV["HOME"], ".aprc")
176
- load dotfile if File.readable?(dotfile)
163
+ load_dotfile
177
164
  merge_options!(AwesomePrint.defaults) if AwesomePrint.defaults.is_a?(Hash)
178
165
  rescue => e
179
- $stderr.puts "Could not load #{dotfile}: #{e}"
166
+ $stderr.puts "Could not load '.aprc' from ENV['HOME']: #{e}"
180
167
  end
181
168
  end
182
169
  end
@@ -1,10 +1,10 @@
1
- # Copyright (c) 2010-2013 Michael Dvorkin
1
+ # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
2
  #
3
3
  # Awesome Print is freely distributable under the terms of MIT license.
4
4
  # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
5
  #------------------------------------------------------------------------------
6
6
  module AwesomePrint
7
7
  def self.version
8
- '1.7.0'
8
+ '1.9.2'
9
9
  end
10
10
  end
data/lib/awesome_print.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2013 Michael Dvorkin
1
+ # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
2
  #
3
3
  # Awesome Print is freely distributable under the terms of MIT license.
4
4
  # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
@@ -8,33 +8,34 @@
8
8
  # so do nothing for subsequent requires.
9
9
  #
10
10
  unless defined?(AwesomePrint::Inspector)
11
- %w(array string method object class kernel).each do |file|
12
- require File.dirname(__FILE__) + "/awesome_print/core_ext/#{file}"
11
+ %w(awesome_method_array string method object class kernel).each do |file|
12
+ require "awesome_print/core_ext/#{file}"
13
13
  end
14
14
 
15
- require File.dirname(__FILE__) + "/awesome_print/inspector"
16
- require File.dirname(__FILE__) + "/awesome_print/formatter"
17
- require File.dirname(__FILE__) + "/awesome_print/version"
18
- require File.dirname(__FILE__) + "/awesome_print/core_ext/logger" if defined?(Logger)
15
+ require 'awesome_print/custom_defaults'
16
+ require 'awesome_print/inspector'
17
+ require 'awesome_print/formatter'
18
+ require 'awesome_print/version'
19
+ require 'awesome_print/core_ext/logger' if defined?(Logger)
19
20
  #
20
21
  # Load the following under normal circumstances as well as in Rails
21
22
  # console when required from ~/.irbrc or ~/.pryrc.
22
23
  #
23
- require File.dirname(__FILE__) + "/awesome_print/ext/active_record" if defined?(ActiveRecord) || AwesomePrint.rails_console?
24
- require File.dirname(__FILE__) + "/awesome_print/ext/active_support" if defined?(ActiveSupport) || AwesomePrint.rails_console?
24
+ require 'awesome_print/ext/active_record' if defined?(ActiveRecord) || AwesomePrint.rails_console?
25
+ require 'awesome_print/ext/active_support' if defined?(ActiveSupport) || AwesomePrint.rails_console?
25
26
  #
26
27
  # Load remaining extensions.
27
28
  #
28
29
  if defined?(ActiveSupport.on_load)
29
30
  ActiveSupport.on_load(:action_view) do
30
- require File.dirname(__FILE__) + "/awesome_print/ext/action_view"
31
+ require 'awesome_print/ext/action_view'
31
32
  end
32
33
  end
33
- require File.dirname(__FILE__) + "/awesome_print/ext/mongo_mapper" if defined?(MongoMapper)
34
- require File.dirname(__FILE__) + "/awesome_print/ext/mongoid" if defined?(Mongoid)
35
- require File.dirname(__FILE__) + "/awesome_print/ext/nokogiri" if defined?(Nokogiri)
36
- require File.dirname(__FILE__) + "/awesome_print/ext/nobrainer" if defined?(NoBrainer)
37
- require File.dirname(__FILE__) + "/awesome_print/ext/ripple" if defined?(Ripple)
38
- require File.dirname(__FILE__) + "/awesome_print/ext/sequel" if defined?(Sequel)
39
- require File.dirname(__FILE__) + "/awesome_print/ext/ostruct" if defined?(OpenStruct)
34
+ require 'awesome_print/ext/mongo_mapper' if defined?(MongoMapper)
35
+ require 'awesome_print/ext/mongoid' if defined?(Mongoid)
36
+ require 'awesome_print/ext/nokogiri' if defined?(Nokogiri)
37
+ require 'awesome_print/ext/nobrainer' if defined?(NoBrainer)
38
+ require 'awesome_print/ext/ripple' if defined?(Ripple)
39
+ require 'awesome_print/ext/sequel' if defined?(Sequel)
40
+ require 'awesome_print/ext/ostruct' if defined?(OpenStruct)
40
41
  end
@@ -7,7 +7,7 @@ if ExtVerifier.has_rails?
7
7
  end
8
8
 
9
9
  # Establish connection to in-memory SQLite DB
10
- ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
10
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
11
11
 
12
12
  # Create the users table
13
13
  ActiveRecord::Migration.verbose = false
@@ -18,7 +18,13 @@ if ExtVerifier.has_rails?
18
18
  t.datetime :created_at
19
19
  end
20
20
 
21
+ ActiveRecord::Migration.create_table :emails do |t|
22
+ t.references :user
23
+ t.string :email_address
24
+ end
25
+
21
26
  # Create models
22
- class User < ActiveRecord::Base; end
27
+ class User < ActiveRecord::Base; has_many :emails; end
23
28
  class SubUser < User; end
29
+ class Email < ActiveRecord::Base; belongs_to :user; end
24
30
  end
data/spec/colors_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe "AwesomePrint" do
3
+ RSpec.describe 'AwesomePrint' do
4
4
  def stub_tty!(output = true, stream = STDOUT)
5
5
  if output
6
6
  stream.instance_eval { def tty?; true; end }
@@ -9,94 +9,94 @@ RSpec.describe "AwesomePrint" do
9
9
  end
10
10
  end
11
11
 
12
- before do
13
- stub_dotfile!
14
- end
15
-
16
- describe "colorization" do
12
+ describe 'colorization' do
17
13
  PLAIN = '[ 1, :two, "three", [ nil, [ true, false ] ] ]'
18
14
  COLORIZED = "[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]"
19
15
 
20
16
  before do
21
- ENV['TERM'] = "xterm-colors"
17
+ ENV['TERM'] = 'xterm-colors'
22
18
  ENV.delete('ANSICON')
23
- @arr = [ 1, :two, "three", [ nil, [ true, false] ] ]
19
+ @arr = [1, :two, 'three', [nil, [true, false]]]
24
20
  end
25
21
 
26
- describe "default settings (no forced colors)" do
22
+ describe 'default settings (no forced colors)' do
27
23
  before do
28
24
  AwesomePrint.force_colors! false
29
25
  end
30
26
 
31
- it "colorizes tty processes by default" do
27
+ it 'colorizes tty processes by default' do
32
28
  stub_tty!
33
- expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
29
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
34
30
  end
35
31
 
36
32
  it "colorizes processes with ENV['ANSICON'] by default" do
37
33
  begin
38
34
  stub_tty!
39
- term, ENV['ANSICON'] = ENV['ANSICON'], "1"
40
- expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
35
+ term = ENV['ANSICON']
36
+ ENV['ANSICON'] = '1'
37
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
41
38
  ensure
42
39
  ENV['ANSICON'] = term
43
40
  end
44
41
  end
45
42
 
46
- it "does not colorize tty processes running in dumb terminals by default" do
43
+ it 'does not colorize tty processes running in dumb terminals by default' do
47
44
  begin
48
45
  stub_tty!
49
- term, ENV['TERM'] = ENV['TERM'], "dumb"
50
- expect(@arr.ai(:multiline => false)).to eq(PLAIN)
46
+ term = ENV['TERM']
47
+ ENV['TERM'] = 'dumb'
48
+ expect(@arr.ai(multiline: false)).to eq(PLAIN)
51
49
  ensure
52
50
  ENV['TERM'] = term
53
51
  end
54
52
  end
55
53
 
56
- it "does not colorize subprocesses by default" do
54
+ it 'does not colorize subprocesses by default' do
57
55
  begin
58
56
  stub_tty! false
59
- expect(@arr.ai(:multiline => false)).to eq(PLAIN)
57
+ expect(@arr.ai(multiline: false)).to eq(PLAIN)
60
58
  ensure
61
59
  stub_tty!
62
60
  end
63
61
  end
64
62
  end
65
63
 
66
- describe "forced colors override" do
64
+ describe 'forced colors override' do
67
65
  before do
68
66
  AwesomePrint.force_colors!
69
67
  end
70
-
71
- it "still colorizes tty processes" do
68
+
69
+ it 'still colorizes tty processes' do
72
70
  stub_tty!
73
- expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
71
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
74
72
  end
75
73
 
76
74
  it "colorizes processes with ENV['ANSICON'] set to 0" do
77
75
  begin
78
76
  stub_tty!
79
- term, ENV['ANSICON'] = ENV['ANSICON'], "1"
80
- expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
77
+ term = ENV['ANSICON']
78
+ ENV['ANSICON'] = '1'
79
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
81
80
  ensure
82
81
  ENV['ANSICON'] = term
83
82
  end
84
83
  end
85
-
86
- it "colorizes dumb terminals" do
84
+
85
+ it 'colorizes dumb terminals' do
87
86
  begin
88
87
  stub_tty!
89
- term, ENV['TERM'] = ENV['TERM'], "dumb"
90
- expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
88
+ term = ENV['TERM']
89
+ ENV['TERM'] = 'dumb'
90
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
91
91
  ensure
92
92
  ENV['TERM'] = term
93
93
  end
94
94
  end
95
95
 
96
- it "colorizes subprocess" do
96
+ it 'colorizes subprocess' do
97
97
  begin
98
98
  stub_tty! false
99
- expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
99
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
100
100
  ensure
101
101
  stub_tty!
102
102
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ require 'logger'
5
+ require 'awesome_print/core_ext/logger'
6
+
7
+ RSpec.describe 'AwesomePrint logging extensions' do
8
+ before(:all) do
9
+ @logger = Logger.new('/dev/null') rescue Logger.new('nul')
10
+ end
11
+
12
+ describe 'ap method' do
13
+ it 'should awesome_inspect the given object' do
14
+ object = double
15
+ expect(object).to receive(:ai)
16
+ @logger.ap object
17
+ end
18
+
19
+ describe 'the log level' do
20
+ before do
21
+ AwesomePrint.defaults = {}
22
+ end
23
+
24
+ it 'should fallback to the default :debug log level' do
25
+ expect(@logger).to receive(:debug)
26
+ @logger.ap(nil)
27
+ end
28
+
29
+ it 'should use the global user default if no level passed' do
30
+ AwesomePrint.defaults = { log_level: :info }
31
+ expect(@logger).to receive(:info)
32
+ @logger.ap(nil)
33
+ end
34
+
35
+ it 'should use the passed in level' do
36
+ expect(@logger).to receive(:warn)
37
+ @logger.ap(nil, :warn)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'String extensions' do
4
+ [:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white].each_with_index do |color, i|
5
+ it "should have #{color} color" do
6
+ expect(color.to_s.send(color)).to eq("\e[1;#{30 + i}m#{color}\e[0m")
7
+ end
8
+
9
+ it "should have #{color}ish color" do
10
+ expect(color.to_s.send(:"#{color}ish")).to eq("\e[0;#{30 + i}m#{color}\e[0m")
11
+ end
12
+ end
13
+
14
+ it 'should have black and pale colors' do
15
+ expect('black'.send(:black)).to eq('black'.send(:grayish))
16
+ expect('pale'.send(:pale)).to eq('pale'.send(:whiteish))
17
+ expect('pale'.send(:pale)).to eq("\e[0;37mpale\e[0m")
18
+ expect('whiteish'.send(:whiteish)).to eq("\e[0;37mwhiteish\e[0m")
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'AwesomePrint ActionView extensions', skip: -> { !ExtVerifier.has_rails? }.call do
4
+ before do
5
+ @view = if rails_6_1?
6
+ ActionView::Base.new(ActionView::LookupContext.new([]), {}, {})
7
+ else
8
+ ActionView::Base.new
9
+ end
10
+ end
11
+
12
+ it "uses HTML and adds 'debug_dump' class to plain <pre> tag" do
13
+ markup = rand
14
+ expect(@view.ap(markup, plain: true)).to eq(%Q|<pre class="debug_dump">#{markup}</pre>|)
15
+ end
16
+
17
+ it "uses HTML and adds 'debug_dump' class to colorized <pre> tag" do
18
+ markup = ' &<hello>'
19
+ expect(@view.ap(markup)).to eq('<pre class="debug_dump"><kbd style="color:brown">&quot; &amp;&lt;hello&gt;&quot;</kbd></pre>')
20
+ end
21
+ end