From 7e6e7c01aa049170d46187fdacdb41944e714522 Mon Sep 17 00:00:00 2001 From: Mauro George Date: Thu, 12 Feb 2015 19:57:41 -0200 Subject: [PATCH] Remove conditional check against old Ruby versions AwesomePrint supports Ruby 1.9.3 or later. This remove lot of conditional check against Ruby prior to 1.9.3. --- spec/ext/active_record_spec.rb | 30 ++------ spec/formats_spec.rb | 61 ++++------------ spec/methods_spec.rb | 128 ++++++++++++--------------------- spec/misc_spec.rb | 17 ++--- 4 files changed, 69 insertions(+), 167 deletions(-) diff --git a/spec/ext/active_record_spec.rb b/spec/ext/active_record_spec.rb index 6b67ac3..860a5db 100644 --- a/spec/ext/active_record_spec.rb +++ b/spec/ext/active_record_spec.rb @@ -27,11 +27,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }. :rank => 1 } EOS - if RUBY_VERSION < '1.9' - str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992') - else - str.sub!('?', '1992-10-10 12:30:00 UTC') - end + str.sub!('?', '1992-10-10 12:30:00 UTC') expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str) end @@ -55,13 +51,8 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }. } ] 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 + str.sub!('??', '1992-10-10 12:30:00 UTC') + str.sub!('?!', '2003-05-26 14:15:00 UTC') expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str) end @@ -87,13 +78,8 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }. } ] 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 + str.sub!('??', '1992-10-10 12:30:00 UTC') + str.sub!('?!', '2003-05-26 14:15:00 UTC') expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str) end end @@ -1695,11 +1681,7 @@ class SubUser < User { out = @ap.send(:awesome, User.methods.grep(/first/)) if ActiveRecord::VERSION::STRING >= "3.2" - if RUBY_VERSION >= "1.9" - expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/) - else - expect(out).to match(/\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/) - end + expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/) else expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/) end diff --git a/spec/formats_spec.rb b/spec/formats_spec.rb index 4c1c8ac..91c8b0b 100644 --- a/spec/formats_spec.rb +++ b/spec/formats_spec.rb @@ -361,14 +361,7 @@ EOS it "plain multiline" do out = @hash.ai(:plain => true) - if RUBY_VERSION.to_f < 1.9 # Order of @hash keys is not guaranteed. - expect(out).to match(/^\{[^\}]+\}/m) - expect(out).to match(/ "b" => "b",?/) - expect(out).to match(/ :a => "a",?/) - expect(out).to match(/ :z => "z",?/) - expect(out).to match(/ "alpha" => "alpha",?$/) - else - expect(out).to eq <<-EOS.strip + expect(out).to eq <<-EOS.strip { "b" => "b", :a => "a", @@ -376,7 +369,6 @@ EOS "alpha" => "alpha" } EOS - end end it "plain multiline with sorted keys" do @@ -488,16 +480,7 @@ EOS it "should present Rational object with arbitrary precision" do rat = Rational(201020102010201020102010201020102010, 2) 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" - expect(out).to eq("100510051005100510051005100510051005") - else - expect(out).to eq("100510051005100510051005100510051005/1") - end + expect(out).to eq("100510051005100510051005100510051005/1") end end @@ -523,38 +506,20 @@ EOS expect(Set.new.ai).to eq([].ai) end - if RUBY_VERSION > "1.9" - it "plain multiline" do - expect(@set.ai(:plain => true)).to eq(@arr.ai(:plain => true)) - end + it "plain multiline" do + expect(@set.ai(:plain => true)).to eq(@arr.ai(:plain => true)) + end - it "plain multiline indented" do - expect(@set.ai(:plain => true, :indent => 1)).to eq(@arr.ai(:plain => true, :indent => 1)) - end + it "plain multiline indented" do + expect(@set.ai(:plain => true, :indent => 1)).to eq(@arr.ai(:plain => true, :indent => 1)) + end - it "plain single line" do - expect(@set.ai(:plain => true, :multiline => false)).to eq(@arr.ai(:plain => true, :multiline => false)) - end + it "plain single line" do + expect(@set.ai(:plain => true, :multiline => false)).to eq(@arr.ai(:plain => true, :multiline => false)) + end - it "colored multiline (default)" do - expect(@set.ai).to eq(@arr.ai) - end - else # Prior to Ruby 1.9 the order of set values is unpredicatble. - it "plain multiline" do - expect(@set.sort_by{ |x| x.to_s }.ai(:plain => true)).to eq(@arr.sort_by{ |x| x.to_s }.ai(:plain => true)) - end - - it "plain multiline indented" do - expect(@set.sort_by{ |x| x.to_s }.ai(:plain => true, :indent => 1)).to eq(@arr.sort_by{ |x| x.to_s }.ai(:plain => true, :indent => 1)) - end - - it "plain single line" do - expect(@set.sort_by{ |x| x.to_s }.ai(:plain => true, :multiline => false)).to eq(@arr.sort_by{ |x| x.to_s }.ai(:plain => true, :multiline => false)) - end - - it "colored multiline (default)" do - expect(@set.sort_by{ |x| x.to_s }.ai).to eq(@arr.sort_by{ |x| x.to_s }.ai) - end + it "colored multiline (default)" do + expect(@set.ai).to eq(@arr.ai) end end diff --git a/spec/methods_spec.rb b/spec/methods_spec.rb index 0ad25ab..8aa5524 100644 --- a/spec/methods_spec.rb +++ b/spec/methods_spec.rb @@ -72,11 +72,7 @@ RSpec.describe "Single method" do def world(a,b); end end method = Hello.instance_method(:world) - if RUBY_VERSION < '1.9.2' - expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(arg1, arg2)\e[0m") - else - expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m") - end + expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m") end end @@ -140,11 +136,7 @@ RSpec.describe "Object methods" do protected def m3(a,b); end end - if RUBY_VERSION < '1.9.2' - expect(Hello.new.protected_methods.ai(:plain => true, :index => false)).to eq("[\n m3(arg1, arg2) Hello\n]") - else - expect(Hello.new.protected_methods.ai(:plain => true, :index => false)).to eq("[\n m3(a, b) Hello\n]") - end + expect(Hello.new.protected_methods.ai(:plain => true, :index => false)).to eq("[\n m3(a, b) Hello\n]") end end @@ -167,11 +159,7 @@ RSpec.describe "Object methods" do def m3(a,b); end end out = Hello.new.private_methods.ai(:plain => true).split("\n").grep(/m\d/) - if RUBY_VERSION < '1.9.2' - expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(arg1, arg2\)\s+Hello$/) - else - expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(a, b\)\s+Hello$/) - end + expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(a, b\)\s+Hello$/) end end @@ -193,11 +181,7 @@ RSpec.describe "Object methods" do def self.m3(a,b); end end out = Hello.singleton_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/) - if RUBY_VERSION < '1.9.2' - expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello$/) - else - expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello$/) - end + expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello$/) end end end @@ -227,11 +211,7 @@ RSpec.describe "Class methods" do def m3(a,b); end end out = Hello.instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/) - if RUBY_VERSION < '1.9.2' - expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/) - else - expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) - end + expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) end end @@ -251,11 +231,7 @@ RSpec.describe "Class methods" do def m3(a,b); end end out = Hello.public_instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/) - if RUBY_VERSION < '1.9.2' - expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/) - else - expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) - end + expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) end end @@ -277,11 +253,7 @@ RSpec.describe "Class methods" do def m3(a,b); end end out = Hello.protected_instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/) - if RUBY_VERSION < '1.9.2' - expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/) - else - expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) - end + expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) end end @@ -303,64 +275,58 @@ RSpec.describe "Class methods" do def m3(a,b); end end out = Hello.private_instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/) - if RUBY_VERSION < '1.9.2' - expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/) - else - expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) - end + expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) end end end -if RUBY_VERSION >= '1.9.2' - RSpec.describe "Ruby 1.9.2+ Method#parameters" do - before do - stub_dotfile! - end +RSpec.describe "Ruby 1.9.2+ Method#parameters" do + before do + stub_dotfile! + end - after do - Object.instance_eval{ remove_const :Hello } if defined?(Hello) - end + after do + Object.instance_eval{ remove_const :Hello } if defined?(Hello) + end - it "()" do - class Hello - def m1; end - end - out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) - expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/) + it "()" do + class Hello + def m1; end end + out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) + expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/) + end - it ":req" do - class Hello - def m1(a, b, c); end - end - out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) - expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, b, c\)\s+Hello$/) + it ":req" do + class Hello + def m1(a, b, c); end end + out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) + expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, b, c\)\s+Hello$/) + end - it ":opt" do - class Hello - def m1(a, b = 1, c = 2); end # m1(a, *b, *c) - end - out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) - expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/) + it ":opt" do + class Hello + def m1(a, b = 1, c = 2); end # m1(a, *b, *c) end + out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) + expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/) + end - it ":rest" do - class Hello - def m1(*a); end # m1(*a) - end - out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) - expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/) + it ":rest" do + class Hello + def m1(*a); end # m1(*a) end + out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) + expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/) + end - it ":block" do - class Hello - def m1(a, b = nil, &blk); end # m1(a, *b, &blk) - end - out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) - expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, &blk\)\s+Hello$/) + it ":block" do + class Hello + def m1(a, b = nil, &blk); end # m1(a, *b, &blk) end + out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/) + expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, &blk\)\s+Hello$/) end end @@ -450,10 +416,6 @@ RSpec.describe "Methods arrays" do it "appending garbage to methods array should not raise error" do arr = 42.methods << [ :wtf ] expect { arr.ai(:plain => true) }.not_to raise_error - if RUBY_VERSION < '1.9.2' - expect(arr.ai(:plain => true)).to match(/\s+wtf\(\?\)\s+\?/) # [ :wtf ].to_s => "wtf" - else - expect(arr.ai(:plain => true)).to match(/\s+\[:wtf\]\(\?\)\s+\?/) # [ :wtf ].to_s => [:wtf] - end + expect(arr.ai(:plain => true)).to match(/\s+\[:wtf\]\(\?\)\s+\?/) # [ :wtf ].to_s => [:wtf] end end diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 21b50ce..d9db988 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -32,13 +32,10 @@ RSpec.describe "AwesomePrint" do expect(grepped.ai(:plain => true, :multiline => false)).to eq('[ "1", "2" ]') end - # See https://github.com/michaeldv/awesome_print/issues/85 - if RUBY_VERSION >= "1.8.7" - it "handle array grep when a method is defined in C and thus doesn't have a binding" do - arr = (0..6).to_a - grepped = arr.grep(1..4, &:succ) - expect(grepped.ai(:plain => true, :multiline => false)).to eq('[ 2, 3, 4, 5 ]') - end + it "handle array grep when a method is defined in C and thus doesn't have a binding" do + arr = (0..6).to_a + grepped = arr.grep(1..4, &:succ) + expect(grepped.ai(:plain => true, :multiline => false)).to eq('[ 2, 3, 4, 5 ]') end it "returns value passed as a parameter" do @@ -177,11 +174,7 @@ EOS it "shoud not raise ArgumentError when formatting HTML" do out = "hello".ai(:color => { :string => :red }, :html => true) - if RUBY_VERSION >= "1.9" - expect(out).to eq(%Q|
[red]"hello"[/red]
|) - else - expect(out).to eq(%Q|
[red]"hello"[/red]
|) - end + expect(out).to eq(%Q|
[red]"hello"[/red]
|) end it "shoud not raise ArgumentError when formatting HTML (shade color)" do