From f67bb17e1102a93980e8a5b1943d27dcbdf925b9 Mon Sep 17 00:00:00 2001 From: Mauro George Date: Wed, 11 Feb 2015 19:52:11 -0200 Subject: [PATCH 1/3] Cover missing line on ActiveRecord The type check of ActiveRecord::Relation on ActiveRecord extension was never reached. With this tests, we add a coverage against this. --- spec/ext/active_record_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/ext/active_record_spec.rb b/spec/ext/active_record_spec.rb index 5b4a6ec..6b67ac3 100644 --- a/spec/ext/active_record_spec.rb +++ b/spec/ext/active_record_spec.rb @@ -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] # { + :admin => false, + :created_at => ??, + :id => 1, + :name => "Diana", + :rank => 1 + }, + [1] # { + :admin => true, + :created_at => ?!, + :id => 2, + :name => "Laura", + :rank => 2 + } ] EOS if RUBY_VERSION < '1.9' From 4249b7acffc045839f376af7e3b178c2850ebbfd Mon Sep 17 00:00:00 2001 From: Mauro George Date: Thu, 12 Feb 2015 18:52:23 -0200 Subject: [PATCH 2/3] Improve coverage of Formatter#awesome_object Cover the case when the option plain is false, this way show the colorized object. Cover the multiline option as false, this way show the content in a single line. --- spec/objects_spec.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/spec/objects_spec.rb b/spec/objects_spec.rb index ee7d241..cdbfa40 100644 --- a/spec/objects_spec.rb +++ b/spec/objects_spec.rb @@ -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 +# +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 +# EOS expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str) expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect) From 41e40e2bb67273cd8e57b98d5d5be85ccc45681b Mon Sep 17 00:00:00 2001 From: Mauro George Date: Thu, 12 Feb 2015 19:24:47 -0200 Subject: [PATCH 3/3] Add code coverage to AwesomePrint::Nokogiri when handles a empty NodeSet --- spec/ext/nokogiri_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/ext/nokogiri_spec.rb b/spec/ext/nokogiri_spec.rb index 19623e0..466059b 100644 --- a/spec/ext/nokogiri_spec.rb +++ b/spec/ext/nokogiri_spec.rb @@ -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