awesome_print 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +10 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +47 -38
- data/Rakefile +5 -5
- data/lib/ap.rb +2 -2
- data/lib/awesome_print.rb +18 -17
- data/lib/awesome_print/colorize.rb +1 -1
- data/lib/awesome_print/core_ext/{array.rb → awesome_method_array.rb} +16 -18
- data/lib/awesome_print/core_ext/class.rb +3 -2
- data/lib/awesome_print/core_ext/kernel.rb +1 -1
- data/lib/awesome_print/core_ext/logger.rb +1 -1
- data/lib/awesome_print/core_ext/method.rb +2 -2
- data/lib/awesome_print/core_ext/object.rb +3 -2
- data/lib/awesome_print/core_ext/string.rb +3 -3
- data/lib/awesome_print/custom_defaults.rb +57 -0
- data/lib/awesome_print/ext/action_view.rb +8 -4
- data/lib/awesome_print/ext/active_record.rb +19 -11
- data/lib/awesome_print/ext/active_support.rb +1 -1
- data/lib/awesome_print/ext/mongo_mapper.rb +16 -13
- data/lib/awesome_print/ext/mongoid.rb +8 -6
- data/lib/awesome_print/ext/nobrainer.rb +8 -5
- data/lib/awesome_print/ext/nokogiri.rb +4 -4
- data/lib/awesome_print/ext/ostruct.rb +1 -1
- data/lib/awesome_print/ext/ripple.rb +5 -6
- data/lib/awesome_print/ext/sequel.rb +7 -6
- data/lib/awesome_print/formatter.rb +11 -19
- data/lib/awesome_print/formatters.rb +15 -0
- data/lib/awesome_print/formatters/array_formatter.rb +108 -42
- data/lib/awesome_print/formatters/base_formatter.rb +13 -11
- data/lib/awesome_print/formatters/class_formatter.rb +2 -1
- data/lib/awesome_print/formatters/dir_formatter.rb +1 -1
- data/lib/awesome_print/formatters/file_formatter.rb +1 -1
- data/lib/awesome_print/formatters/hash_formatter.rb +74 -22
- data/lib/awesome_print/formatters/object_formatter.rb +9 -14
- data/lib/awesome_print/formatters/struct_formatter.rb +71 -0
- data/lib/awesome_print/inspector.rb +77 -93
- data/lib/awesome_print/version.rb +2 -2
- data/spec/active_record_helper.rb +8 -2
- data/spec/colors_spec.rb +30 -30
- data/spec/core_ext/logger_spec.rb +43 -0
- data/spec/core_ext/string_spec.rb +20 -0
- data/spec/ext/action_view_spec.rb +18 -0
- data/spec/ext/active_record_spec.rb +252 -0
- data/spec/ext/active_support_spec.rb +26 -0
- data/spec/ext/mongo_mapper_spec.rb +261 -0
- data/spec/ext/mongoid_spec.rb +104 -0
- data/spec/ext/nobrainer_spec.rb +59 -0
- data/spec/ext/nokogiri_spec.rb +46 -0
- data/spec/ext/ostruct_spec.rb +22 -0
- data/spec/ext/ripple_spec.rb +48 -0
- data/spec/formats_spec.rb +193 -165
- data/spec/methods_spec.rb +116 -128
- data/spec/misc_spec.rb +104 -108
- data/spec/objects_spec.rb +70 -28
- data/spec/spec_helper.rb +27 -10
- data/spec/support/active_record_data.rb +20 -0
- data/spec/support/active_record_data/3_2_diana.txt +24 -0
- data/spec/support/active_record_data/3_2_diana_legacy.txt +24 -0
- data/spec/support/active_record_data/3_2_multi.txt +50 -0
- data/spec/support/active_record_data/3_2_multi_legacy.txt +50 -0
- data/spec/support/active_record_data/4_0_diana.txt +98 -0
- data/spec/support/active_record_data/4_0_multi.txt +198 -0
- data/spec/support/active_record_data/4_1_diana.txt +97 -0
- data/spec/support/active_record_data/4_1_multi.txt +196 -0
- data/spec/support/active_record_data/4_2_diana.txt +109 -0
- data/spec/support/active_record_data/4_2_diana_legacy.txt +109 -0
- data/spec/support/active_record_data/4_2_multi.txt +220 -0
- data/spec/support/active_record_data/4_2_multi_legacy.txt +220 -0
- data/spec/support/active_record_data/5_0_diana.txt +105 -0
- data/spec/support/active_record_data/5_0_multi.txt +212 -0
- data/spec/support/ext_verifier.rb +42 -0
- data/spec/support/mongoid_versions.rb +22 -0
- data/spec/support/rails_versions.rb +35 -0
- metadata +79 -4
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'AwesomePrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.call do
|
4
|
+
|
5
|
+
if ExtVerifier.has_mongoid?
|
6
|
+
before :all do
|
7
|
+
class MongoUser
|
8
|
+
include Mongoid::Document
|
9
|
+
|
10
|
+
field :first_name, type: String
|
11
|
+
field :last_name, type: String
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after :all do
|
16
|
+
Object.instance_eval { remove_const :MongoUser }
|
17
|
+
Object.instance_eval { remove_const :Chamelion }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
@ap = AwesomePrint::Inspector.new plain: true, sort_keys: true
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should print class instance' do
|
26
|
+
user = MongoUser.new first_name: 'Al', last_name: 'Capone'
|
27
|
+
out = @ap.send :awesome, user
|
28
|
+
|
29
|
+
object_id = user.id.inspect
|
30
|
+
str = <<-EOS.strip
|
31
|
+
#<MongoUser:placeholder_id> {
|
32
|
+
:_id => #{object_id},
|
33
|
+
:first_name => "Al",
|
34
|
+
:last_name => "Capone"
|
35
|
+
}
|
36
|
+
EOS
|
37
|
+
expect(out).to be_similar_to(str, { skip_bson: true })
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should print the class' do
|
41
|
+
class_spec = if mongoid_3_0?
|
42
|
+
<<-EOS.strip
|
43
|
+
class MongoUser < Object {
|
44
|
+
:_id => :"moped/bson/object_id",
|
45
|
+
:_type => :string,
|
46
|
+
:first_name => :string,
|
47
|
+
:last_name => :string
|
48
|
+
}
|
49
|
+
EOS
|
50
|
+
elsif mongoid_3_1?
|
51
|
+
<<-EOS.strip
|
52
|
+
class MongoUser < Object {
|
53
|
+
:_id => :"moped/bson/object_id",
|
54
|
+
:first_name => :string,
|
55
|
+
:last_name => :string
|
56
|
+
}
|
57
|
+
EOS
|
58
|
+
elsif mongoid_4_0?
|
59
|
+
<<-EOS.strip
|
60
|
+
class MongoUser < Object {
|
61
|
+
:_id => :"bson/object_id",
|
62
|
+
:first_name => :string,
|
63
|
+
:last_name => :string
|
64
|
+
}
|
65
|
+
EOS
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(@ap.send(:awesome, MongoUser)).to eq class_spec
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should print the class when type is undefined' do
|
72
|
+
class Chamelion
|
73
|
+
include Mongoid::Document
|
74
|
+
field :last_attribute
|
75
|
+
end
|
76
|
+
|
77
|
+
class_spec = if mongoid_3_0?
|
78
|
+
<<-EOS.strip
|
79
|
+
class Chamelion < Object {
|
80
|
+
:_id => :"moped/bson/object_id",
|
81
|
+
:_type => :string,
|
82
|
+
:last_attribute => :object
|
83
|
+
}
|
84
|
+
EOS
|
85
|
+
elsif mongoid_3_1?
|
86
|
+
<<-EOS.strip
|
87
|
+
class Chamelion < Object {
|
88
|
+
:_id => :"moped/bson/object_id",
|
89
|
+
:last_attribute => :object
|
90
|
+
}
|
91
|
+
EOS
|
92
|
+
elsif mongoid_4_0?
|
93
|
+
<<-EOS.strip
|
94
|
+
class Chamelion < Object {
|
95
|
+
:_id => :"bson/object_id",
|
96
|
+
:last_attribute => :object
|
97
|
+
}
|
98
|
+
EOS
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
expect(@ap.send(:awesome, Chamelion)).to eq class_spec
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'AwesomePrint/NoBrainer', skip: -> { !ExtVerifier.has_nobrainer? }.call do
|
4
|
+
|
5
|
+
if ExtVerifier.has_nobrainer?
|
6
|
+
before :all do
|
7
|
+
NoBrainer.configure do |config|
|
8
|
+
config.app_name = 'ap_test'
|
9
|
+
config.environment = :test
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
before :all do
|
14
|
+
class SomeModel
|
15
|
+
include NoBrainer::Document
|
16
|
+
|
17
|
+
field :first_name, type: String
|
18
|
+
field :last_name, type: String
|
19
|
+
field :some_field
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
after :all do
|
24
|
+
Object.instance_eval { remove_const :SomeModel }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
before do
|
29
|
+
@ap = AwesomePrint::Inspector.new plain: true
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should print class instance' do
|
33
|
+
user = SomeModel.new first_name: 'Al', last_name: 'Capone'
|
34
|
+
out = @ap.send :awesome, user
|
35
|
+
|
36
|
+
object_id = user.id.inspect
|
37
|
+
str = <<-EOS.strip
|
38
|
+
#<SomeModel id: #{object_id}> {
|
39
|
+
:id => #{object_id},
|
40
|
+
:first_name => "Al",
|
41
|
+
:last_name => "Capone"
|
42
|
+
}
|
43
|
+
EOS
|
44
|
+
expect(out).to eq(str)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should print the class' do
|
48
|
+
class_spec = <<-EOS.strip
|
49
|
+
class SomeModel < Object {
|
50
|
+
:id => :string,
|
51
|
+
:first_name => :string,
|
52
|
+
:last_name => :string,
|
53
|
+
:some_field => :object
|
54
|
+
}
|
55
|
+
EOS
|
56
|
+
|
57
|
+
expect(@ap.send(:awesome, SomeModel)).to eq class_spec
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'AwesomePrint/Nokogiri' do
|
4
|
+
it 'should colorize tags' do
|
5
|
+
xml = Nokogiri::XML('<html><body><h1></h1></body></html>')
|
6
|
+
expect(xml.ai).to eq <<-EOS
|
7
|
+
<?xml version=\"1.0\"?>\e[1;32m
|
8
|
+
\e[0m<\e[1;36mhtml\e[0m>\e[1;32m
|
9
|
+
\e[0m<\e[1;36mbody\e[0m>\e[1;32m
|
10
|
+
\e[0m<\e[1;36mh1\e[0m/>\e[1;32m
|
11
|
+
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
12
|
+
\e[0m<\e[1;36m/html\e[0m>
|
13
|
+
EOS
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should colorize contents' do
|
17
|
+
xml = Nokogiri::XML('<html><body><h1>Hello</h1></body></html>')
|
18
|
+
expect(xml.ai).to eq <<-EOS
|
19
|
+
<?xml version=\"1.0\"?>\e[1;32m
|
20
|
+
\e[0m<\e[1;36mhtml\e[0m>\e[1;32m
|
21
|
+
\e[0m<\e[1;36mbody\e[0m>\e[1;32m
|
22
|
+
\e[0m<\e[1;36mh1\e[0m>\e[1;32mHello\e[0m<\e[1;36m/h1\e[0m>\e[1;32m
|
23
|
+
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
24
|
+
\e[0m<\e[1;36m/html\e[0m>
|
25
|
+
EOS
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should colorize class and id' do
|
29
|
+
xml = Nokogiri::XML('<html><body><h1><span id="hello" class="world"></span></h1></body></html>')
|
30
|
+
expect(xml.ai).to eq <<-EOS
|
31
|
+
<?xml version=\"1.0\"?>\e[1;32m
|
32
|
+
\e[0m<\e[1;36mhtml\e[0m>\e[1;32m
|
33
|
+
\e[0m<\e[1;36mbody\e[0m>\e[1;32m
|
34
|
+
\e[0m<\e[1;36mh1\e[0m>\e[1;32m
|
35
|
+
\e[0m<\e[1;36mspan\e[0m \e[1;33mid=\"hello\"\e[0m \e[1;33mclass=\"world\"\e[0m/>\e[1;32m
|
36
|
+
\e[0m<\e[1;36m/h1\e[0m>\e[1;32m
|
37
|
+
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
38
|
+
\e[0m<\e[1;36m/html\e[0m>
|
39
|
+
EOS
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'handle empty NodeSet' do
|
43
|
+
xml = Nokogiri::XML::NodeSet.new(Nokogiri::XML(''))
|
44
|
+
expect(xml.ai).to eq('[]')
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'AwesomePrint Ostruct extension' do
|
4
|
+
before do
|
5
|
+
@ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'empty hash' do
|
9
|
+
struct = OpenStruct.new
|
10
|
+
expect(@ap.send(:awesome, struct)).to eq('OpenStruct {}')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'plain multiline' do
|
14
|
+
struct = OpenStruct.new name: 'Foo', address: 'Bar'
|
15
|
+
expect(@ap.send(:awesome, struct)).to eq <<-EOS.strip
|
16
|
+
OpenStruct {
|
17
|
+
:address => "Bar",
|
18
|
+
:name => "Foo"
|
19
|
+
}
|
20
|
+
EOS
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'AwesomePrint/Ripple', skip: -> { !ExtVerifier.has_ripple? }.call do
|
4
|
+
|
5
|
+
if ExtVerifier.has_ripple?
|
6
|
+
before :all do
|
7
|
+
class RippleUser
|
8
|
+
include Ripple::Document
|
9
|
+
|
10
|
+
key_on :_id
|
11
|
+
property :_id, String
|
12
|
+
property :first_name, String
|
13
|
+
property :last_name, String
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
after :all do
|
18
|
+
Object.instance_eval { remove_const :RippleUser }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
@ap = AwesomePrint::Inspector.new plain: true, sort_keys: true
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should print class instance' do
|
27
|
+
user = RippleUser.new _id: '12345', first_name: 'Al', last_name: 'Capone'
|
28
|
+
out = @ap.send :awesome, user
|
29
|
+
|
30
|
+
expect(out).to be_similar_to <<-EOS.strip
|
31
|
+
#<RippleUser:placeholder_id> {
|
32
|
+
:_id => "12345",
|
33
|
+
:first_name => "Al",
|
34
|
+
:last_name => "Capone"
|
35
|
+
}
|
36
|
+
EOS
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should print the class' do
|
40
|
+
expect(@ap.send(:awesome, RippleUser)).to eq <<-EOS.strip
|
41
|
+
class RippleUser < Object {
|
42
|
+
:_id => :string,
|
43
|
+
:first_name => :string,
|
44
|
+
:last_name => :string
|
45
|
+
}
|
46
|
+
EOS
|
47
|
+
end
|
48
|
+
end
|
data/spec/formats_spec.rb
CHANGED
@@ -1,24 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require 'bigdecimal'
|
3
|
+
require 'rational'
|
4
|
+
require 'set'
|
5
5
|
|
6
|
-
RSpec.describe
|
7
|
-
|
8
|
-
stub_dotfile!
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "Array" do
|
6
|
+
RSpec.describe 'AwesomePrint' do
|
7
|
+
describe 'Array' do
|
12
8
|
before do
|
13
|
-
@arr = [
|
9
|
+
@arr = [1, :two, 'three', [nil, [true, false]]]
|
14
10
|
end
|
15
11
|
|
16
|
-
it
|
17
|
-
expect([].ai).to eq(
|
12
|
+
it 'empty array' do
|
13
|
+
expect([].ai).to eq('[]')
|
18
14
|
end
|
19
15
|
|
20
|
-
it
|
21
|
-
expect(@arr.ai(:
|
16
|
+
it 'plain multiline' do
|
17
|
+
expect(@arr.ai(plain: true)).to eq <<-EOS.strip
|
22
18
|
[
|
23
19
|
[0] 1,
|
24
20
|
[1] :two,
|
@@ -34,8 +30,8 @@ RSpec.describe "AwesomePrint" do
|
|
34
30
|
EOS
|
35
31
|
end
|
36
32
|
|
37
|
-
it
|
38
|
-
expect(@arr.ai(:
|
33
|
+
it 'plain multiline without index' do
|
34
|
+
expect(@arr.ai(plain: true, index: false)).to eq <<-EOS.strip
|
39
35
|
[
|
40
36
|
1,
|
41
37
|
:two,
|
@@ -51,8 +47,8 @@ EOS
|
|
51
47
|
EOS
|
52
48
|
end
|
53
49
|
|
54
|
-
it
|
55
|
-
expect(@arr.ai(:
|
50
|
+
it 'plain multiline indented' do
|
51
|
+
expect(@arr.ai(plain: true, indent: 2)).to eq <<-EOS.strip
|
56
52
|
[
|
57
53
|
[0] 1,
|
58
54
|
[1] :two,
|
@@ -68,8 +64,8 @@ EOS
|
|
68
64
|
EOS
|
69
65
|
end
|
70
66
|
|
71
|
-
it
|
72
|
-
expect(@arr.ai(:
|
67
|
+
it 'plain multiline indented without index' do
|
68
|
+
expect(@arr.ai(plain: true, indent: 2, index: false)).to eq <<-EOS.strip
|
73
69
|
[
|
74
70
|
1,
|
75
71
|
:two,
|
@@ -85,11 +81,11 @@ EOS
|
|
85
81
|
EOS
|
86
82
|
end
|
87
83
|
|
88
|
-
it
|
89
|
-
expect(@arr.ai(:
|
84
|
+
it 'plain single line' do
|
85
|
+
expect(@arr.ai(plain: true, multiline: false)).to eq('[ 1, :two, "three", [ nil, [ true, false ] ] ]')
|
90
86
|
end
|
91
87
|
|
92
|
-
it
|
88
|
+
it 'colored multiline (default)' do
|
93
89
|
expect(@arr.ai).to eq <<-EOS.strip
|
94
90
|
[
|
95
91
|
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
@@ -106,8 +102,8 @@ EOS
|
|
106
102
|
EOS
|
107
103
|
end
|
108
104
|
|
109
|
-
it
|
110
|
-
expect(@arr.ai(:
|
105
|
+
it 'colored multiline indented' do
|
106
|
+
expect(@arr.ai(indent: 8)).to eq <<-EOS.strip
|
111
107
|
[
|
112
108
|
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
113
109
|
\e[1;37m[1] \e[0m\e[0;36m:two\e[0m,
|
@@ -123,20 +119,20 @@ EOS
|
|
123
119
|
EOS
|
124
120
|
end
|
125
121
|
|
126
|
-
it
|
127
|
-
expect(@arr.ai(:
|
122
|
+
it 'colored single line' do
|
123
|
+
expect(@arr.ai(multiline: false)).to eq("[ \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 ] ] ]")
|
128
124
|
end
|
129
125
|
end
|
130
126
|
|
131
127
|
#------------------------------------------------------------------------------
|
132
|
-
describe
|
128
|
+
describe 'Nested Array' do
|
133
129
|
before do
|
134
|
-
@arr = [
|
130
|
+
@arr = [1, 2]
|
135
131
|
@arr << @arr
|
136
132
|
end
|
137
133
|
|
138
|
-
it
|
139
|
-
expect(@arr.ai(:
|
134
|
+
it 'plain multiline' do
|
135
|
+
expect(@arr.ai(plain: true)).to eq <<-EOS.strip
|
140
136
|
[
|
141
137
|
[0] 1,
|
142
138
|
[1] 2,
|
@@ -145,8 +141,8 @@ EOS
|
|
145
141
|
EOS
|
146
142
|
end
|
147
143
|
|
148
|
-
it
|
149
|
-
expect(@arr.ai(:
|
144
|
+
it 'plain multiline without index' do
|
145
|
+
expect(@arr.ai(plain: true, index: false)).to eq <<-EOS.strip
|
150
146
|
[
|
151
147
|
1,
|
152
148
|
2,
|
@@ -155,19 +151,19 @@ EOS
|
|
155
151
|
EOS
|
156
152
|
end
|
157
153
|
|
158
|
-
it
|
159
|
-
expect(@arr.ai(:
|
154
|
+
it 'plain single line' do
|
155
|
+
expect(@arr.ai(plain: true, multiline: false)).to eq('[ 1, 2, [...] ]')
|
160
156
|
end
|
161
157
|
end
|
162
158
|
|
163
159
|
#------------------------------------------------------------------------------
|
164
|
-
describe
|
160
|
+
describe 'Limited Output Array' do
|
165
161
|
before(:each) do
|
166
162
|
@arr = (1..1000).to_a
|
167
163
|
end
|
168
164
|
|
169
|
-
it
|
170
|
-
expect(@arr.ai(:
|
165
|
+
it 'plain limited output large' do
|
166
|
+
expect(@arr.ai(plain: true, limit: true)).to eq <<-EOS.strip
|
171
167
|
[
|
172
168
|
[ 0] 1,
|
173
169
|
[ 1] 2,
|
@@ -180,9 +176,9 @@ EOS
|
|
180
176
|
EOS
|
181
177
|
end
|
182
178
|
|
183
|
-
it
|
179
|
+
it 'plain limited output small' do
|
184
180
|
@arr = @arr[0..3]
|
185
|
-
expect(@arr.ai(:
|
181
|
+
expect(@arr.ai(plain: true, limit: true)).to eq <<-EOS.strip
|
186
182
|
[
|
187
183
|
[0] 1,
|
188
184
|
[1] 2,
|
@@ -192,8 +188,8 @@ EOS
|
|
192
188
|
EOS
|
193
189
|
end
|
194
190
|
|
195
|
-
it
|
196
|
-
expect(@arr.ai(:
|
191
|
+
it 'plain limited output with 10 lines' do
|
192
|
+
expect(@arr.ai(plain: true, limit: 10)).to eq <<-EOS.strip
|
197
193
|
[
|
198
194
|
[ 0] 1,
|
199
195
|
[ 1] 2,
|
@@ -209,8 +205,8 @@ EOS
|
|
209
205
|
EOS
|
210
206
|
end
|
211
207
|
|
212
|
-
it
|
213
|
-
expect(@arr.ai(:
|
208
|
+
it 'plain limited output with 11 lines' do
|
209
|
+
expect(@arr.ai(plain: true, limit: 11)).to eq <<-EOS.strip
|
214
210
|
[
|
215
211
|
[ 0] 1,
|
216
212
|
[ 1] 2,
|
@@ -229,13 +225,13 @@ EOS
|
|
229
225
|
end
|
230
226
|
|
231
227
|
#------------------------------------------------------------------------------
|
232
|
-
describe
|
228
|
+
describe 'Limited Output Hash' do
|
233
229
|
before(:each) do
|
234
|
-
@hash = (
|
230
|
+
@hash = ('a'..'z').inject({}) { |h, v| h.merge({ v => v.to_sym }) }
|
235
231
|
end
|
236
232
|
|
237
|
-
it
|
238
|
-
expect(@hash.ai(:
|
233
|
+
it 'plain limited output' do
|
234
|
+
expect(@hash.ai(sort_keys: true, plain: true, limit: true)).to eq <<-EOS.strip
|
239
235
|
{
|
240
236
|
"a" => :a,
|
241
237
|
"b" => :b,
|
@@ -250,17 +246,17 @@ EOS
|
|
250
246
|
end
|
251
247
|
|
252
248
|
#------------------------------------------------------------------------------
|
253
|
-
describe
|
249
|
+
describe 'Hash' do
|
254
250
|
before do
|
255
|
-
@hash = { 1 => { :
|
251
|
+
@hash = { 1 => { sym: { 'str' => { [1, 2, 3] => { { k: :v } => Hash } } } } }
|
256
252
|
end
|
257
253
|
|
258
|
-
it
|
259
|
-
expect({}.ai).to eq(
|
254
|
+
it 'empty hash' do
|
255
|
+
expect({}.ai).to eq('{}')
|
260
256
|
end
|
261
257
|
|
262
|
-
it
|
263
|
-
expect(@hash.ai(:
|
258
|
+
it 'plain multiline' do
|
259
|
+
expect(@hash.ai(plain: true)).to eq <<-EOS.strip
|
264
260
|
{
|
265
261
|
1 => {
|
266
262
|
:sym => {
|
@@ -275,8 +271,24 @@ EOS
|
|
275
271
|
EOS
|
276
272
|
end
|
277
273
|
|
278
|
-
it
|
279
|
-
expect(@hash.ai(:
|
274
|
+
it 'new hash syntax' do
|
275
|
+
expect(@hash.ai(plain: true, ruby19_syntax: true)).to eq <<-EOS.strip
|
276
|
+
{
|
277
|
+
1 => {
|
278
|
+
sym: {
|
279
|
+
"str" => {
|
280
|
+
[ 1, 2, 3 ] => {
|
281
|
+
{ k: :v } => Hash < Object
|
282
|
+
}
|
283
|
+
}
|
284
|
+
}
|
285
|
+
}
|
286
|
+
}
|
287
|
+
EOS
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'plain multiline indented' do
|
291
|
+
expect(@hash.ai(plain: true, indent: 1)).to eq <<-EOS.strip
|
280
292
|
{
|
281
293
|
1 => {
|
282
294
|
:sym => {
|
@@ -291,11 +303,11 @@ EOS
|
|
291
303
|
EOS
|
292
304
|
end
|
293
305
|
|
294
|
-
it
|
295
|
-
expect(@hash.ai(:
|
306
|
+
it 'plain single line' do
|
307
|
+
expect(@hash.ai(plain: true, multiline: false)).to eq('{ 1 => { :sym => { "str" => { [ 1, 2, 3 ] => { { :k => :v } => Hash < Object } } } } }')
|
296
308
|
end
|
297
309
|
|
298
|
-
it
|
310
|
+
it 'colored multiline (default)' do
|
299
311
|
expect(@hash.ai).to eq <<-EOS.strip
|
300
312
|
{
|
301
313
|
1\e[0;37m => \e[0m{
|
@@ -311,8 +323,24 @@ EOS
|
|
311
323
|
EOS
|
312
324
|
end
|
313
325
|
|
314
|
-
it
|
315
|
-
expect(@hash.ai(:
|
326
|
+
it 'colored with new hash syntax' do
|
327
|
+
expect(@hash.ai(ruby19_syntax: true)).to eq <<-EOS.strip
|
328
|
+
{
|
329
|
+
1\e[0;37m => \e[0m{
|
330
|
+
sym\e[0;37m: \e[0m{
|
331
|
+
\"str\"\e[0;37m => \e[0m{
|
332
|
+
[ 1, 2, 3 ]\e[0;37m => \e[0m{
|
333
|
+
{ k: :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m
|
334
|
+
}
|
335
|
+
}
|
336
|
+
}
|
337
|
+
}
|
338
|
+
}
|
339
|
+
EOS
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'colored multiline indented' do
|
343
|
+
expect(@hash.ai(indent: 2)).to eq <<-EOS.strip
|
316
344
|
{
|
317
345
|
1\e[0;37m => \e[0m{
|
318
346
|
:sym\e[0;37m => \e[0m{
|
@@ -327,40 +355,40 @@ EOS
|
|
327
355
|
EOS
|
328
356
|
end
|
329
357
|
|
330
|
-
it
|
331
|
-
expect(@hash.ai(:
|
358
|
+
it 'colored single line' do
|
359
|
+
expect(@hash.ai(multiline: false)).to eq("{ 1\e[0;37m => \e[0m{ :sym\e[0;37m => \e[0m{ \"str\"\e[0;37m => \e[0m{ [ 1, 2, 3 ]\e[0;37m => \e[0m{ { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m } } } } }")
|
332
360
|
end
|
333
361
|
|
334
362
|
end
|
335
363
|
|
336
364
|
#------------------------------------------------------------------------------
|
337
|
-
describe
|
365
|
+
describe 'Nested Hash' do
|
338
366
|
before do
|
339
367
|
@hash = {}
|
340
368
|
@hash[:a] = @hash
|
341
369
|
end
|
342
370
|
|
343
|
-
it
|
344
|
-
expect(@hash.ai(:
|
371
|
+
it 'plain multiline' do
|
372
|
+
expect(@hash.ai(plain: true)).to eq <<-EOS.strip
|
345
373
|
{
|
346
374
|
:a => {...}
|
347
375
|
}
|
348
376
|
EOS
|
349
377
|
end
|
350
378
|
|
351
|
-
it
|
352
|
-
expect(@hash.ai(:
|
379
|
+
it 'plain single line' do
|
380
|
+
expect(@hash.ai(plain: true, multiline: false)).to eq('{ :a => {...} }')
|
353
381
|
end
|
354
382
|
end
|
355
383
|
|
356
384
|
#------------------------------------------------------------------------------
|
357
|
-
describe
|
385
|
+
describe 'Hash with several keys' do
|
358
386
|
before do
|
359
|
-
@hash = {
|
387
|
+
@hash = { 'b' => 'b', :a => 'a', :z => 'z', 'alpha' => 'alpha' }
|
360
388
|
end
|
361
389
|
|
362
|
-
it
|
363
|
-
out = @hash.ai(:
|
390
|
+
it 'plain multiline' do
|
391
|
+
out = @hash.ai(plain: true)
|
364
392
|
if RUBY_VERSION.to_f < 1.9 # Order of @hash keys is not guaranteed.
|
365
393
|
expect(out).to match(/^\{[^\}]+\}/m)
|
366
394
|
expect(out).to match(/ "b" => "b",?/)
|
@@ -379,8 +407,8 @@ EOS
|
|
379
407
|
end
|
380
408
|
end
|
381
409
|
|
382
|
-
it
|
383
|
-
expect(@hash.ai(:
|
410
|
+
it 'plain multiline with sorted keys' do
|
411
|
+
expect(@hash.ai(plain: true, sort_keys: true)).to eq <<-EOS.strip
|
384
412
|
{
|
385
413
|
:a => "a",
|
386
414
|
"alpha" => "alpha",
|
@@ -393,14 +421,14 @@ EOS
|
|
393
421
|
end
|
394
422
|
|
395
423
|
#------------------------------------------------------------------------------
|
396
|
-
describe
|
424
|
+
describe 'Negative options[:indent]' do
|
397
425
|
#
|
398
426
|
# With Ruby < 1.9 the order of hash keys is not defined so we can't
|
399
427
|
# reliably compare the output string.
|
400
428
|
#
|
401
|
-
it
|
402
|
-
hash = { [0, 0, 255] => :yellow, :red =>
|
403
|
-
out = hash.ai(:
|
429
|
+
it 'hash keys must be left aligned' do
|
430
|
+
hash = { [0, 0, 255] => :yellow, :red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' }
|
431
|
+
out = hash.ai(plain: true, indent: -4, sort_keys: true)
|
404
432
|
expect(out).to eq <<-EOS.strip
|
405
433
|
{
|
406
434
|
[ 0, 0, 255 ] => :yellow,
|
@@ -410,9 +438,9 @@ EOS
|
|
410
438
|
EOS
|
411
439
|
end
|
412
440
|
|
413
|
-
it
|
414
|
-
arr = [
|
415
|
-
out = arr.ai(:
|
441
|
+
it 'nested hash keys should be indented (array of hashes)' do
|
442
|
+
arr = [{ a: 1, bb: 22, ccc: 333 }, { 1 => :a, 22 => :bb, 333 => :ccc }]
|
443
|
+
out = arr.ai(plain: true, indent: -4, sort_keys: true)
|
416
444
|
expect(out).to eq <<-EOS.strip
|
417
445
|
[
|
418
446
|
[0] {
|
@@ -429,9 +457,9 @@ EOS
|
|
429
457
|
EOS
|
430
458
|
end
|
431
459
|
|
432
|
-
it
|
433
|
-
arr = { :
|
434
|
-
out = arr.ai(:
|
460
|
+
it 'nested hash keys should be indented (hash of hashes)' do
|
461
|
+
arr = { first: { a: 1, bb: 22, ccc: 333 }, second: { 1 => :a, 22 => :bb, 333 => :ccc } }
|
462
|
+
out = arr.ai(plain: true, indent: -4, sort_keys: true)
|
435
463
|
expect(out).to eq <<-EOS.strip
|
436
464
|
{
|
437
465
|
:first => {
|
@@ -450,131 +478,131 @@ EOS
|
|
450
478
|
end
|
451
479
|
|
452
480
|
#------------------------------------------------------------------------------
|
453
|
-
describe
|
454
|
-
it
|
455
|
-
expect(self.class.ai(:
|
481
|
+
describe 'Class' do
|
482
|
+
it 'should show superclass (plain)' do
|
483
|
+
expect(self.class.ai(plain: true)).to eq("#{self.class} < #{self.class.superclass}")
|
456
484
|
end
|
457
485
|
|
458
|
-
it
|
486
|
+
it 'should show superclass (color)' do
|
459
487
|
expect(self.class.ai).to eq("#{self.class} < #{self.class.superclass}".yellow)
|
460
488
|
end
|
461
489
|
end
|
462
490
|
|
463
491
|
#------------------------------------------------------------------------------
|
464
|
-
describe
|
465
|
-
it
|
466
|
-
File.open(__FILE__,
|
467
|
-
expect(f.ai(:
|
492
|
+
describe 'File' do
|
493
|
+
it 'should display a file (plain)' do
|
494
|
+
File.open(__FILE__, 'r') do |f|
|
495
|
+
expect(f.ai(plain: true)).to eq("#{f.inspect}\n" << `ls -alF #{f.path}`.chop)
|
468
496
|
end
|
469
497
|
end
|
470
498
|
end
|
471
499
|
|
472
500
|
#------------------------------------------------------------------------------
|
473
|
-
describe
|
474
|
-
it
|
501
|
+
describe 'Dir' do
|
502
|
+
it 'should display a direcory (plain)' do
|
475
503
|
Dir.open(File.dirname(__FILE__)) do |d|
|
476
|
-
expect(d.ai(:
|
504
|
+
expect(d.ai(plain: true)).to eq("#{d.inspect}\n" << `ls -alF #{d.path}`.chop)
|
477
505
|
end
|
478
506
|
end
|
479
507
|
end
|
480
508
|
|
481
509
|
#------------------------------------------------------------------------------
|
482
|
-
describe
|
483
|
-
it
|
484
|
-
big = BigDecimal(
|
485
|
-
expect(big.ai(:
|
510
|
+
describe 'BigDecimal and Rational' do
|
511
|
+
it 'should present BigDecimal object with arbitrary precision' do
|
512
|
+
big = BigDecimal('201020102010201020102010201020102010.4')
|
513
|
+
expect(big.ai(plain: true)).to eq('201020102010201020102010201020102010.4')
|
486
514
|
end
|
487
515
|
|
488
|
-
it
|
516
|
+
it 'should present Rational object with arbitrary precision' do
|
489
517
|
rat = Rational(201020102010201020102010201020102010, 2)
|
490
|
-
out = rat.ai(:
|
518
|
+
out = rat.ai(plain: true)
|
491
519
|
#
|
492
520
|
# Ruby 1.9 slightly changed the format of Rational#to_s, see
|
493
521
|
# http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3 and
|
494
522
|
# http://www.ruby-forum.com/topic/189397
|
495
523
|
#
|
496
|
-
if RUBY_VERSION <
|
497
|
-
expect(out).to eq(
|
524
|
+
if RUBY_VERSION < '1.9'
|
525
|
+
expect(out).to eq('100510051005100510051005100510051005')
|
498
526
|
else
|
499
|
-
expect(out).to eq(
|
527
|
+
expect(out).to eq('100510051005100510051005100510051005/1')
|
500
528
|
end
|
501
529
|
end
|
502
530
|
end
|
503
531
|
|
504
532
|
#------------------------------------------------------------------------------
|
505
|
-
describe
|
506
|
-
it
|
533
|
+
describe 'Utility methods' do
|
534
|
+
it 'should merge options' do
|
507
535
|
ap = AwesomePrint::Inspector.new
|
508
|
-
ap.send(:merge_options!, { :
|
509
|
-
options = ap.instance_variable_get(
|
536
|
+
ap.send(:merge_options!, { color: { array: :black }, indent: 0 })
|
537
|
+
options = ap.instance_variable_get('@options')
|
510
538
|
expect(options[:color][:array]).to eq(:black)
|
511
539
|
expect(options[:indent]).to eq(0)
|
512
540
|
end
|
513
541
|
end
|
514
542
|
|
515
543
|
#------------------------------------------------------------------------------
|
516
|
-
describe
|
544
|
+
describe 'Set' do
|
517
545
|
before do
|
518
|
-
@arr = [1, :two,
|
546
|
+
@arr = [1, :two, 'three']
|
519
547
|
@set = Set.new(@arr)
|
520
548
|
end
|
521
549
|
|
522
|
-
it
|
550
|
+
it 'empty set' do
|
523
551
|
expect(Set.new.ai).to eq([].ai)
|
524
552
|
end
|
525
553
|
|
526
|
-
if RUBY_VERSION >
|
527
|
-
it
|
528
|
-
expect(@set.ai(:
|
554
|
+
if RUBY_VERSION > '1.9'
|
555
|
+
it 'plain multiline' do
|
556
|
+
expect(@set.ai(plain: true)).to eq(@arr.ai(plain: true))
|
529
557
|
end
|
530
558
|
|
531
|
-
it
|
532
|
-
expect(@set.ai(:
|
559
|
+
it 'plain multiline indented' do
|
560
|
+
expect(@set.ai(plain: true, indent: 1)).to eq(@arr.ai(plain: true, indent: 1))
|
533
561
|
end
|
534
562
|
|
535
|
-
it
|
536
|
-
expect(@set.ai(:
|
563
|
+
it 'plain single line' do
|
564
|
+
expect(@set.ai(plain: true, multiline: false)).to eq(@arr.ai(plain: true, multiline: false))
|
537
565
|
end
|
538
566
|
|
539
|
-
it
|
567
|
+
it 'colored multiline (default)' do
|
540
568
|
expect(@set.ai).to eq(@arr.ai)
|
541
569
|
end
|
542
570
|
else # Prior to Ruby 1.9 the order of set values is unpredicatble.
|
543
|
-
it
|
544
|
-
expect(@set.sort_by{ |x| x.to_s }.ai(:
|
571
|
+
it 'plain multiline' do
|
572
|
+
expect(@set.sort_by { |x| x.to_s }.ai(plain: true)).to eq(@arr.sort_by { |x| x.to_s }.ai(plain: true))
|
545
573
|
end
|
546
574
|
|
547
|
-
it
|
548
|
-
expect(@set.sort_by{ |x| x.to_s }.ai(:
|
575
|
+
it 'plain multiline indented' do
|
576
|
+
expect(@set.sort_by { |x| x.to_s }.ai(plain: true, indent: 1)).to eq(@arr.sort_by { |x| x.to_s }.ai(plain: true, indent: 1))
|
549
577
|
end
|
550
578
|
|
551
|
-
it
|
552
|
-
expect(@set.sort_by{ |x| x.to_s }.ai(:
|
579
|
+
it 'plain single line' do
|
580
|
+
expect(@set.sort_by { |x| x.to_s }.ai(plain: true, multiline: false)).to eq(@arr.sort_by { |x| x.to_s }.ai(plain: true, multiline: false))
|
553
581
|
end
|
554
582
|
|
555
|
-
it
|
556
|
-
expect(@set.sort_by{ |x| x.to_s }.ai).to eq(@arr.sort_by{ |x| x.to_s }.ai)
|
583
|
+
it 'colored multiline (default)' do
|
584
|
+
expect(@set.sort_by { |x| x.to_s }.ai).to eq(@arr.sort_by { |x| x.to_s }.ai)
|
557
585
|
end
|
558
586
|
end
|
559
587
|
end
|
560
588
|
|
561
589
|
#------------------------------------------------------------------------------
|
562
|
-
describe
|
590
|
+
describe 'Struct' do
|
563
591
|
before do
|
564
592
|
@struct = unless defined?(Struct::SimpleStruct)
|
565
|
-
Struct.new(
|
593
|
+
Struct.new('SimpleStruct', :name, :address).new
|
566
594
|
else
|
567
595
|
Struct::SimpleStruct.new
|
568
596
|
end
|
569
|
-
@struct.name =
|
570
|
-
@struct.address =
|
597
|
+
@struct.name = 'Herman Munster'
|
598
|
+
@struct.address = '1313 Mockingbird Lane'
|
571
599
|
end
|
572
600
|
|
573
|
-
it
|
574
|
-
expect(Struct.new(
|
601
|
+
it 'empty struct' do
|
602
|
+
expect(Struct.new('EmptyStruct').ai).to eq("\e[1;33mStruct::EmptyStruct < Struct\e[0m")
|
575
603
|
end
|
576
604
|
|
577
|
-
it
|
605
|
+
it 'plain multiline' do
|
578
606
|
s1 = <<-EOS.strip
|
579
607
|
address = \"1313 Mockingbird Lane\",
|
580
608
|
name = \"Herman Munster\"
|
@@ -583,10 +611,10 @@ EOS
|
|
583
611
|
name = \"Herman Munster\",
|
584
612
|
address = \"1313 Mockingbird Lane\"
|
585
613
|
EOS
|
586
|
-
expect(@struct.ai(:
|
614
|
+
expect(@struct.ai(plain: true)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
587
615
|
end
|
588
616
|
|
589
|
-
it
|
617
|
+
it 'plain multiline indented' do
|
590
618
|
s1 = <<-EOS.strip
|
591
619
|
address = "1313 Mockingbird Lane",
|
592
620
|
name = "Herman Munster"
|
@@ -595,16 +623,16 @@ EOS
|
|
595
623
|
name = "Herman Munster",
|
596
624
|
address = "1313 Mockingbird Lane"
|
597
625
|
EOS
|
598
|
-
expect(@struct.ai(:
|
626
|
+
expect(@struct.ai(plain: true, indent: 1)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
599
627
|
end
|
600
628
|
|
601
|
-
it
|
602
|
-
s1 =
|
603
|
-
s2 =
|
604
|
-
expect(@struct.ai(:
|
629
|
+
it 'plain single line' do
|
630
|
+
s1 = 'address = "1313 Mockingbird Lane", name = "Herman Munster"'
|
631
|
+
s2 = 'name = "Herman Munster", address = "1313 Mockingbird Lane"'
|
632
|
+
expect(@struct.ai(plain: true, multiline: false)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
605
633
|
end
|
606
634
|
|
607
|
-
it
|
635
|
+
it 'colored multiline (default)' do
|
608
636
|
s1 = <<-EOS.strip
|
609
637
|
address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m,
|
610
638
|
name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m
|
@@ -618,16 +646,16 @@ EOS
|
|
618
646
|
end
|
619
647
|
|
620
648
|
#------------------------------------------------------------------------------
|
621
|
-
describe
|
649
|
+
describe 'Inherited from standard Ruby classes' do
|
622
650
|
after do
|
623
|
-
Object.instance_eval{ remove_const :My } if defined?(My)
|
651
|
+
Object.instance_eval { remove_const :My } if defined?(My)
|
624
652
|
end
|
625
653
|
|
626
|
-
it
|
654
|
+
it 'inherited from Array should be displayed as Array' do
|
627
655
|
class My < Array; end
|
628
656
|
|
629
|
-
my = My.new([
|
630
|
-
expect(my.ai(:
|
657
|
+
my = My.new([1, :two, 'three', [nil, [true, false]]])
|
658
|
+
expect(my.ai(plain: true)).to eq <<-EOS.strip
|
631
659
|
[
|
632
660
|
[0] 1,
|
633
661
|
[1] :two,
|
@@ -643,11 +671,11 @@ EOS
|
|
643
671
|
EOS
|
644
672
|
end
|
645
673
|
|
646
|
-
it
|
674
|
+
it 'inherited from Hash should be displayed as Hash' do
|
647
675
|
class My < Hash; end
|
648
676
|
|
649
|
-
my = My[
|
650
|
-
expect(my.ai(:
|
677
|
+
my = My[{ 1 => { sym: { 'str' => { [1, 2, 3] => { { k: :v } => Hash } } } } }]
|
678
|
+
expect(my.ai(plain: true)).to eq <<-EOS.strip
|
651
679
|
{
|
652
680
|
1 => {
|
653
681
|
:sym => {
|
@@ -662,31 +690,31 @@ EOS
|
|
662
690
|
EOS
|
663
691
|
end
|
664
692
|
|
665
|
-
it
|
693
|
+
it 'inherited from File should be displayed as File' do
|
666
694
|
class My < File; end
|
667
695
|
|
668
696
|
my = File.new('/dev/null') rescue File.new('nul')
|
669
|
-
expect(my.ai(:
|
697
|
+
expect(my.ai(plain: true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop)
|
670
698
|
end
|
671
699
|
|
672
|
-
it
|
700
|
+
it 'inherited from Dir should be displayed as Dir' do
|
673
701
|
class My < Dir; end
|
674
702
|
|
675
703
|
require 'tmpdir'
|
676
704
|
my = My.new(Dir.tmpdir)
|
677
|
-
expect(my.ai(:
|
705
|
+
expect(my.ai(plain: true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop)
|
678
706
|
end
|
679
707
|
|
680
|
-
it
|
708
|
+
it 'should handle a class that defines its own #send method' do
|
681
709
|
class My
|
682
710
|
def send(arg1, arg2, arg3); end
|
683
711
|
end
|
684
712
|
|
685
713
|
my = My.new
|
686
|
-
expect { my.methods.ai(:
|
714
|
+
expect { my.methods.ai(plain: true) }.not_to raise_error
|
687
715
|
end
|
688
716
|
|
689
|
-
it
|
717
|
+
it 'should handle a class defines its own #method method (ex. request.method)' do
|
690
718
|
class My
|
691
719
|
def method
|
692
720
|
'POST'
|
@@ -694,21 +722,21 @@ EOS
|
|
694
722
|
end
|
695
723
|
|
696
724
|
my = My.new
|
697
|
-
expect { my.methods.ai(:
|
725
|
+
expect { my.methods.ai(plain: true) }.not_to raise_error
|
698
726
|
end
|
699
727
|
|
700
|
-
describe
|
701
|
-
it
|
728
|
+
describe 'should handle a class that defines its own #to_hash method' do
|
729
|
+
it 'that takes arguments' do
|
702
730
|
class My
|
703
731
|
def to_hash(a, b)
|
704
732
|
end
|
705
733
|
end
|
706
734
|
|
707
735
|
my = My.new
|
708
|
-
expect { my.ai(:
|
736
|
+
expect { my.ai(plain: true) }.not_to raise_error
|
709
737
|
end
|
710
738
|
|
711
|
-
it
|
739
|
+
it 'that returns nil' do
|
712
740
|
class My
|
713
741
|
def to_hash()
|
714
742
|
return nil
|
@@ -716,7 +744,7 @@ EOS
|
|
716
744
|
end
|
717
745
|
|
718
746
|
my = My.new
|
719
|
-
expect { my.ai(:
|
747
|
+
expect { my.ai(plain: true) }.not_to raise_error
|
720
748
|
end
|
721
749
|
|
722
750
|
it "that returns an object that doesn't support #keys" do
|
@@ -730,7 +758,7 @@ EOS
|
|
730
758
|
end
|
731
759
|
|
732
760
|
my = My.new
|
733
|
-
expect { my.ai(:
|
761
|
+
expect { my.ai(plain: true) }.not_to raise_error
|
734
762
|
end
|
735
763
|
|
736
764
|
it "that returns an object that doesn't support subscripting" do
|
@@ -744,7 +772,7 @@ EOS
|
|
744
772
|
end
|
745
773
|
|
746
774
|
my = My.new
|
747
|
-
expect { my.ai(:
|
775
|
+
expect { my.ai(plain: true) }.not_to raise_error
|
748
776
|
end
|
749
777
|
end
|
750
778
|
end
|