amazing_print 1.6.0 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -2
- data/lib/amazing_print/ext/active_record.rb +32 -2
- data/lib/amazing_print/ext/nobrainer.rb +2 -2
- data/lib/amazing_print/formatters/base_formatter.rb +5 -1
- data/lib/amazing_print/formatters/hash_formatter.rb +29 -9
- data/lib/amazing_print/formatters/mswin_helper.rb +4 -4
- data/lib/amazing_print/formatters/object_formatter.rb +1 -1
- data/lib/amazing_print/formatters/struct_formatter.rb +1 -1
- data/lib/amazing_print/inspector.rb +1 -1
- data/lib/amazing_print/version.rb +1 -1
- metadata +6 -63
- data/.gitignore +0 -35
- data/Appraisals +0 -66
- data/Gemfile +0 -18
- data/Gemfile.lock +0 -94
- data/LICENSE +0 -22
- data/Rakefile +0 -25
- data/spec/active_record_helper.rb +0 -43
- data/spec/colors_spec.rb +0 -120
- data/spec/core_ext/logger_spec.rb +0 -70
- data/spec/ext/action_controller_spec.rb +0 -40
- data/spec/ext/action_view_spec.rb +0 -24
- data/spec/ext/active_model_spec.rb +0 -37
- data/spec/ext/active_record_spec.rb +0 -302
- data/spec/ext/active_support_spec.rb +0 -37
- data/spec/ext/mongo_mapper_spec.rb +0 -265
- data/spec/ext/mongoid_spec.rb +0 -135
- data/spec/ext/nobrainer_spec.rb +0 -64
- data/spec/ext/nokogiri_spec.rb +0 -52
- data/spec/ext/ostruct_spec.rb +0 -24
- data/spec/ext/ripple_spec.rb +0 -53
- data/spec/ext/sequel_spec.rb +0 -45
- data/spec/formats_spec.rb +0 -795
- data/spec/methods_spec.rb +0 -520
- data/spec/misc_spec.rb +0 -206
- data/spec/objects_spec.rb +0 -225
- data/spec/sequel_helper.rb +0 -18
- data/spec/spec_helper.rb +0 -112
- data/spec/support/active_record_data/3_2_diana.txt +0 -24
- data/spec/support/active_record_data/3_2_diana_legacy.txt +0 -24
- data/spec/support/active_record_data/3_2_multi.txt +0 -50
- data/spec/support/active_record_data/3_2_multi_legacy.txt +0 -50
- data/spec/support/active_record_data/4_0_diana.txt +0 -98
- data/spec/support/active_record_data/4_0_multi.txt +0 -198
- data/spec/support/active_record_data/4_1_diana.txt +0 -97
- data/spec/support/active_record_data/4_1_multi.txt +0 -196
- data/spec/support/active_record_data/4_2_diana.txt +0 -109
- data/spec/support/active_record_data/4_2_diana_legacy.txt +0 -109
- data/spec/support/active_record_data/4_2_multi.txt +0 -220
- data/spec/support/active_record_data/4_2_multi_legacy.txt +0 -220
- data/spec/support/active_record_data/5_0_diana.txt +0 -105
- data/spec/support/active_record_data/5_0_multi.txt +0 -212
- data/spec/support/active_record_data/5_1_diana.txt +0 -104
- data/spec/support/active_record_data/5_1_multi.txt +0 -210
- data/spec/support/active_record_data/5_2_diana.txt +0 -104
- data/spec/support/active_record_data/5_2_multi.txt +0 -210
- data/spec/support/active_record_data/6_0_diana.txt +0 -104
- data/spec/support/active_record_data/6_0_multi.txt +0 -210
- data/spec/support/active_record_data/6_1_diana.txt +0 -109
- data/spec/support/active_record_data/6_1_multi.txt +0 -220
- data/spec/support/active_record_data/7_0_diana.txt +0 -110
- data/spec/support/active_record_data/7_0_multi.txt +0 -222
- data/spec/support/active_record_data.rb +0 -22
- data/spec/support/ext_verifier.rb +0 -46
- data/spec/support/mongoid_versions.rb +0 -24
- data/spec/support/rails_versions.rb +0 -62
data/spec/misc_spec.rb
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rubocop:disable Lint/ConstantDefinitionInBlock, Lint/EmptyClass
|
4
|
-
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
RSpec.describe 'AmazingPrint' do
|
8
|
-
describe 'Misc' do
|
9
|
-
it 'handle weird objects that return nil on inspect' do
|
10
|
-
weird = Class.new do
|
11
|
-
def inspect
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
expect(weird.new.ai(plain: true)).to eq('')
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'handle frozen object.inspect' do
|
19
|
-
weird = Class.new do
|
20
|
-
def inspect
|
21
|
-
'ice'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
expect(weird.new.ai(plain: false)).to eq('ice')
|
25
|
-
end
|
26
|
-
|
27
|
-
# See https://github.com/awesome-print/awesome_print/issues/35
|
28
|
-
it 'handle array grep when pattern contains / chapacter' do
|
29
|
-
hash = { '1/x' => 1, '2//x' => :'2' }
|
30
|
-
grepped = hash.keys.sort.grep(%r{^(\d+)/}) { Regexp.last_match(1) }
|
31
|
-
expect(grepped.ai(plain: true, multiline: false)).to eq('[ "1", "2" ]')
|
32
|
-
end
|
33
|
-
|
34
|
-
# See https://github.com/awesome-print/awesome_print/issues/85
|
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
|
-
end
|
40
|
-
|
41
|
-
it 'returns value passed as a parameter' do
|
42
|
-
object = rand
|
43
|
-
allow(self).to receive(:puts)
|
44
|
-
expect(ap(object)).to eq(object)
|
45
|
-
end
|
46
|
-
|
47
|
-
# Require different file name this time (lib/ap.rb vs. lib/amazing_print).
|
48
|
-
it "several require 'amazing_print' should do no harm" do
|
49
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../lib/ap")
|
50
|
-
expect { rand.ai }.not_to raise_error
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'format ENV as hash' do
|
54
|
-
expect(ENV.ai(plain: true)).to eq(ENV.to_hash.ai(plain: true))
|
55
|
-
expect(ENV.ai).to eq(ENV.to_hash.ai)
|
56
|
-
end
|
57
|
-
|
58
|
-
# See https://github.com/awesome-print/awesome_print/issues/134
|
59
|
-
it 'IPAddr workaround' do
|
60
|
-
require 'ipaddr'
|
61
|
-
ipaddr = IPAddr.new('3ffe:505:2::1')
|
62
|
-
expect(ipaddr.ai).to eq('#<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>')
|
63
|
-
end
|
64
|
-
|
65
|
-
# See https://github.com/awesome-print/awesome_print/issues/139
|
66
|
-
it 'Object that overrides == and expects the :id method' do
|
67
|
-
weird = Class.new do
|
68
|
-
# Raises NoMethodError: undefined method `id' when "other" is nil or ENV.
|
69
|
-
def ==(other)
|
70
|
-
id == other.id
|
71
|
-
end
|
72
|
-
alias_method :eql?, :==
|
73
|
-
end
|
74
|
-
expect { weird.new.ai }.not_to raise_error
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
#------------------------------------------------------------------------------
|
79
|
-
describe 'HTML output' do
|
80
|
-
it 'wraps ap output with plain <pre> tag' do
|
81
|
-
markup = rand
|
82
|
-
expect(markup.ai(html: true, plain: true)).to eq("<pre>#{markup}</pre>")
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'wraps ap output with <pre> tag with colorized <kbd>' do
|
86
|
-
markup = rand
|
87
|
-
expect(markup.ai(html: true)).to eq(%(<pre><kbd style="color:blue">#{markup}</kbd></pre>))
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'wraps multiline ap output with <pre> tag with colorized <kbd>' do
|
91
|
-
markup = [1, :two, 'three']
|
92
|
-
expect(markup.ai(html: true)).to eq <<~EOS.strip
|
93
|
-
<pre>[
|
94
|
-
<kbd style="color:white">[0] </kbd><kbd style="color:blue">1</kbd>,
|
95
|
-
<kbd style="color:white">[1] </kbd><kbd style="color:darkcyan">:two</kbd>,
|
96
|
-
<kbd style="color:white">[2] </kbd><kbd style="color:brown">"three"</kbd>
|
97
|
-
]</pre>
|
98
|
-
EOS
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'wraps hash ap output with only an outer <pre> tag' do
|
102
|
-
markup = [{ 'hello' => 'world' }]
|
103
|
-
expect(markup.ai(html: true)).to eq <<~EOS.strip
|
104
|
-
<pre>[
|
105
|
-
<kbd style="color:white">[0] </kbd>{
|
106
|
-
<kbd style="color:brown">"hello"</kbd><kbd style="color:slategray"> => </kbd><kbd style="color:brown">"world"</kbd>
|
107
|
-
}
|
108
|
-
]</pre>
|
109
|
-
EOS
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'encodes HTML entities (plain)' do
|
113
|
-
markup = ' &<hello>'
|
114
|
-
expect(markup.ai(html: true, plain: true)).to eq('<pre>" &<hello>"</pre>')
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'encodes HTML entities (color)' do
|
118
|
-
markup = ' &<hello>'
|
119
|
-
expect(markup.ai(html: true)).to eq('<pre><kbd style="color:brown">" &<hello>"</kbd></pre>')
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
#------------------------------------------------------------------------------
|
124
|
-
describe 'AmazingPrint.defaults' do
|
125
|
-
after do
|
126
|
-
AmazingPrint.defaults = nil
|
127
|
-
end
|
128
|
-
|
129
|
-
# See https://github.com/awesome-print/awesome_print/issues/98
|
130
|
-
it 'properlies merge the defaults' do
|
131
|
-
AmazingPrint.defaults = { indent: -2, sort_keys: true }
|
132
|
-
hash = { [0, 0, 255] => :yellow, :red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' }
|
133
|
-
out = hash.ai(plain: true)
|
134
|
-
expect(out).to eq <<~EOS.strip
|
135
|
-
{
|
136
|
-
[ 0, 0, 255 ] => :yellow,
|
137
|
-
"magenta" => "rgb(255, 0, 255)",
|
138
|
-
:red => "rgb(255, 0, 0)"
|
139
|
-
}
|
140
|
-
EOS
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
#------------------------------------------------------------------------------
|
145
|
-
describe 'Console' do
|
146
|
-
it 'detects IRB' do
|
147
|
-
class IRB; end
|
148
|
-
ENV.delete('RAILS_ENV')
|
149
|
-
expect(AmazingPrint.console?).to be(true)
|
150
|
-
expect(AmazingPrint.rails_console?).to be(false)
|
151
|
-
Object.instance_eval { remove_const :IRB }
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'detects Pry' do
|
155
|
-
class Pry; end
|
156
|
-
ENV.delete('RAILS_ENV')
|
157
|
-
expect(AmazingPrint.console?).to be(true)
|
158
|
-
expect(AmazingPrint.rails_console?).to be(false)
|
159
|
-
Object.instance_eval { remove_const :Pry }
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'detects Rails::Console' do
|
163
|
-
class IRB; end
|
164
|
-
|
165
|
-
module Rails; class Console; end; end
|
166
|
-
expect(AmazingPrint.console?).to be(true)
|
167
|
-
expect(AmazingPrint.rails_console?).to be(true)
|
168
|
-
Object.instance_eval { remove_const :IRB }
|
169
|
-
Object.instance_eval { remove_const :Rails }
|
170
|
-
end
|
171
|
-
|
172
|
-
it "detects ENV['RAILS_ENV']" do
|
173
|
-
class Pry; end
|
174
|
-
ENV['RAILS_ENV'] = 'development'
|
175
|
-
expect(AmazingPrint.console?).to be(true)
|
176
|
-
expect(AmazingPrint.rails_console?).to be(true)
|
177
|
-
Object.instance_eval { remove_const :Pry }
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'returns the actual object when *not* running under console' do
|
181
|
-
expect(capture! { ap([1, 2, 3]) }).to eq([1, 2, 3])
|
182
|
-
expect(capture! { ap({ a: 1 }) }).to eq({ a: 1 })
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'returns nil when running under console' do
|
186
|
-
class IRB; end
|
187
|
-
expect(capture! { ap([1, 2, 3]) }).to be_nil
|
188
|
-
expect(capture! { ap({ a: 1 }) }).to be_nil
|
189
|
-
Object.instance_eval { remove_const :IRB }
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'handles NoMethodError on IRB implicit #ai' do
|
193
|
-
module IRB; class Irb; end; end
|
194
|
-
irb_context = double('irb_context', last_value: BasicObject.new)
|
195
|
-
IRB.define_singleton_method :version, -> { 'test_version' }
|
196
|
-
irb = IRB::Irb.new
|
197
|
-
irb.instance_eval { @context = irb_context }
|
198
|
-
AmazingPrint.irb!
|
199
|
-
expect(irb).to receive(:puts).with("(Object doesn't support #ai)")
|
200
|
-
expect { irb.output_value }.not_to raise_error
|
201
|
-
Object.instance_eval { remove_const :IRB }
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
# rubocop:enable Lint/ConstantDefinitionInBlock, Lint/EmptyClass
|
data/spec/objects_spec.rb
DELETED
@@ -1,225 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rubocop:disable Lint/ConstantDefinitionInBlock
|
4
|
-
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
RSpec.describe 'Objects' do
|
8
|
-
after do
|
9
|
-
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'Formatting an object' do
|
13
|
-
it 'attributes' do
|
14
|
-
class Hello
|
15
|
-
attr_reader :abra
|
16
|
-
attr_writer :ca
|
17
|
-
attr_accessor :dabra
|
18
|
-
|
19
|
-
def initialize
|
20
|
-
@abra = 1
|
21
|
-
@ca = 2
|
22
|
-
@dabra = 3
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
hello = Hello.new
|
27
|
-
out = hello.ai(plain: true, raw: true)
|
28
|
-
str = <<~EOS.strip
|
29
|
-
#<Hello:placeholder_id
|
30
|
-
attr_accessor :dabra = 3,
|
31
|
-
attr_reader :abra = 1,
|
32
|
-
attr_writer :ca = 2
|
33
|
-
>
|
34
|
-
EOS
|
35
|
-
expect(out).to be_similar_to(str)
|
36
|
-
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'instance variables' do
|
40
|
-
class Hello
|
41
|
-
def initialize
|
42
|
-
@abra = 1
|
43
|
-
@ca = 2
|
44
|
-
@dabra = 3
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
hello = Hello.new
|
49
|
-
out = hello.ai(plain: true, raw: true)
|
50
|
-
str = <<~EOS.strip
|
51
|
-
#<Hello:placeholder_id
|
52
|
-
@abra = 1,
|
53
|
-
@ca = 2,
|
54
|
-
@dabra = 3
|
55
|
-
>
|
56
|
-
EOS
|
57
|
-
expect(out).to be_similar_to(str)
|
58
|
-
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'attributes and instance variables' do
|
62
|
-
class Hello
|
63
|
-
attr_reader :abra
|
64
|
-
attr_writer :ca
|
65
|
-
attr_accessor :dabra
|
66
|
-
|
67
|
-
def initialize
|
68
|
-
@abra = 1
|
69
|
-
@ca = 2
|
70
|
-
@dabra = 3
|
71
|
-
@scooby = 3
|
72
|
-
@dooby = 2
|
73
|
-
@doo = 1
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
hello = Hello.new
|
78
|
-
out = hello.ai(plain: true, raw: true)
|
79
|
-
str = <<~EOS.strip
|
80
|
-
#<Hello:placeholder_id
|
81
|
-
@doo = 1,
|
82
|
-
@dooby = 2,
|
83
|
-
@scooby = 3,
|
84
|
-
attr_accessor :dabra = 3,
|
85
|
-
attr_reader :abra = 1,
|
86
|
-
attr_writer :ca = 2
|
87
|
-
>
|
88
|
-
EOS
|
89
|
-
expect(out).to be_similar_to(str)
|
90
|
-
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'without the plain options print the colorized values' do
|
94
|
-
class Hello
|
95
|
-
attr_reader :abra
|
96
|
-
attr_writer :ca
|
97
|
-
|
98
|
-
def initialize
|
99
|
-
@abra = 1
|
100
|
-
@ca = 2
|
101
|
-
@dabra = 3
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
hello = Hello.new
|
106
|
-
out = hello.ai(raw: true)
|
107
|
-
str = <<~EOS.strip
|
108
|
-
#<Hello:placeholder_id
|
109
|
-
\e[0;36m@dabra\e[0m\e[0;37m = \e[0m\e[1;34m3\e[0m,
|
110
|
-
\e[1;36mattr_reader\e[0m \e[0;35m:abra\e[0m\e[0;37m = \e[0m\e[1;34m1\e[0m,
|
111
|
-
\e[1;36mattr_writer\e[0m \e[0;35m:ca\e[0m\e[0;37m = \e[0m\e[1;34m2\e[0m
|
112
|
-
>
|
113
|
-
EOS
|
114
|
-
expect(out).to be_similar_to(str)
|
115
|
-
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'with multine as false show inline values' do
|
119
|
-
class Hello
|
120
|
-
attr_reader :abra
|
121
|
-
attr_writer :ca
|
122
|
-
|
123
|
-
def initialize
|
124
|
-
@abra = 1
|
125
|
-
@ca = 2
|
126
|
-
@dabra = 3
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
hello = Hello.new
|
131
|
-
out = hello.ai(multiline: false, plain: true, raw: true)
|
132
|
-
str = <<~EOS.strip
|
133
|
-
#<Hello:placeholder_id @dabra = 3, attr_reader :abra = 1, attr_writer :ca = 2>
|
134
|
-
EOS
|
135
|
-
expect(out).to be_similar_to(str)
|
136
|
-
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'without the sort_vars option does not sort instance variables' do
|
140
|
-
class Hello
|
141
|
-
attr_reader :abra
|
142
|
-
attr_writer :ca
|
143
|
-
attr_accessor :dabra
|
144
|
-
|
145
|
-
def initialize
|
146
|
-
@abra = 1
|
147
|
-
@ca = 2
|
148
|
-
@dabra = 3
|
149
|
-
@scooby = 3
|
150
|
-
@dooby = 2
|
151
|
-
@doo = 1
|
152
|
-
end
|
153
|
-
|
154
|
-
def instance_variables
|
155
|
-
%i[@scooby @dooby @doo @abra @ca @dabra]
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
hello = Hello.new
|
160
|
-
out = hello.ai(plain: true, raw: true, sort_vars: false)
|
161
|
-
str = <<~EOS.strip
|
162
|
-
#<Hello:placeholder_id
|
163
|
-
@scooby = 3,
|
164
|
-
@dooby = 2,
|
165
|
-
@doo = 1,
|
166
|
-
attr_reader :abra = 1,
|
167
|
-
attr_writer :ca = 2,
|
168
|
-
attr_accessor :dabra = 3
|
169
|
-
>
|
170
|
-
EOS
|
171
|
-
expect(out).to be_similar_to(str)
|
172
|
-
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'object_id' do
|
176
|
-
class Hello
|
177
|
-
def initialize
|
178
|
-
@abra = 1
|
179
|
-
@ca = 2
|
180
|
-
@dabra = 3
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
hello = Hello.new
|
185
|
-
out = hello.ai(plain: true, raw: true, object_id: false)
|
186
|
-
str = <<~EOS.strip
|
187
|
-
#<Hello
|
188
|
-
@abra = 1,
|
189
|
-
@ca = 2,
|
190
|
-
@dabra = 3
|
191
|
-
>
|
192
|
-
EOS
|
193
|
-
expect(out).to be_similar_to(str)
|
194
|
-
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'class_name' do
|
198
|
-
class Hello
|
199
|
-
def initialize
|
200
|
-
@abra = 1
|
201
|
-
@ca = 2
|
202
|
-
@dabra = 3
|
203
|
-
end
|
204
|
-
|
205
|
-
def to_s
|
206
|
-
'CustomizedHello'
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
hello = Hello.new
|
211
|
-
out = hello.ai(plain: true, raw: true, class_name: :to_s)
|
212
|
-
str = <<~EOS.strip
|
213
|
-
#<CustomizedHello:placeholder_id
|
214
|
-
@abra = 1,
|
215
|
-
@ca = 2,
|
216
|
-
@dabra = 3
|
217
|
-
>
|
218
|
-
EOS
|
219
|
-
expect(out).to be_similar_to(str)
|
220
|
-
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
# rubocop:enable Lint/ConstantDefinitionInBlock
|
data/spec/sequel_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if ExtVerifier.has_sequel?
|
4
|
-
# Establish connection to in-memory SQLite DB
|
5
|
-
DB = RUBY_PLATFORM == 'java' ? Sequel.connect('jdbc:sqlite::memory:') : Sequel.sqlite
|
6
|
-
|
7
|
-
# Create the users table
|
8
|
-
DB.create_table :sequel_users do
|
9
|
-
primary_key :id
|
10
|
-
String :first_name
|
11
|
-
String :last_name
|
12
|
-
TrueClass :admin
|
13
|
-
DateTime :created_at
|
14
|
-
end
|
15
|
-
|
16
|
-
# Create models
|
17
|
-
class SequelUser < Sequel::Model; end
|
18
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
4
|
-
#
|
5
|
-
# AmazingPrint is freely distributable under the terms of MIT license.
|
6
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
7
|
-
#------------------------------------------------------------------------------
|
8
|
-
#
|
9
|
-
# Running specs from the command line:
|
10
|
-
# $ rake spec # Entire spec suite.
|
11
|
-
# $ rspec spec/objects_spec.rb # Individual spec file.
|
12
|
-
#
|
13
|
-
# NOTE: To successfully run specs with Ruby 1.8.6 the older versions of
|
14
|
-
# Bundler and RSpec gems are required:
|
15
|
-
#
|
16
|
-
# $ gem install bundler -v=1.0.2
|
17
|
-
# $ gem install rspec -v=2.6.0
|
18
|
-
#
|
19
|
-
|
20
|
-
# require 'simplecov'
|
21
|
-
# SimpleCov.start
|
22
|
-
|
23
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
24
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
25
|
-
|
26
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each do |file|
|
27
|
-
require file
|
28
|
-
end
|
29
|
-
|
30
|
-
ExtVerifier.require_dependencies!(
|
31
|
-
%w[
|
32
|
-
rails
|
33
|
-
active_record
|
34
|
-
action_controller
|
35
|
-
action_view
|
36
|
-
active_support/all
|
37
|
-
mongoid
|
38
|
-
mongo_mapper
|
39
|
-
ripple nobrainer
|
40
|
-
ostruct
|
41
|
-
sequel
|
42
|
-
]
|
43
|
-
)
|
44
|
-
require 'nokogiri' unless RUBY_PLATFORM.include?('mswin')
|
45
|
-
require 'amazing_print'
|
46
|
-
|
47
|
-
RSpec.configure do |config|
|
48
|
-
config.disable_monkey_patching!
|
49
|
-
# TODO: Make specs not order dependent
|
50
|
-
# config.order = :random
|
51
|
-
Kernel.srand config.seed
|
52
|
-
config.filter_run focus: true
|
53
|
-
config.run_all_when_everything_filtered = true
|
54
|
-
config.expect_with :rspec do |expectations|
|
55
|
-
expectations.syntax = :expect
|
56
|
-
end
|
57
|
-
config.mock_with :rspec do |mocks|
|
58
|
-
mocks.syntax = :expect
|
59
|
-
mocks.verify_partial_doubles = true
|
60
|
-
end
|
61
|
-
|
62
|
-
config.default_formatter = 'doc' if config.files_to_run.one?
|
63
|
-
|
64
|
-
# Run before all examples. Using suite or all will not work as stubs are
|
65
|
-
# killed after each example ends.
|
66
|
-
config.before do |_example|
|
67
|
-
stub_dotfile!
|
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
|
75
|
-
end
|
76
|
-
|
77
|
-
# This matcher handles the normalization of objects to replace non deterministic
|
78
|
-
# parts (such as object IDs) with simple placeholder strings before doing a
|
79
|
-
# comparison with a given string. It's important that this method only matches
|
80
|
-
# a string which strictly conforms to the expected object ID format.
|
81
|
-
RSpec::Matchers.define :be_similar_to do |expected, options|
|
82
|
-
match do |actual|
|
83
|
-
options ||= {}
|
84
|
-
@actual = normalize_object_id_strings(actual, options)
|
85
|
-
values_match? expected, @actual
|
86
|
-
end
|
87
|
-
|
88
|
-
diffable
|
89
|
-
end
|
90
|
-
|
91
|
-
# Override the Object IDs with a placeholder so that we are only checking
|
92
|
-
# that an ID is present and not that it matches a certain value. This is
|
93
|
-
# necessary as the Object IDs are not deterministic.
|
94
|
-
def normalize_object_id_strings(str, options)
|
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]
|
97
|
-
str
|
98
|
-
end
|
99
|
-
|
100
|
-
def stub_dotfile!
|
101
|
-
allow_any_instance_of(AmazingPrint::Inspector)
|
102
|
-
.to receive(:load_dotfile)
|
103
|
-
.and_return(true)
|
104
|
-
end
|
105
|
-
|
106
|
-
def capture!
|
107
|
-
standard = $stdout
|
108
|
-
$stdout = StringIO.new
|
109
|
-
yield
|
110
|
-
ensure
|
111
|
-
$stdout = standard
|
112
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
#<User:placeholder_id
|
2
|
-
@aggregation_cache = {},
|
3
|
-
@attributes_cache = {},
|
4
|
-
@destroyed = false,
|
5
|
-
@marked_for_destruction = false,
|
6
|
-
@mass_assignment_options = nil,
|
7
|
-
@new_record = true,
|
8
|
-
@previously_changed = {},
|
9
|
-
@readonly = false,
|
10
|
-
attr_accessor :attributes = {
|
11
|
-
"admin" => false,
|
12
|
-
"created_at" => "1992-10-10 12:30:00",
|
13
|
-
"id" => nil,
|
14
|
-
"name" => "Diana",
|
15
|
-
"rank" => 1
|
16
|
-
},
|
17
|
-
attr_reader :association_cache = {},
|
18
|
-
attr_reader :changed_attributes = {
|
19
|
-
"admin" => nil,
|
20
|
-
"created_at" => nil,
|
21
|
-
"name" => nil,
|
22
|
-
"rank" => nil
|
23
|
-
}
|
24
|
-
>
|
@@ -1,24 +0,0 @@
|
|
1
|
-
#<User:placeholder_id
|
2
|
-
@aggregation_cache = {},
|
3
|
-
@attributes_cache = {},
|
4
|
-
@destroyed = false,
|
5
|
-
@marked_for_destruction = false,
|
6
|
-
@new_record = true,
|
7
|
-
@previously_changed = {},
|
8
|
-
@readonly = false,
|
9
|
-
attr_accessor :attributes = {
|
10
|
-
"admin" => false,
|
11
|
-
"created_at" => "1992-10-10 12:30:00",
|
12
|
-
"id" => nil,
|
13
|
-
"name" => "Diana",
|
14
|
-
"rank" => 1
|
15
|
-
},
|
16
|
-
attr_reader :association_cache = {},
|
17
|
-
attr_reader :changed_attributes = {
|
18
|
-
"admin" => nil,
|
19
|
-
"created_at" => nil,
|
20
|
-
"name" => nil,
|
21
|
-
"rank" => nil
|
22
|
-
},
|
23
|
-
attr_reader :mass_assignment_options = nil
|
24
|
-
>
|
@@ -1,50 +0,0 @@
|
|
1
|
-
[
|
2
|
-
[0] #<User:placeholder_id
|
3
|
-
@aggregation_cache = {},
|
4
|
-
@attributes_cache = {},
|
5
|
-
@destroyed = false,
|
6
|
-
@marked_for_destruction = false,
|
7
|
-
@mass_assignment_options = nil,
|
8
|
-
@new_record = true,
|
9
|
-
@previously_changed = {},
|
10
|
-
@readonly = false,
|
11
|
-
attr_accessor :attributes = {
|
12
|
-
"admin" => false,
|
13
|
-
"created_at" => "1992-10-10 12:30:00",
|
14
|
-
"id" => nil,
|
15
|
-
"name" => "Diana",
|
16
|
-
"rank" => 1
|
17
|
-
},
|
18
|
-
attr_reader :association_cache = {},
|
19
|
-
attr_reader :changed_attributes = {
|
20
|
-
"admin" => nil,
|
21
|
-
"created_at" => nil,
|
22
|
-
"name" => nil,
|
23
|
-
"rank" => nil
|
24
|
-
}
|
25
|
-
>,
|
26
|
-
[1] #<User:placeholder_id
|
27
|
-
@aggregation_cache = {},
|
28
|
-
@attributes_cache = {},
|
29
|
-
@destroyed = false,
|
30
|
-
@marked_for_destruction = false,
|
31
|
-
@mass_assignment_options = nil,
|
32
|
-
@new_record = true,
|
33
|
-
@previously_changed = {},
|
34
|
-
@readonly = false,
|
35
|
-
attr_accessor :attributes = {
|
36
|
-
"admin" => true,
|
37
|
-
"created_at" => "2003-05-26 14:15:00",
|
38
|
-
"id" => nil,
|
39
|
-
"name" => "Laura",
|
40
|
-
"rank" => 2
|
41
|
-
},
|
42
|
-
attr_reader :association_cache = {},
|
43
|
-
attr_reader :changed_attributes = {
|
44
|
-
"admin" => nil,
|
45
|
-
"created_at" => nil,
|
46
|
-
"name" => nil,
|
47
|
-
"rank" => nil
|
48
|
-
}
|
49
|
-
>
|
50
|
-
]
|