From bef11700b5b03a2982c7f55ee60bfeb0435fd589 Mon Sep 17 00:00:00 2001 From: Mike Dvorkin Date: Mon, 3 Sep 2012 21:22:05 -0700 Subject: [PATCH] Make sure Rational specs pass with Ruby 1.8.x --- README.md | 1 + lib/awesome_print/formatter.rb | 2 +- spec/formats_spec.rb | 12 +++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f23c4e7..3fcc45e 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Default options: :keyword => :cyan, :method => :purpleish, :nilclass => :red, + :rational => :blue, :string => :yellowish, :struct => :pale, :symbol => :cyanish, diff --git a/lib/awesome_print/formatter.rb b/lib/awesome_print/formatter.rb index bcf62c6..0465c93 100755 --- a/lib/awesome_print/formatter.rb +++ b/lib/awesome_print/formatter.rb @@ -201,7 +201,7 @@ module AwesomePrint def awesome_bigdecimal(n) colorize(n.to_s("F"), :bigdecimal) end - + # Format Rational object. #------------------------------------------------------------------------------ def awesome_rational(n) diff --git a/spec/formats_spec.rb b/spec/formats_spec.rb index e665e96..d6d4674 100644 --- a/spec/formats_spec.rb +++ b/spec/formats_spec.rb @@ -486,7 +486,17 @@ EOS it "should present Rational object with arbitrary precision" do rat = Rational(201020102010201020102010201020102010, 2) - rat.ai(:plain => true).should == "100510051005100510051005100510051005/1" + out = rat.ai(:plain => true) + # + # Ruby 1.9 slightly changed the format of Rational#to_s, see + # http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3 and + # http://www.ruby-forum.com/topic/189397 + # + if RUBY_VERSION < "1.9" + out.should == "100510051005100510051005100510051005" + else + out.should == "100510051005100510051005100510051005/1" + end end end