2014-12-31 15:59:32 -05:00
|
|
|
require 'spec_helper'
|
2011-11-08 19:49:06 -05:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
RSpec.describe 'Objects' do
|
2011-11-08 19:49:06 -05:00
|
|
|
after do
|
2016-11-08 21:39:25 -05:00
|
|
|
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
describe 'Formatting an object' do
|
|
|
|
it 'attributes' do
|
2011-11-08 19:49:06 -05:00
|
|
|
class Hello
|
|
|
|
attr_reader :abra
|
|
|
|
attr_writer :ca
|
|
|
|
attr_accessor :dabra
|
|
|
|
|
|
|
|
def initialize
|
2016-11-09 01:04:02 -05:00
|
|
|
@abra = 1
|
|
|
|
@ca = 2
|
|
|
|
@dabra = 3
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-11 18:41:33 -04:00
|
|
|
hello = Hello.new
|
2016-11-08 09:53:17 -05:00
|
|
|
out = hello.ai(plain: true, raw: true)
|
2011-11-08 19:49:06 -05:00
|
|
|
str = <<-EOS.strip
|
2016-05-09 10:04:42 -04:00
|
|
|
#<Hello:placeholder_id
|
2011-11-08 19:49:06 -05:00
|
|
|
attr_accessor :dabra = 3,
|
|
|
|
attr_reader :abra = 1,
|
|
|
|
attr_writer :ca = 2
|
|
|
|
>
|
|
|
|
EOS
|
2016-05-09 10:04:42 -04:00
|
|
|
expect(out).to be_similar_to(str)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'instance variables' do
|
2011-11-08 19:49:06 -05:00
|
|
|
class Hello
|
|
|
|
def initialize
|
2016-11-09 01:04:02 -05:00
|
|
|
@abra = 1
|
|
|
|
@ca = 2
|
|
|
|
@dabra = 3
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-11 18:41:33 -04:00
|
|
|
hello = Hello.new
|
2016-11-08 09:53:17 -05:00
|
|
|
out = hello.ai(plain: true, raw: true)
|
2011-11-08 19:49:06 -05:00
|
|
|
str = <<-EOS.strip
|
2016-05-09 10:04:42 -04:00
|
|
|
#<Hello:placeholder_id
|
2011-11-08 19:49:06 -05:00
|
|
|
@abra = 1,
|
|
|
|
@ca = 2,
|
|
|
|
@dabra = 3
|
|
|
|
>
|
|
|
|
EOS
|
2016-05-09 10:04:42 -04:00
|
|
|
expect(out).to be_similar_to(str)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'attributes and instance variables' do
|
2011-11-08 19:49:06 -05:00
|
|
|
class Hello
|
|
|
|
attr_reader :abra
|
|
|
|
attr_writer :ca
|
|
|
|
attr_accessor :dabra
|
|
|
|
|
|
|
|
def initialize
|
2016-11-09 01:04:02 -05:00
|
|
|
@abra = 1
|
|
|
|
@ca = 2
|
|
|
|
@dabra = 3
|
|
|
|
@scooby = 3
|
|
|
|
@dooby = 2
|
|
|
|
@doo = 1
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-11 18:41:33 -04:00
|
|
|
hello = Hello.new
|
2016-11-08 09:53:17 -05:00
|
|
|
out = hello.ai(plain: true, raw: true)
|
2011-11-08 19:49:06 -05:00
|
|
|
str = <<-EOS.strip
|
2016-05-09 10:04:42 -04:00
|
|
|
#<Hello:placeholder_id
|
2011-11-08 19:49:06 -05:00
|
|
|
@doo = 1,
|
|
|
|
@dooby = 2,
|
|
|
|
@scooby = 3,
|
|
|
|
attr_accessor :dabra = 3,
|
|
|
|
attr_reader :abra = 1,
|
|
|
|
attr_writer :ca = 2
|
|
|
|
>
|
2015-02-12 15:52:23 -05:00
|
|
|
EOS
|
2016-05-09 10:04:42 -04:00
|
|
|
expect(out).to be_similar_to(str)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
2015-02-12 15:52:23 -05:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'without the plain options print the colorized values' do
|
2015-02-12 15:52:23 -05:00
|
|
|
class Hello
|
|
|
|
attr_reader :abra
|
|
|
|
attr_writer :ca
|
|
|
|
|
|
|
|
def initialize
|
2016-11-09 01:04:02 -05:00
|
|
|
@abra = 1
|
|
|
|
@ca = 2
|
2015-02-12 15:52:23 -05:00
|
|
|
@dabra = 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hello = Hello.new
|
2016-11-08 09:53:17 -05:00
|
|
|
out = hello.ai(raw: true)
|
2015-02-12 15:52:23 -05:00
|
|
|
str = <<-EOS.strip
|
2016-05-09 10:04:42 -04:00
|
|
|
#<Hello:placeholder_id
|
2015-02-12 15:52:23 -05:00
|
|
|
\e[0;36m@dabra\e[0m\e[0;37m = \e[0m\e[1;34m3\e[0m,
|
|
|
|
\e[1;36mattr_reader\e[0m \e[0;35m:abra\e[0m\e[0;37m = \e[0m\e[1;34m1\e[0m,
|
|
|
|
\e[1;36mattr_writer\e[0m \e[0;35m:ca\e[0m\e[0;37m = \e[0m\e[1;34m2\e[0m
|
|
|
|
>
|
|
|
|
EOS
|
2016-05-09 10:04:42 -04:00
|
|
|
expect(out).to be_similar_to(str)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
2015-02-12 15:52:23 -05:00
|
|
|
end
|
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'with multine as false show inline values' do
|
2015-02-12 15:52:23 -05:00
|
|
|
class Hello
|
|
|
|
attr_reader :abra
|
|
|
|
attr_writer :ca
|
|
|
|
|
|
|
|
def initialize
|
2016-11-09 01:04:02 -05:00
|
|
|
@abra = 1
|
|
|
|
@ca = 2
|
2015-02-12 15:52:23 -05:00
|
|
|
@dabra = 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hello = Hello.new
|
2016-11-08 09:53:17 -05:00
|
|
|
out = hello.ai(multiline: false, plain: true, raw: true)
|
2015-02-12 15:52:23 -05:00
|
|
|
str = <<-EOS.strip
|
2016-05-09 10:04:42 -04:00
|
|
|
#<Hello:placeholder_id @dabra = 3, attr_reader :abra = 1, attr_writer :ca = 2>
|
2017-01-10 07:58:55 -05:00
|
|
|
EOS
|
|
|
|
expect(out).to be_similar_to(str)
|
|
|
|
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'without the sort_vars option does not sort instance variables' do
|
|
|
|
class Hello
|
|
|
|
attr_reader :abra
|
|
|
|
attr_writer :ca
|
|
|
|
attr_accessor :dabra
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@abra = 1
|
|
|
|
@ca = 2
|
|
|
|
@dabra = 3
|
|
|
|
@scooby = 3
|
|
|
|
@dooby = 2
|
|
|
|
@doo = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def instance_variables
|
|
|
|
[:@scooby, :@dooby, :@doo, :@abra, :@ca, :@dabra]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hello = Hello.new
|
|
|
|
out = hello.ai(plain: true, raw: true, sort_vars: false)
|
|
|
|
str = <<-EOS.strip
|
|
|
|
#<Hello:placeholder_id
|
|
|
|
@scooby = 3,
|
|
|
|
@dooby = 2,
|
|
|
|
@doo = 1,
|
|
|
|
attr_reader :abra = 1,
|
|
|
|
attr_writer :ca = 2,
|
|
|
|
attr_accessor :dabra = 3
|
|
|
|
>
|
2011-11-08 19:49:06 -05:00
|
|
|
EOS
|
2016-05-09 10:04:42 -04:00
|
|
|
expect(out).to be_similar_to(str)
|
2016-11-08 09:53:17 -05:00
|
|
|
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
2017-01-10 08:48:36 -05:00
|
|
|
|
|
|
|
it 'object_id' do
|
|
|
|
class Hello
|
|
|
|
def initialize
|
|
|
|
@abra = 1
|
|
|
|
@ca = 2
|
|
|
|
@dabra = 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hello = Hello.new
|
|
|
|
out = hello.ai(plain: true, raw: true, object_id: false)
|
|
|
|
str = <<-EOS.strip
|
|
|
|
#<Hello
|
|
|
|
@abra = 1,
|
|
|
|
@ca = 2,
|
|
|
|
@dabra = 3
|
|
|
|
>
|
|
|
|
EOS
|
|
|
|
expect(out).to be_similar_to(str)
|
|
|
|
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'class_name' do
|
|
|
|
class Hello
|
|
|
|
def initialize
|
|
|
|
@abra = 1
|
|
|
|
@ca = 2
|
|
|
|
@dabra = 3
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"CustomizedHello"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hello = Hello.new
|
|
|
|
out = hello.ai(plain: true, raw: true, class_name: :to_s)
|
|
|
|
str = <<-EOS.strip
|
|
|
|
#<CustomizedHello:placeholder_id
|
|
|
|
@abra = 1,
|
|
|
|
@ca = 2,
|
|
|
|
@dabra = 3
|
|
|
|
>
|
|
|
|
EOS
|
|
|
|
expect(out).to be_similar_to(str)
|
|
|
|
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
|
|
|
end
|
|
|
|
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
end
|