2014-12-31 15:59:32 -05:00
|
|
|
require 'spec_helper'
|
2011-11-08 19:49:06 -05:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
RSpec.describe "Objects" do
|
2011-11-08 19:49:06 -05:00
|
|
|
before do
|
|
|
|
stub_dotfile!
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
|
|
end
|
|
|
|
|
2012-09-11 18:41:33 -04:00
|
|
|
describe "Formatting an object" do
|
2011-11-08 19:49:06 -05:00
|
|
|
it "attributes" do
|
|
|
|
class Hello
|
|
|
|
attr_reader :abra
|
|
|
|
attr_writer :ca
|
|
|
|
attr_accessor :dabra
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@abra, @ca, @dabra = 1, 2, 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-11 18:41:33 -04:00
|
|
|
hello = Hello.new
|
|
|
|
out = hello.ai(:plain => true, :raw => true)
|
2011-11-08 19:49:06 -05:00
|
|
|
str = <<-EOS.strip
|
|
|
|
#<Hello:0x01234567
|
|
|
|
attr_accessor :dabra = 3,
|
|
|
|
attr_reader :abra = 1,
|
|
|
|
attr_writer :ca = 2
|
|
|
|
>
|
|
|
|
EOS
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
|
|
|
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "instance variables" do
|
|
|
|
class Hello
|
|
|
|
def initialize
|
|
|
|
@abra, @ca, @dabra = 1, 2, 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-11 18:41:33 -04:00
|
|
|
hello = Hello.new
|
|
|
|
out = hello.ai(:plain => true, :raw => true)
|
2011-11-08 19:49:06 -05:00
|
|
|
str = <<-EOS.strip
|
|
|
|
#<Hello:0x01234567
|
|
|
|
@abra = 1,
|
|
|
|
@ca = 2,
|
|
|
|
@dabra = 3
|
|
|
|
>
|
|
|
|
EOS
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
|
|
|
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "attributes and instance variables" do
|
|
|
|
class Hello
|
|
|
|
attr_reader :abra
|
|
|
|
attr_writer :ca
|
|
|
|
attr_accessor :dabra
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@abra, @ca, @dabra = 1, 2, 3
|
|
|
|
@scooby, @dooby, @doo = 3, 2, 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-11 18:41:33 -04:00
|
|
|
hello = Hello.new
|
|
|
|
out = hello.ai(:plain => true, :raw => true)
|
2011-11-08 19:49:06 -05:00
|
|
|
str = <<-EOS.strip
|
|
|
|
#<Hello:0x01234567
|
|
|
|
@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
|
|
|
|
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
|
|
|
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "without the plain options print the colorized values" do
|
|
|
|
class Hello
|
|
|
|
attr_reader :abra
|
|
|
|
attr_writer :ca
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@abra, @ca = 1, 2
|
|
|
|
@dabra = 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hello = Hello.new
|
|
|
|
out = hello.ai(:raw => true)
|
|
|
|
str = <<-EOS.strip
|
|
|
|
#<Hello:0x01234567
|
|
|
|
\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
|
|
|
|
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
|
|
|
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "with multine as false show inline values" do
|
|
|
|
class Hello
|
|
|
|
attr_reader :abra
|
|
|
|
attr_writer :ca
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@abra, @ca = 1, 2
|
|
|
|
@dabra = 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hello = Hello.new
|
|
|
|
out = hello.ai(:multiline => false, :plain => true, :raw => true)
|
|
|
|
str = <<-EOS.strip
|
|
|
|
#<Hello:0x01234567 @dabra = 3, attr_reader :abra = 1, attr_writer :ca = 2>
|
2011-11-08 19:49:06 -05:00
|
|
|
EOS
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
|
|
|
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
2011-11-08 19:49:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|