amazing_print 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +35 -0
  3. data/Appraisals +60 -0
  4. data/CHANGELOG.md +2 -0
  5. data/CONTRIBUTING.md +81 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +21 -0
  8. data/README.md +356 -0
  9. data/Rakefile +23 -0
  10. data/lib/amazing_print.rb +46 -0
  11. data/lib/amazing_print/colorize.rb +25 -0
  12. data/lib/amazing_print/core_ext/awesome_method_array.rb +82 -0
  13. data/lib/amazing_print/core_ext/class.rb +23 -0
  14. data/lib/amazing_print/core_ext/kernel.rb +25 -0
  15. data/lib/amazing_print/core_ext/logger.rb +21 -0
  16. data/lib/amazing_print/core_ext/method.rb +21 -0
  17. data/lib/amazing_print/core_ext/object.rb +23 -0
  18. data/lib/amazing_print/core_ext/string.rb +42 -0
  19. data/lib/amazing_print/custom_defaults.rb +57 -0
  20. data/lib/amazing_print/ext/action_view.rb +22 -0
  21. data/lib/amazing_print/ext/active_record.rb +103 -0
  22. data/lib/amazing_print/ext/active_support.rb +45 -0
  23. data/lib/amazing_print/ext/mongo_mapper.rb +125 -0
  24. data/lib/amazing_print/ext/mongoid.rb +68 -0
  25. data/lib/amazing_print/ext/nobrainer.rb +53 -0
  26. data/lib/amazing_print/ext/nokogiri.rb +45 -0
  27. data/lib/amazing_print/ext/ostruct.rb +27 -0
  28. data/lib/amazing_print/ext/ripple.rb +71 -0
  29. data/lib/amazing_print/ext/sequel.rb +55 -0
  30. data/lib/amazing_print/formatter.rb +120 -0
  31. data/lib/amazing_print/formatters.rb +14 -0
  32. data/lib/amazing_print/formatters/array_formatter.rb +139 -0
  33. data/lib/amazing_print/formatters/base_formatter.rb +148 -0
  34. data/lib/amazing_print/formatters/class_formatter.rb +24 -0
  35. data/lib/amazing_print/formatters/dir_formatter.rb +21 -0
  36. data/lib/amazing_print/formatters/file_formatter.rb +21 -0
  37. data/lib/amazing_print/formatters/hash_formatter.rb +106 -0
  38. data/lib/amazing_print/formatters/method_formatter.rb +21 -0
  39. data/lib/amazing_print/formatters/object_formatter.rb +82 -0
  40. data/lib/amazing_print/formatters/simple_formatter.rb +20 -0
  41. data/lib/amazing_print/formatters/struct_formatter.rb +74 -0
  42. data/lib/amazing_print/indentator.rb +17 -0
  43. data/lib/amazing_print/inspector.rb +175 -0
  44. data/lib/amazing_print/version.rb +10 -0
  45. data/lib/ap.rb +10 -0
  46. data/spec/active_record_helper.rb +30 -0
  47. data/spec/colors_spec.rb +114 -0
  48. data/spec/core_ext/logger_spec.rb +44 -0
  49. data/spec/core_ext/string_spec.rb +20 -0
  50. data/spec/ext/action_view_spec.rb +17 -0
  51. data/spec/ext/active_record_spec.rb +297 -0
  52. data/spec/ext/active_support_spec.rb +26 -0
  53. data/spec/ext/mongo_mapper_spec.rb +259 -0
  54. data/spec/ext/mongoid_spec.rb +66 -0
  55. data/spec/ext/nobrainer_spec.rb +58 -0
  56. data/spec/ext/nokogiri_spec.rb +50 -0
  57. data/spec/ext/ostruct_spec.rb +22 -0
  58. data/spec/ext/ripple_spec.rb +47 -0
  59. data/spec/formats_spec.rb +779 -0
  60. data/spec/methods_spec.rb +478 -0
  61. data/spec/misc_spec.rb +245 -0
  62. data/spec/objects_spec.rb +219 -0
  63. data/spec/spec_helper.rb +106 -0
  64. data/spec/support/active_record_data.rb +20 -0
  65. data/spec/support/active_record_data/3_2_diana.txt +24 -0
  66. data/spec/support/active_record_data/3_2_diana_legacy.txt +24 -0
  67. data/spec/support/active_record_data/3_2_multi.txt +50 -0
  68. data/spec/support/active_record_data/3_2_multi_legacy.txt +50 -0
  69. data/spec/support/active_record_data/4_0_diana.txt +98 -0
  70. data/spec/support/active_record_data/4_0_multi.txt +198 -0
  71. data/spec/support/active_record_data/4_1_diana.txt +97 -0
  72. data/spec/support/active_record_data/4_1_multi.txt +196 -0
  73. data/spec/support/active_record_data/4_2_diana.txt +109 -0
  74. data/spec/support/active_record_data/4_2_diana_legacy.txt +109 -0
  75. data/spec/support/active_record_data/4_2_multi.txt +220 -0
  76. data/spec/support/active_record_data/4_2_multi_legacy.txt +220 -0
  77. data/spec/support/active_record_data/5_0_diana.txt +105 -0
  78. data/spec/support/active_record_data/5_0_multi.txt +212 -0
  79. data/spec/support/active_record_data/5_1_diana.txt +104 -0
  80. data/spec/support/active_record_data/5_1_multi.txt +210 -0
  81. data/spec/support/active_record_data/5_2_diana.txt +104 -0
  82. data/spec/support/active_record_data/5_2_multi.txt +210 -0
  83. data/spec/support/active_record_data/6_0_diana.txt +104 -0
  84. data/spec/support/active_record_data/6_0_multi.txt +210 -0
  85. data/spec/support/ext_verifier.rb +41 -0
  86. data/spec/support/mongoid_versions.rb +22 -0
  87. data/spec/support/rails_versions.rb +50 -0
  88. metadata +243 -0
