amazing_print 1.3.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +0 -6
- data/CHANGELOG.md +24 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +51 -47
- data/README.md +9 -7
- data/lib/amazing_print/colorize.rb +5 -14
- data/lib/amazing_print/colors.rb +37 -0
- 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 +1 -3
- data/lib/amazing_print/core_ext/object.rb +1 -1
- data/lib/amazing_print/custom_defaults.rb +10 -3
- data/lib/amazing_print/ext/active_record.rb +5 -9
- data/lib/amazing_print/ext/active_support.rb +1 -3
- data/lib/amazing_print/ext/mongo_mapper.rb +4 -7
- data/lib/amazing_print/ext/mongoid.rb +2 -6
- data/lib/amazing_print/ext/nobrainer.rb +3 -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 +7 -6
- 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 +11 -1
- data/lib/amazing_print/formatters/file_formatter.rb +11 -1
- data/lib/amazing_print/formatters/hash_formatter.rb +5 -3
- data/lib/amazing_print/formatters/method_formatter.rb +1 -0
- data/lib/amazing_print/formatters/mswin_helper.rb +63 -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 +3 -7
- data/spec/active_record_helper.rb +3 -0
- data/spec/colors_spec.rb +15 -6
- data/spec/core_ext/logger_spec.rb +7 -7
- data/spec/ext/action_controller_spec.rb +5 -5
- data/spec/ext/active_model_spec.rb +1 -1
- data/spec/ext/active_record_spec.rb +39 -73
- data/spec/ext/active_support_spec.rb +3 -3
- data/spec/ext/mongo_mapper_spec.rb +15 -11
- data/spec/ext/mongoid_spec.rb +7 -3
- data/spec/ext/nobrainer_spec.rb +6 -2
- data/spec/ext/nokogiri_spec.rb +7 -7
- data/spec/ext/ripple_spec.rb +6 -2
- data/spec/ext/sequel_spec.rb +1 -1
- data/spec/formats_spec.rb +101 -90
- data/spec/methods_spec.rb +12 -4
- data/spec/misc_spec.rb +29 -70
- data/spec/objects_spec.rb +4 -0
- data/spec/spec_helper.rb +11 -9
- metadata +10 -142
- data/lib/amazing_print/core_ext/string.rb +0 -45
- data/spec/core_ext/string_spec.rb +0 -15
data/spec/formats_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock
|
4
|
+
|
3
5
|
require 'spec_helper'
|
4
6
|
require 'bigdecimal'
|
5
7
|
require 'set'
|
@@ -91,7 +93,7 @@ RSpec.describe 'AmazingPrint' do
|
|
91
93
|
[
|
92
94
|
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
93
95
|
\e[1;37m[1] \e[0m\e[0;36m:two\e[0m,
|
94
|
-
\e[1;37m[2] \e[0m\e[0;33m
|
96
|
+
\e[1;37m[2] \e[0m\e[0;33m"three"\e[0m,
|
95
97
|
\e[1;37m[3] \e[0m[
|
96
98
|
\e[1;37m[0] \e[0m\e[1;31mnil\e[0m,
|
97
99
|
\e[1;37m[1] \e[0m[
|
@@ -108,7 +110,7 @@ RSpec.describe 'AmazingPrint' do
|
|
108
110
|
[
|
109
111
|
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
110
112
|
\e[1;37m[1] \e[0m\e[0;36m:two\e[0m,
|
111
|
-
\e[1;37m[2] \e[0m\e[0;33m
|
113
|
+
\e[1;37m[2] \e[0m\e[0;33m"three"\e[0m,
|
112
114
|
\e[1;37m[3] \e[0m[
|
113
115
|
\e[1;37m[0] \e[0m\e[1;31mnil\e[0m,
|
114
116
|
\e[1;37m[1] \e[0m[
|
@@ -159,7 +161,7 @@ RSpec.describe 'AmazingPrint' do
|
|
159
161
|
|
160
162
|
#------------------------------------------------------------------------------
|
161
163
|
describe 'Limited Output Array' do
|
162
|
-
before
|
164
|
+
before do
|
163
165
|
@arr = (1..1000).to_a
|
164
166
|
end
|
165
167
|
|
@@ -227,7 +229,7 @@ RSpec.describe 'AmazingPrint' do
|
|
227
229
|
|
228
230
|
#------------------------------------------------------------------------------
|
229
231
|
describe 'Limited Output Hash' do
|
230
|
-
before
|
232
|
+
before do
|
231
233
|
@hash = ('a'..'z').inject({}) { |h, v| h.merge({ v => v.to_sym }) }
|
232
234
|
end
|
233
235
|
|
@@ -305,7 +307,8 @@ RSpec.describe 'AmazingPrint' do
|
|
305
307
|
end
|
306
308
|
|
307
309
|
it 'plain single line' do
|
308
|
-
expect(@hash.ai(plain: true,
|
310
|
+
expect(@hash.ai(plain: true,
|
311
|
+
multiline: false)).to eq('{ 1 => { :sym => { "str" => { [ 1, 2, 3 ] => { { :k => :v } => Hash < Object } } } } }')
|
309
312
|
end
|
310
313
|
|
311
314
|
it 'colored multiline (default)' do
|
@@ -313,7 +316,7 @@ RSpec.describe 'AmazingPrint' do
|
|
313
316
|
{
|
314
317
|
1\e[0;37m => \e[0m{
|
315
318
|
:sym\e[0;37m => \e[0m{
|
316
|
-
|
319
|
+
"str"\e[0;37m => \e[0m{
|
317
320
|
[ 1, 2, 3 ]\e[0;37m => \e[0m{
|
318
321
|
{ :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m
|
319
322
|
}
|
@@ -328,8 +331,8 @@ RSpec.describe 'AmazingPrint' do
|
|
328
331
|
expect(@hash.ai(ruby19_syntax: true)).to eq <<~EOS.strip
|
329
332
|
{
|
330
333
|
1\e[0;37m => \e[0m{
|
331
|
-
sym
|
332
|
-
|
334
|
+
sym: {
|
335
|
+
"str"\e[0;37m => \e[0m{
|
333
336
|
[ 1, 2, 3 ]\e[0;37m => \e[0m{
|
334
337
|
{ k: :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m
|
335
338
|
}
|
@@ -345,7 +348,7 @@ RSpec.describe 'AmazingPrint' do
|
|
345
348
|
{
|
346
349
|
1\e[0;37m => \e[0m{
|
347
350
|
:sym\e[0;37m => \e[0m{
|
348
|
-
|
351
|
+
"str"\e[0;37m => \e[0m{
|
349
352
|
[ 1, 2, 3 ]\e[0;37m => \e[0m{
|
350
353
|
{ :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m
|
351
354
|
}
|
@@ -389,22 +392,14 @@ RSpec.describe 'AmazingPrint' do
|
|
389
392
|
|
390
393
|
it 'plain multiline' do
|
391
394
|
out = @hash.ai(plain: true)
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
{
|
401
|
-
"b" => "b",
|
402
|
-
:a => "a",
|
403
|
-
:z => "z",
|
404
|
-
"alpha" => "alpha"
|
405
|
-
}
|
406
|
-
EOS
|
407
|
-
end
|
395
|
+
expect(out).to eq <<~EOS.strip
|
396
|
+
{
|
397
|
+
"b" => "b",
|
398
|
+
:a => "a",
|
399
|
+
:z => "z",
|
400
|
+
"alpha" => "alpha"
|
401
|
+
}
|
402
|
+
EOS
|
408
403
|
end
|
409
404
|
|
410
405
|
it 'plain multiline with sorted keys' do
|
@@ -476,61 +471,79 @@ RSpec.describe 'AmazingPrint' do
|
|
476
471
|
end
|
477
472
|
end
|
478
473
|
|
474
|
+
#
|
475
|
+
# With Ruby 1.9 syntax
|
476
|
+
#
|
477
|
+
it 'hash keys must be left aligned' do
|
478
|
+
hash = { [0, 0, 255] => :yellow, :bloodiest_red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' }
|
479
|
+
out = hash.ai(plain: true, indent: -2, ruby19_syntax: true, sort_keys: true)
|
480
|
+
expect(out).to eq <<~EOS.strip
|
481
|
+
{
|
482
|
+
[ 0, 0, 255 ] => :yellow,
|
483
|
+
bloodiest_red: "rgb(255, 0, 0)",
|
484
|
+
"magenta" => "rgb(255, 0, 255)"
|
485
|
+
}
|
486
|
+
EOS
|
487
|
+
end
|
488
|
+
|
479
489
|
#------------------------------------------------------------------------------
|
480
490
|
describe 'Class' do
|
481
|
-
it '
|
491
|
+
it 'shows superclass (plain)' do
|
482
492
|
expect(self.class.ai(plain: true)).to eq("#{self.class} < #{self.class.superclass}")
|
483
493
|
end
|
484
494
|
|
485
|
-
it '
|
486
|
-
expect(self.class.ai).to eq("#{self.class} < #{self.class.superclass}"
|
495
|
+
it 'shows superclass (color)' do
|
496
|
+
expect(self.class.ai).to eq(AmazingPrint::Colors.yellow("#{self.class} < #{self.class.superclass}"))
|
487
497
|
end
|
488
498
|
end
|
489
499
|
|
490
500
|
#------------------------------------------------------------------------------
|
491
501
|
describe 'File' do
|
492
|
-
it '
|
502
|
+
it 'displays a file (plain)', unix: true do
|
493
503
|
File.open(__FILE__, 'r') do |f|
|
494
504
|
expect(f.ai(plain: true)).to eq("#{f.inspect}\n" + `ls -alF #{f.path}`.chop)
|
495
505
|
end
|
496
506
|
end
|
507
|
+
|
508
|
+
it 'displays a file (plain) akin to powershell Get-ChildItem', mswin: true do
|
509
|
+
File.open(__FILE__, 'r') do |f|
|
510
|
+
expect(f.ai(plain: true)).to eq("#{f.inspect}\n" + AmazingPrint::Formatters::GetChildItem.new(f.path).to_s)
|
511
|
+
end
|
512
|
+
end
|
497
513
|
end
|
498
514
|
|
499
515
|
#------------------------------------------------------------------------------
|
500
516
|
describe 'Dir' do
|
501
|
-
it '
|
517
|
+
it 'displays a direcory (plain)', unix: true do
|
502
518
|
Dir.open(File.dirname(__FILE__)) do |d|
|
503
519
|
expect(d.ai(plain: true)).to eq("#{d.inspect}\n" + `ls -alF #{d.path}`.chop)
|
504
520
|
end
|
505
521
|
end
|
522
|
+
|
523
|
+
it 'displays a directory (plain) akin to powershell Get-ChildItem', mswin: true do
|
524
|
+
Dir.open(File.dirname(__FILE__)) do |d|
|
525
|
+
expect(d.ai(plain: true)).to eq("#{d.inspect}\n" + AmazingPrint::Formatters::GetChildItem.new(d.path).to_s)
|
526
|
+
end
|
527
|
+
end
|
506
528
|
end
|
507
529
|
|
508
530
|
#------------------------------------------------------------------------------
|
509
531
|
describe 'BigDecimal and Rational' do
|
510
|
-
it '
|
532
|
+
it 'presents BigDecimal object with arbitrary precision' do
|
511
533
|
big = BigDecimal('201020102010201020102010201020102010.4')
|
512
534
|
expect(big.ai(plain: true)).to eq('201020102010201020102010201020102010.4')
|
513
535
|
end
|
514
536
|
|
515
|
-
it '
|
537
|
+
it 'presents Rational object with arbitrary precision' do
|
516
538
|
rat = Rational(201_020_102_010_201_020_102_010_201_020_102_010, 2)
|
517
539
|
out = rat.ai(plain: true)
|
518
|
-
|
519
|
-
# Ruby 1.9 slightly changed the format of Rational#to_s, see
|
520
|
-
# http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3 and
|
521
|
-
# http://www.ruby-forum.com/topic/189397
|
522
|
-
#
|
523
|
-
if RUBY_VERSION < '1.9'
|
524
|
-
expect(out).to eq('100510051005100510051005100510051005')
|
525
|
-
else
|
526
|
-
expect(out).to eq('100510051005100510051005100510051005/1')
|
527
|
-
end
|
540
|
+
expect(out).to eq('100510051005100510051005100510051005/1')
|
528
541
|
end
|
529
542
|
end
|
530
543
|
|
531
544
|
#------------------------------------------------------------------------------
|
532
545
|
describe 'Utility methods' do
|
533
|
-
it '
|
546
|
+
it 'merges options' do
|
534
547
|
ap = AmazingPrint::Inspector.new
|
535
548
|
ap.send(:merge_options!, { color: { array: :black }, indent: 0 })
|
536
549
|
options = ap.instance_variable_get('@options')
|
@@ -550,38 +563,20 @@ RSpec.describe 'AmazingPrint' do
|
|
550
563
|
expect(Set.new.ai).to eq([].ai)
|
551
564
|
end
|
552
565
|
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
end
|
557
|
-
|
558
|
-
it 'plain multiline indented' do
|
559
|
-
expect(@set.ai(plain: true, indent: 1)).to eq(@arr.ai(plain: true, indent: 1))
|
560
|
-
end
|
561
|
-
|
562
|
-
it 'plain single line' do
|
563
|
-
expect(@set.ai(plain: true, multiline: false)).to eq(@arr.ai(plain: true, multiline: false))
|
564
|
-
end
|
565
|
-
|
566
|
-
it 'colored multiline (default)' do
|
567
|
-
expect(@set.ai).to eq(@arr.ai)
|
568
|
-
end
|
569
|
-
else # Prior to Ruby 1.9 the order of set values is unpredicatble.
|
570
|
-
it 'plain multiline' do
|
571
|
-
expect(@set.sort_by(&:to_s).ai(plain: true)).to eq(@arr.sort_by(&:to_s).ai(plain: true))
|
572
|
-
end
|
566
|
+
it 'plain multiline' do
|
567
|
+
expect(@set.ai(plain: true)).to eq(@arr.ai(plain: true))
|
568
|
+
end
|
573
569
|
|
574
|
-
|
575
|
-
|
576
|
-
|
570
|
+
it 'plain multiline indented' do
|
571
|
+
expect(@set.ai(plain: true, indent: 1)).to eq(@arr.ai(plain: true, indent: 1))
|
572
|
+
end
|
577
573
|
|
578
|
-
|
579
|
-
|
580
|
-
|
574
|
+
it 'plain single line' do
|
575
|
+
expect(@set.ai(plain: true, multiline: false)).to eq(@arr.ai(plain: true, multiline: false))
|
576
|
+
end
|
581
577
|
|
582
|
-
|
583
|
-
|
584
|
-
end
|
578
|
+
it 'colored multiline (default)' do
|
579
|
+
expect(@set.ai).to eq(@arr.ai)
|
585
580
|
end
|
586
581
|
end
|
587
582
|
|
@@ -603,12 +598,12 @@ RSpec.describe 'AmazingPrint' do
|
|
603
598
|
|
604
599
|
it 'plain multiline' do
|
605
600
|
s1 = <<-EOS.strip
|
606
|
-
address =
|
607
|
-
name =
|
601
|
+
address = "1313 Mockingbird Lane",
|
602
|
+
name = "Herman Munster"
|
608
603
|
EOS
|
609
604
|
s2 = <<-EOS.strip
|
610
|
-
name =
|
611
|
-
address =
|
605
|
+
name = "Herman Munster",
|
606
|
+
address = "1313 Mockingbird Lane"
|
612
607
|
EOS
|
613
608
|
expect(@struct.ai(plain: true)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
614
609
|
end
|
@@ -633,12 +628,12 @@ RSpec.describe 'AmazingPrint' do
|
|
633
628
|
|
634
629
|
it 'colored multiline (default)' do
|
635
630
|
s1 = <<-EOS.strip
|
636
|
-
address\e[0;37m = \e[0m\e[0;33m
|
637
|
-
name\e[0;37m = \e[0m\e[0;33m
|
631
|
+
address\e[0;37m = \e[0m\e[0;33m"1313 Mockingbird Lane"\e[0m,
|
632
|
+
name\e[0;37m = \e[0m\e[0;33m"Herman Munster"\e[0m
|
638
633
|
EOS
|
639
634
|
s2 = <<-EOS.strip
|
640
|
-
name\e[0;37m = \e[0m\e[0;33m
|
641
|
-
address\e[0;37m = \e[0m\e[0;33m
|
635
|
+
name\e[0;37m = \e[0m\e[0;33m"Herman Munster"\e[0m,
|
636
|
+
address\e[0;37m = \e[0m\e[0;33m"1313 Mockingbird Lane"\e[0m
|
642
637
|
EOS
|
643
638
|
expect(@struct.ai).to satisfy { |out| out.include?(s1) || out.include?(s2) }
|
644
639
|
end
|
@@ -689,18 +684,24 @@ RSpec.describe 'AmazingPrint' do
|
|
689
684
|
EOS
|
690
685
|
end
|
691
686
|
|
692
|
-
it 'inherited from File should be displayed as File' do
|
687
|
+
it 'inherited from File should be displayed as File', unix: true do
|
693
688
|
class My < File; end
|
694
689
|
|
695
690
|
my = begin
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
691
|
+
File.new('/dev/null')
|
692
|
+
rescue StandardError
|
693
|
+
File.new('nul')
|
694
|
+
end
|
700
695
|
expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + `ls -alF #{my.path}`.chop)
|
701
696
|
end
|
702
697
|
|
703
|
-
it 'inherited from
|
698
|
+
it 'inherited from File should be displayed as File', mswin: true do
|
699
|
+
class My < File; end
|
700
|
+
my = My.new('nul') # it's /dev/null in Windows
|
701
|
+
expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + AmazingPrint::Formatters::GetChildItem.new(my.path).to_s)
|
702
|
+
end
|
703
|
+
|
704
|
+
it 'inherited from Dir should be displayed as Dir', unix: true do
|
704
705
|
class My < Dir; end
|
705
706
|
|
706
707
|
require 'tmpdir'
|
@@ -708,7 +709,15 @@ RSpec.describe 'AmazingPrint' do
|
|
708
709
|
expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + `ls -alF #{my.path}`.chop)
|
709
710
|
end
|
710
711
|
|
711
|
-
it '
|
712
|
+
it 'inherited from Dir are displayed as Dir', mswin: true do
|
713
|
+
class My < Dir; end
|
714
|
+
|
715
|
+
require 'tmpdir'
|
716
|
+
my = My.new(Dir.tmpdir)
|
717
|
+
expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + AmazingPrint::Formatters::GetChildItem.new(my.path).to_s)
|
718
|
+
end
|
719
|
+
|
720
|
+
it 'handles a class that defines its own #send method' do
|
712
721
|
class My
|
713
722
|
def send(arg1, arg2, arg3); end
|
714
723
|
end
|
@@ -717,7 +726,7 @@ RSpec.describe 'AmazingPrint' do
|
|
717
726
|
expect { my.methods.ai(plain: true) }.not_to raise_error
|
718
727
|
end
|
719
728
|
|
720
|
-
it '
|
729
|
+
it 'handles a class defines its own #method method (ex. request.method)' do
|
721
730
|
class My
|
722
731
|
def method
|
723
732
|
'POST'
|
@@ -753,7 +762,7 @@ RSpec.describe 'AmazingPrint' do
|
|
753
762
|
class My
|
754
763
|
def to_hash
|
755
764
|
object = Object.new
|
756
|
-
object.define_singleton_method('[]') {
|
765
|
+
object.define_singleton_method('[]') { nil }
|
757
766
|
|
758
767
|
object
|
759
768
|
end
|
@@ -767,7 +776,7 @@ RSpec.describe 'AmazingPrint' do
|
|
767
776
|
class My
|
768
777
|
def to_hash
|
769
778
|
object = Object.new
|
770
|
-
object.define_singleton_method(:keys) {
|
779
|
+
object.define_singleton_method(:keys) { [:foo] }
|
771
780
|
|
772
781
|
object
|
773
782
|
end
|
@@ -779,3 +788,5 @@ RSpec.describe 'AmazingPrint' do
|
|
779
788
|
end
|
780
789
|
end
|
781
790
|
end
|
791
|
+
|
792
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock
|
data/spec/methods_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock
|
4
|
+
|
3
5
|
require 'spec_helper'
|
4
6
|
|
5
7
|
RSpec.describe 'Single method' do
|
@@ -385,7 +387,8 @@ if RUBY_VERSION >= '1.9.2'
|
|
385
387
|
|
386
388
|
it ':opt' do
|
387
389
|
class Hello
|
388
|
-
|
390
|
+
# m1(a, *b, *c)
|
391
|
+
def m1(a, b = 1, c = 2); end
|
389
392
|
end
|
390
393
|
out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
|
391
394
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/)
|
@@ -393,7 +396,8 @@ if RUBY_VERSION >= '1.9.2'
|
|
393
396
|
|
394
397
|
it ':rest' do
|
395
398
|
class Hello
|
396
|
-
|
399
|
+
# m1(*a)
|
400
|
+
def m1(*a); end
|
397
401
|
end
|
398
402
|
out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
|
399
403
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/)
|
@@ -401,7 +405,8 @@ if RUBY_VERSION >= '1.9.2'
|
|
401
405
|
|
402
406
|
it ':block' do
|
403
407
|
class Hello
|
404
|
-
|
408
|
+
# m1(a, *b, &blk)
|
409
|
+
def m1(a, b = nil, &blk); end
|
405
410
|
end
|
406
411
|
out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
|
407
412
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, &blk\)\s+Hello$/)
|
@@ -431,10 +436,11 @@ RSpec.describe 'Methods arrays' do
|
|
431
436
|
|
432
437
|
def self.m2; end
|
433
438
|
end
|
439
|
+
|
434
440
|
class World
|
435
441
|
def self.m1; end
|
436
442
|
end
|
437
|
-
out = (Hello.methods & World.methods - Class.methods).ai(plain: true)
|
443
|
+
out = (Hello.methods & (World.methods - Class.methods)).ai(plain: true)
|
438
444
|
expect(out).to eq("[\n [0] m1() Hello\n]")
|
439
445
|
end
|
440
446
|
|
@@ -510,3 +516,5 @@ RSpec.describe 'Methods arrays' do
|
|
510
516
|
end
|
511
517
|
end
|
512
518
|
end
|
519
|
+
|
520
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock
|
data/spec/misc_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock, Lint/EmptyClass
|
4
|
+
|
3
5
|
require 'spec_helper'
|
4
6
|
|
5
7
|
RSpec.describe 'AmazingPrint' do
|
@@ -24,18 +26,16 @@ RSpec.describe 'AmazingPrint' do
|
|
24
26
|
|
25
27
|
# See https://github.com/awesome-print/awesome_print/issues/35
|
26
28
|
it 'handle array grep when pattern contains / chapacter' do
|
27
|
-
hash = { '1/x' => 1, '2//x' => :
|
29
|
+
hash = { '1/x' => 1, '2//x' => :'2' }
|
28
30
|
grepped = hash.keys.sort.grep(%r{^(\d+)/}) { Regexp.last_match(1) }
|
29
31
|
expect(grepped.ai(plain: true, multiline: false)).to eq('[ "1", "2" ]')
|
30
32
|
end
|
31
33
|
|
32
34
|
# See https://github.com/awesome-print/awesome_print/issues/85
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
expect(grepped.ai(plain: true, multiline: false)).to eq('[ 2, 3, 4, 5 ]')
|
38
|
-
end
|
35
|
+
it "handle array grep when a method is defined in C and thus doesn't have a binding" do
|
36
|
+
arr = (0..6).to_a
|
37
|
+
grepped = arr.grep(1..4, &:succ)
|
38
|
+
expect(grepped.ai(plain: true, multiline: false)).to eq('[ 2, 3, 4, 5 ]')
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'returns value passed as a parameter' do
|
@@ -46,7 +46,7 @@ RSpec.describe 'AmazingPrint' do
|
|
46
46
|
|
47
47
|
# Require different file name this time (lib/ap.rb vs. lib/amazing_print).
|
48
48
|
it "several require 'amazing_print' should do no harm" do
|
49
|
-
require File.expand_path(File.dirname(__FILE__)
|
49
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../lib/ap")
|
50
50
|
expect { rand.ai }.not_to raise_error
|
51
51
|
end
|
52
52
|
|
@@ -127,7 +127,7 @@ RSpec.describe 'AmazingPrint' do
|
|
127
127
|
end
|
128
128
|
|
129
129
|
# See https://github.com/awesome-print/awesome_print/issues/98
|
130
|
-
it '
|
130
|
+
it 'properlies merge the defaults' do
|
131
131
|
AmazingPrint.defaults = { indent: -2, sort_keys: true }
|
132
132
|
hash = { [0, 0, 255] => :yellow, :red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' }
|
133
133
|
out = hash.ai(plain: true)
|
@@ -141,94 +141,51 @@ RSpec.describe 'AmazingPrint' do
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
-
#------------------------------------------------------------------------------
|
145
|
-
describe 'Coexistence with the colorize gem' do
|
146
|
-
before do # Redefine String#red just like colorize gem does it.
|
147
|
-
@awesome_method = ''.method(:red)
|
148
|
-
|
149
|
-
String.instance_eval do
|
150
|
-
define_method :red do # Method arity is now 0 in Ruby 1.9+.
|
151
|
-
"[red]#{self}[/red]"
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
after do # Restore String#red method.
|
157
|
-
awesome_method = @awesome_method
|
158
|
-
String.instance_eval do
|
159
|
-
define_method :red, awesome_method
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'shoud not raise ArgumentError when formatting HTML' do
|
164
|
-
out = 'hello'.ai(color: { string: :red }, html: true)
|
165
|
-
if RUBY_VERSION >= '1.9'
|
166
|
-
expect(out).to eq(%(<pre>[red]<kbd style="color:red">"hello"</kbd>[/red]</pre>))
|
167
|
-
else
|
168
|
-
expect(out).to eq(%(<pre>[red]"hello"[/red]</pre>))
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'shoud not raise ArgumentError when formatting HTML (shade color)' do
|
173
|
-
out = 'hello'.ai(color: { string: :redish }, html: true)
|
174
|
-
expect(out).to eq(%(<pre><kbd style="color:darkred">"hello"</kbd></pre>))
|
175
|
-
end
|
176
|
-
|
177
|
-
it 'shoud not raise ArgumentError when formatting non-HTML' do
|
178
|
-
out = 'hello'.ai(color: { string: :red }, html: false)
|
179
|
-
expect(out).to eq(%([red]"hello"[/red]))
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'shoud not raise ArgumentError when formatting non-HTML (shade color)' do
|
183
|
-
out = 'hello'.ai(color: { string: :redish }, html: false)
|
184
|
-
expect(out).to eq(%(\e[0;31m"hello"\e[0m))
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
144
|
#------------------------------------------------------------------------------
|
189
145
|
describe 'Console' do
|
190
|
-
it '
|
146
|
+
it 'detects IRB' do
|
191
147
|
class IRB; end
|
192
148
|
ENV.delete('RAILS_ENV')
|
193
|
-
expect(AmazingPrint.console?).to
|
194
|
-
expect(AmazingPrint.rails_console?).to
|
149
|
+
expect(AmazingPrint.console?).to be(true)
|
150
|
+
expect(AmazingPrint.rails_console?).to be(false)
|
195
151
|
Object.instance_eval { remove_const :IRB }
|
196
152
|
end
|
197
153
|
|
198
|
-
it '
|
154
|
+
it 'detects Pry' do
|
199
155
|
class Pry; end
|
200
156
|
ENV.delete('RAILS_ENV')
|
201
|
-
expect(AmazingPrint.console?).to
|
202
|
-
expect(AmazingPrint.rails_console?).to
|
157
|
+
expect(AmazingPrint.console?).to be(true)
|
158
|
+
expect(AmazingPrint.rails_console?).to be(false)
|
203
159
|
Object.instance_eval { remove_const :Pry }
|
204
160
|
end
|
205
161
|
|
206
|
-
it '
|
162
|
+
it 'detects Rails::Console' do
|
207
163
|
class IRB; end
|
164
|
+
|
208
165
|
module Rails; class Console; end; end
|
209
|
-
expect(AmazingPrint.console?).to
|
210
|
-
expect(AmazingPrint.rails_console?).to
|
166
|
+
expect(AmazingPrint.console?).to be(true)
|
167
|
+
expect(AmazingPrint.rails_console?).to be(true)
|
211
168
|
Object.instance_eval { remove_const :IRB }
|
212
169
|
Object.instance_eval { remove_const :Rails }
|
213
170
|
end
|
214
171
|
|
215
|
-
it "
|
172
|
+
it "detects ENV['RAILS_ENV']" do
|
216
173
|
class Pry; end
|
217
174
|
ENV['RAILS_ENV'] = 'development'
|
218
|
-
expect(AmazingPrint.console?).to
|
219
|
-
expect(AmazingPrint.rails_console?).to
|
175
|
+
expect(AmazingPrint.console?).to be(true)
|
176
|
+
expect(AmazingPrint.rails_console?).to be(true)
|
220
177
|
Object.instance_eval { remove_const :Pry }
|
221
178
|
end
|
222
179
|
|
223
|
-
it '
|
180
|
+
it 'returns the actual object when *not* running under console' do
|
224
181
|
expect(capture! { ap([1, 2, 3]) }).to eq([1, 2, 3])
|
225
182
|
expect(capture! { ap({ a: 1 }) }).to eq({ a: 1 })
|
226
183
|
end
|
227
184
|
|
228
|
-
it '
|
185
|
+
it 'returns nil when running under console' do
|
229
186
|
class IRB; end
|
230
|
-
expect(capture! { ap([1, 2, 3]) }).to
|
231
|
-
expect(capture! { ap({ a: 1 }) }).to
|
187
|
+
expect(capture! { ap([1, 2, 3]) }).to be_nil
|
188
|
+
expect(capture! { ap({ a: 1 }) }).to be_nil
|
232
189
|
Object.instance_eval { remove_const :IRB }
|
233
190
|
end
|
234
191
|
|
@@ -240,8 +197,10 @@ RSpec.describe 'AmazingPrint' do
|
|
240
197
|
irb.instance_eval { @context = irb_context }
|
241
198
|
AmazingPrint.irb!
|
242
199
|
expect(irb).to receive(:puts).with("(Object doesn't support #ai)")
|
243
|
-
expect { irb.output_value }.
|
200
|
+
expect { irb.output_value }.not_to raise_error
|
244
201
|
Object.instance_eval { remove_const :IRB }
|
245
202
|
end
|
246
203
|
end
|
247
204
|
end
|
205
|
+
|
206
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock, Lint/EmptyClass
|
data/spec/objects_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock
|
4
|
+
|
3
5
|
require 'spec_helper'
|
4
6
|
|
5
7
|
RSpec.describe 'Objects' do
|
@@ -219,3 +221,5 @@ RSpec.describe 'Objects' do
|
|
219
221
|
end
|
220
222
|
end
|
221
223
|
end
|
224
|
+
|
225
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock
|
data/spec/spec_helper.rb
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
24
24
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
25
25
|
|
26
|
-
Dir[File.dirname(__FILE__)
|
26
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each do |file|
|
27
27
|
require file
|
28
28
|
end
|
29
29
|
|
@@ -41,7 +41,7 @@ ExtVerifier.require_dependencies!(
|
|
41
41
|
sequel
|
42
42
|
]
|
43
43
|
)
|
44
|
-
require 'nokogiri'
|
44
|
+
require 'nokogiri' unless RUBY_PLATFORM.include?('mswin')
|
45
45
|
require 'amazing_print'
|
46
46
|
|
47
47
|
RSpec.configure do |config|
|
@@ -63,9 +63,15 @@ RSpec.configure do |config|
|
|
63
63
|
|
64
64
|
# Run before all examples. Using suite or all will not work as stubs are
|
65
65
|
# killed after each example ends.
|
66
|
-
config.before
|
66
|
+
config.before do |_example|
|
67
67
|
stub_dotfile!
|
68
68
|
end
|
69
|
+
|
70
|
+
if RUBY_PLATFORM.include?('mswin')
|
71
|
+
config.filter_run_excluding unix: true
|
72
|
+
else
|
73
|
+
config.filter_run_excluding mswin: true
|
74
|
+
end
|
69
75
|
end
|
70
76
|
|
71
77
|
# This matcher handles the normalization of objects to replace non deterministic
|
@@ -86,12 +92,8 @@ end
|
|
86
92
|
# that an ID is present and not that it matches a certain value. This is
|
87
93
|
# necessary as the Object IDs are not deterministic.
|
88
94
|
def normalize_object_id_strings(str, options)
|
89
|
-
unless options[:skip_standard]
|
90
|
-
|
91
|
-
end
|
92
|
-
unless options[:skip_bson]
|
93
|
-
str = str.gsub(/BSON::ObjectId\('[a-f\d]{24}'\)/, 'placeholder_bson_id')
|
94
|
-
end
|
95
|
+
str = str.gsub(/#<(.*?):0x[a-f\d]+/, '#<\1:placeholder_id') unless options[:skip_standard]
|
96
|
+
str = str.gsub(/BSON::ObjectId\('[a-f\d]{24}'\)/, 'placeholder_bson_id') unless options[:skip_bson]
|
95
97
|
str
|
96
98
|
end
|
97
99
|
|