1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Merge pull request #186 from michaeldv/coverage

Improve code coverage
This commit is contained in:
Mauro George 2015-02-12 19:45:12 -02:00
commit d8aeb66b4b
3 changed files with 81 additions and 0 deletions

View file

@ -53,6 +53,38 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
:name => "Laura",
:rank => 2
}
]
EOS
if RUBY_VERSION < '1.9'
str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992')
str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003')
else
str.sub!('??', '1992-10-10 12:30:00 UTC')
str.sub!('?!', '2003-05-26 14:15:00 UTC')
end
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
end
it "display multiple records on a relation" do
@diana.save
@laura.save
out = @ap.send(:awesome, User.all)
str = <<-EOS.strip
[
[0] #<User:0x01234567> {
:admin => false,
:created_at => ??,
:id => 1,
:name => "Diana",
:rank => 1
},
[1] #<User:0x01234567> {
:admin => true,
:created_at => ?!,
:id => 2,
:name => "Laura",
:rank => 2
}
]
EOS
if RUBY_VERSION < '1.9'

View file

@ -42,4 +42,9 @@ RSpec.describe "AwesomePrint/Nokogiri" do
\e[0m<\e[1;36m/html\e[0m>
EOS
end
it "handle empty NodeSet" do
xml = Nokogiri::XML::NodeSet.new(Nokogiri::XML(''))
expect(xml.ai).to eq('[]')
end
end

View file

@ -77,6 +77,50 @@ EOS
attr_reader :abra = 1,
attr_writer :ca = 2
>
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>
EOS
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)