@@ -0,0 +1,10 @@
1
+ # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
+ #
3
+ # AmazingPrint is freely distributable under the terms of MIT license.
4
+ # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
+ #------------------------------------------------------------------------------
6
+ module AmazingPrint
7
+ def self.version
8
+ '1.0.0'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
+ #
3
+ # AmazingPrint is freely distributable under the terms of MIT license.
4
+ # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
+ #------------------------------------------------------------------------------
6
+ #
7
+ # Keeping this for backwards compatibility to allow
8
+ # require "ap"
9
+ #
10
+ require File.dirname(__FILE__) + '/amazing_print'
@@ -0,0 +1,30 @@
1
+ if ExtVerifier.has_rails?
2
+ # Required to use the column support
3
+ module Rails
4
+ def self.env
5
+ {}
6
+ end
7
+ end
8
+
9
+ # Establish connection to in-memory SQLite DB
10
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
11
+
12
+ # Create the users table
13
+ ActiveRecord::Migration.verbose = false
14
+ ActiveRecord::Migration.create_table :users do |t|
15
+ t.string :name
16
+ t.integer :rank
17
+ t.boolean :admin
18
+ t.datetime :created_at
19
+ end
20
+
21
+ ActiveRecord::Migration.create_table :emails do |t|
22
+ t.references :user
23
+ t.string :email_address
24
+ end
25
+
26
+ # Create models
27
+ class User < ActiveRecord::Base; has_many :emails; end
28
+ class SubUser < User; end
29
+ class Email < ActiveRecord::Base; belongs_to :user; end
30
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'AmazingPrint' do
4
+ def stub_tty!(output = true, stream = STDOUT)
5
+ if output
6
+ stream.instance_eval do
7
+ def tty?
8
+ true
9
+ end
10
+ end
11
+ else
12
+ stream.instance_eval do
13
+ def tty?
14
+ false
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ describe 'colorization' do
21
+ PLAIN = '[ 1, :two, "three", [ nil, [ true, false ] ] ]'.freeze
22
+ 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 ] ] ]".freeze
23
+
24
+ before do
25
+ ENV['TERM'] = 'xterm-colors'
26
+ ENV.delete('ANSICON')
27
+ @arr = [1, :two, 'three', [nil, [true, false]]]
28
+ end
29
+
30
+ describe 'default settings (no forced colors)' do
31
+ before do
32
+ AmazingPrint.force_colors! false
33
+ end
34
+
35
+ it 'colorizes tty processes by default' do
36
+ stub_tty!
37
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
38
+ end
39
+
40
+ it "colorizes processes with ENV['ANSICON'] by default" do
41
+ begin
42
+ stub_tty!
43
+ term = ENV['ANSICON']
44
+ ENV['ANSICON'] = '1'
45
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
46
+ ensure
47
+ ENV['ANSICON'] = term
48
+ end
49
+ end
50
+
51
+ it 'does not colorize tty processes running in dumb terminals by default' do
52
+ begin
53
+ stub_tty!
54
+ term = ENV['TERM']
55
+ ENV['TERM'] = 'dumb'
56
+ expect(@arr.ai(multiline: false)).to eq(PLAIN)
57
+ ensure
58
+ ENV['TERM'] = term
59
+ end
60
+ end
61
+
62
+ it 'does not colorize subprocesses by default' do
63
+ begin
64
+ stub_tty! false
65
+ expect(@arr.ai(multiline: false)).to eq(PLAIN)
66
+ ensure
67
+ stub_tty!
68
+ end
69
+ end
70
+ end
71
+
72
+ describe 'forced colors override' do
73
+ before do
74
+ AmazingPrint.force_colors!
75
+ end
76
+
77
+ it 'still colorizes tty processes' do
78
+ stub_tty!
79
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
80
+ end
81
+
82
+ it "colorizes processes with ENV['ANSICON'] set to 0" do
83
+ begin
84
+ stub_tty!
85
+ term = ENV['ANSICON']
86
+ ENV['ANSICON'] = '1'
87
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
88
+ ensure
89
+ ENV['ANSICON'] = term
90
+ end
91
+ end
92
+
93
+ it 'colorizes dumb terminals' do
94
+ begin
95
+ stub_tty!
96
+ term = ENV['TERM']
97
+ ENV['TERM'] = 'dumb'
98
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
99
+ ensure
100
+ ENV['TERM'] = term
101
+ end
102
+ end
103
+
104
+ it 'colorizes subprocess' do
105
+ begin
106
+ stub_tty! false
107
+ expect(@arr.ai(multiline: false)).to eq(COLORIZED)
108
+ ensure
109
+ stub_tty!
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ require 'logger'
4
+ require 'amazing_print/core_ext/logger'
5
+
6
+ RSpec.describe 'AmazingPrint logging extensions' do
7
+ before(:all) do
8
+ @logger = begin
9
+ Logger.new('/dev/null')
10
+ rescue Errno::ENOENT
11
+ Logger.new('nul')
12
+ end
13
+ end
14
+
15
+ describe 'ap method' do
16
+ it 'should awesome_inspect the given object' do
17
+ object = double
18
+ expect(object).to receive(:ai)
19
+ @logger.ap object
20
+ end
21
+
22
+ describe 'the log level' do
23
+ before do
24
+ AmazingPrint.defaults = {}
25
+ end
26
+
27
+ it 'should fallback to the default :debug log level' do
28
+ expect(@logger).to receive(:debug)
29
+ @logger.ap(nil)
30
+ end
31
+
32
+ it 'should use the global user default if no level passed' do
33
+ AmazingPrint.defaults = { log_level: :info }
34
+ expect(@logger).to receive(:info)
35
+ @logger.ap(nil)
36
+ end
37
+
38
+ it 'should use the passed in level' do
39
+ expect(@logger).to receive(:warn)
40
+ @logger.ap(nil, :warn)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'String extensions' do
4
+ %i[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,17 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'AmazingPrint ActionView extensions', skip: -> { !ExtVerifier.has_rails? }.call do
4
+ before do
5
+ @view = ActionView::Base.new
6
+ end
7
+
8
+ it "uses HTML and adds 'debug_dump' class to plain <pre> tag" do
9
+ markup = rand
10
+ expect(@view.ap(markup, plain: true)).to eq(%(<pre class="debug_dump">#{markup}</pre>))
11
+ end
12
+
13
+ it "uses HTML and adds 'debug_dump' class to colorized <pre> tag" do
14
+ markup = ' &<hello>'
15
+ expect(@view.ap(markup)).to eq('<pre class="debug_dump"><kbd style="color:brown">&quot; &amp;&lt;hello&gt;&quot;</kbd></pre>')
16
+ end
17
+ end
@@ -0,0 +1,297 @@
1
+ require 'spec_helper'
2
+ require 'active_record_helper'
3
+
4
+ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }.call do
5
+ describe 'ActiveRecord instance, attributes only (default)' do
6
+ before do
7
+ ActiveRecord::Base.default_timezone = :utc
8
+ @diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00')
9
+ @laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00')
10
+ @ap = AmazingPrint::Inspector.new(plain: true, sort_keys: true)
11
+ end
12
+
13
+ it 'display single record' do
14
+ out = @ap.awesome(@diana)
15
+ str = <<~EOS.strip
16
+ #<User:placeholder_id> {
17
+ :admin => false,
18
+ :created_at => ?,
19
+ :id => nil,
20
+ :name => "Diana",
21
+ :rank => 1
22
+ }
23
+ EOS
24
+ if RUBY_VERSION < '1.9'
25
+ str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
26
+ else
27
+ str.sub!('?', '1992-10-10 12:30:00 UTC')
28
+ end
29
+ expect(out).to be_similar_to(str)
30
+ end
31
+
32
+ it 'display multiple records' do
33
+ out = @ap.awesome([@diana, @laura])
34
+ str = <<~EOS.strip
35
+ [
36
+ [0] #<User:placeholder_id> {
37
+ :admin => false,
38
+ :created_at => ??,
39
+ :id => nil,
40
+ :name => "Diana",
41
+ :rank => 1
42
+ },
43
+ [1] #<User:placeholder_id> {
44
+ :admin => true,
45
+ :created_at => ?!,
46
+ :id => nil,
47
+ :name => "Laura",
48
+ :rank => 2
49
+ }
50
+ ]
51
+ EOS
52
+ if RUBY_VERSION < '1.9'
53
+ str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992')
54
+ str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003')
55
+ else
56
+ str.sub!('??', '1992-10-10 12:30:00 UTC')
57
+ str.sub!('?!', '2003-05-26 14:15:00 UTC')
58
+ end
59
+ expect(out).to be_similar_to(str)
60
+ end
61
+
62
+ it 'display multiple records on a relation' do
63
+ @diana.save
64
+ @laura.save
65
+ out = @ap.awesome(User.all)
66
+ str = <<~EOS.strip
67
+ [
68
+ [0] #<User:placeholder_id> {
69
+ :admin => false,
70
+ :created_at => ??,
71
+ :id => 1,
72
+ :name => "Diana",
73
+ :rank => 1
74
+ },
75
+ [1] #<User:placeholder_id> {
76
+ :admin => true,
77
+ :created_at => ?!,
78
+ :id => 2,
79
+ :name => "Laura",
80
+ :rank => 2
81
+ }
82
+ ]
83
+ EOS
84
+ if RUBY_VERSION < '1.9'
85
+ str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992')
86
+ str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003')
87
+ else
88
+ str.sub!('??', '1992-10-10 12:30:00 UTC')
89
+ str.sub!('?!', '2003-05-26 14:15:00 UTC')
90
+ end
91
+ expect(out).to be_similar_to(str)
92
+ end
93
+ end
94
+
95
+ describe 'Linked records (joins)' do
96
+ before do
97
+ @ap = AmazingPrint::Inspector.new(plain: true)
98
+ end
99
+
100
+ it 'should show the entire record' do
101
+ e = Email.create(email_address: 'foo@bar.com')
102
+ u = User.last
103
+ u.emails << e
104
+ email_record = User.joins(:emails).select('users.id, emails.email_address').last
105
+ out = @ap.awesome(email_record)
106
+ raw_object_string = <<~EOS.strip
107
+ #<User:placeholder_id> {
108
+ "id" => #{u.id},
109
+ "email_address" => "#{e.email_address}"
110
+ }
111
+ EOS
112
+ expect(out).to be_similar_to(raw_object_string)
113
+ end
114
+ end
115
+
116
+ #------------------------------------------------------------------------------
117
+ describe 'ActiveRecord instance (raw)' do
118
+ before do
119
+ ActiveRecord::Base.default_timezone = :utc
120
+ @diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00')
121
+ @laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00')
122
+ @ap = AmazingPrint::Inspector.new(plain: true, sort_keys: true, raw: true)
123
+ end
124
+
125
+ it 'display single record' do
126
+ out = @ap.awesome(@diana)
127
+
128
+ raw_object_string =
129
+ if activerecord_6_0?
130
+ ActiveRecordData.raw_6_0_diana
131
+ elsif activerecord_5_2?
132
+ ActiveRecordData.raw_5_2_diana
133
+ elsif activerecord_5_1?
134
+ ActiveRecordData.raw_5_1_diana
135
+ elsif activerecord_5_0?
136
+ ActiveRecordData.raw_5_0_diana
137
+ elsif activerecord_4_2?
138
+ if RUBY_VERSION > '1.9.3'
139
+ ActiveRecordData.raw_4_2_diana
140
+ else
141
+ ActiveRecordData.raw_4_2_diana_legacy
142
+ end
143
+ elsif activerecord_4_1?
144
+ ActiveRecordData.raw_4_1_diana
145
+ elsif activerecord_4_0?
146
+ ActiveRecordData.raw_4_0_diana
147
+ elsif activerecord_3_2?
148
+ if RUBY_VERSION > '1.9.3'
149
+ ActiveRecordData.raw_3_2_diana
150
+ else
151
+ ActiveRecordData.raw_3_2_diana_legacy
152
+ end
153
+ end
154
+
155
+ if RUBY_PLATFORM == 'java'
156
+ raw_object_string.gsub!(
157
+ 'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer',
158
+ 'ArJdbc::SQLite3::SQLite3Integer'
159
+ )
160
+ end
161
+ raw_object_string.sub!('?', '1992-10-10 12:30:00')
162
+ expect(out).to be_similar_to(raw_object_string)
163
+ end
164
+
165
+ it 'display multiple records' do
166
+ out = @ap.awesome([@diana, @laura])
167
+
168
+ raw_object_string =
169
+ if activerecord_6_0?
170
+ ActiveRecordData.raw_6_0_multi
171
+ elsif activerecord_5_2?
172
+ ActiveRecordData.raw_5_2_multi
173
+ elsif activerecord_5_1?
174
+ ActiveRecordData.raw_5_1_multi
175
+ elsif activerecord_5_0?
176
+ ActiveRecordData.raw_5_0_multi
177
+ elsif activerecord_4_2?
178
+ if RUBY_VERSION > '1.9.3'
179
+ ActiveRecordData.raw_4_2_multi
180
+ else
181
+ ActiveRecordData.raw_4_2_multi_legacy
182
+ end
183
+ elsif activerecord_4_1?
184
+ ActiveRecordData.raw_4_1_multi
185
+ elsif activerecord_4_0?
186
+ ActiveRecordData.raw_4_0_multi
187
+ elsif activerecord_3_2?
188
+ if RUBY_VERSION > '1.9.3'
189
+ ActiveRecordData.raw_3_2_multi
190
+ else
191
+ ActiveRecordData.raw_3_2_multi_legacy
192
+ end
193
+ end
194
+
195
+ if RUBY_PLATFORM == 'java'
196
+ raw_object_string.gsub!(
197
+ 'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer',
198
+ 'ArJdbc::SQLite3::SQLite3Integer'
199
+ )
200
+ end
201
+ raw_object_string.sub!('?', '1992-10-10 12:30:00')
202
+ raw_object_string.sub!('?', '2003-05-26 14:15:00')
203
+ expect(out).to be_similar_to(raw_object_string)
204
+ end
205
+ end
206
+
207
+ #------------------------------------------------------------------------------
208
+ describe 'ActiveRecord class' do
209
+ before do
210
+ @ap = AmazingPrint::Inspector.new(plain: true)
211
+ end
212
+
213
+ it 'should print the class' do
214
+ expect(@ap.awesome(User)).to eq <<~EOS.strip
215
+ class User < ActiveRecord::Base {
216
+ :id => :integer,
217
+ :name => :string,
218
+ :rank => :integer,
219
+ :admin => :boolean,
220
+ :created_at => :datetime
221
+ }
222
+ EOS
223
+ end
224
+
225
+ it 'should print the class for non-direct subclasses of ActiveRecord::Base' do
226
+ out = @ap.awesome(SubUser)
227
+ expect(out).to eq <<~EOS.strip
228
+ class SubUser < User {
229
+ :id => :integer,
230
+ :name => :string,
231
+ :rank => :integer,
232
+ :admin => :boolean,
233
+ :created_at => :datetime
234
+ }
235
+ EOS
236
+ end
237
+
238
+ it 'should print ActiveRecord::Base objects (ex. ancestors)' do
239
+ expect { @ap.awesome(User.ancestors) }.not_to raise_error
240
+ end
241
+ end
242
+
243
+ #------------------------------------------------------------------------------
244
+ describe 'ActiveRecord methods formatting' do
245
+ before do
246
+ @ap = AmazingPrint::Inspector.new(plain: true)
247
+ end
248
+
249
+ it 'should format class methods properly' do
250
+ # spec 1
251
+ out = @ap.awesome(User.methods.grep(/first/))
252
+
253
+ if ActiveRecord::VERSION::STRING >= '3.2'
254
+ if RUBY_PLATFORM == 'java'
255
+ expect(out).to match(
256
+ /\s+first\(\*args,\s&block\)\s+#<Class:\w+>\s+\(ActiveRecord::Querying\)/
257
+ )
258
+ elsif RUBY_VERSION >= '2.4.4'
259
+ expect(out).to match(/\sfirst\(\*arg.*?\)\s+User/)
260
+ elsif RUBY_VERSION >= '1.9'
261
+ expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/)
262
+ else
263
+ expect(out).to match(/\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/)
264
+ end
265
+ else
266
+ expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
267
+ end
268
+
269
+ # spec 2
270
+ out = @ap.awesome(User.methods.grep(/primary_key/))
271
+ if RUBY_PLATFORM == 'java'
272
+ expect(out).to match(
273
+ /\sprimary_key\(.*?\)\s+#<Class:\w+>\s\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
274
+ )
275
+ elsif RUBY_VERSION >= '2.4.4'
276
+ expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
277
+ else
278
+ expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
279
+ end
280
+
281
+ # spec 3
282
+ out = @ap.awesome(User.methods.grep(/validate/))
283
+
284
+ if ActiveRecord::VERSION::MAJOR < 3
285
+ expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
286
+ else
287
+ if RUBY_PLATFORM == 'java'
288
+ expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:\w+> \(ActiveModel::Validations::ClassMethods\)/)
289
+ elsif RUBY_VERSION >= '2.4.4'
290
+ expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
291
+ else
292
+ expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
293
+ end
294
+ end
295
+ end
296
+ end
297
+ end