mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
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.
This commit is contained in:
parent
d8aeb66b4b
commit
7e6e7c01aa
4 changed files with 69 additions and 167 deletions
|
@ -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
|
||||
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
|
||||
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
|
||||
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
|
||||
else
|
||||
expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
||||
end
|
||||
|
|
|
@ -361,13 +361,6 @@ 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
|
||||
{
|
||||
"b" => "b",
|
||||
|
@ -377,7 +370,6 @@ EOS
|
|||
}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
it "plain multiline with sorted keys" do
|
||||
expect(@hash.ai(:plain => true, :sort_keys => true)).to eq <<-EOS.strip
|
||||
|
@ -488,18 +480,9 @@ 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
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Utility methods" do
|
||||
|
@ -523,7 +506,6 @@ 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
|
||||
|
@ -539,23 +521,6 @@ EOS
|
|||
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
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
|
|
@ -72,12 +72,8 @@ 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
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.describe "Object methods" do
|
||||
|
@ -140,13 +136,9 @@ 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
|
||||
end
|
||||
end
|
||||
|
||||
describe "object.private_methods" do
|
||||
it "index: should handle object.private_methods" do
|
||||
|
@ -167,13 +159,9 @@ 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
|
||||
end
|
||||
end
|
||||
|
||||
describe "object.singleton_methods" do
|
||||
it "index: should handle object.singleton_methods" do
|
||||
|
@ -193,13 +181,9 @@ 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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.describe "Class methods" do
|
||||
|
@ -227,13 +211,9 @@ 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
|
||||
end
|
||||
end
|
||||
|
||||
describe "class.public_instance_methods" do
|
||||
it "index: should handle class.public_instance_methods" do
|
||||
|
@ -251,13 +231,9 @@ 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
|
||||
end
|
||||
end
|
||||
|
||||
describe "class.protected_instance_methods" do
|
||||
it "index: should handle class.protected_instance_methods" do
|
||||
|
@ -277,13 +253,9 @@ 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
|
||||
end
|
||||
end
|
||||
|
||||
describe "class.private_instance_methods" do
|
||||
it "index: should handle class.private_instance_methods" do
|
||||
|
@ -303,17 +275,12 @@ 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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if RUBY_VERSION >= '1.9.2'
|
||||
RSpec.describe "Ruby 1.9.2+ Method#parameters" do
|
||||
RSpec.describe "Ruby 1.9.2+ Method#parameters" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
@ -361,7 +328,6 @@ if RUBY_VERSION >= '1.9.2'
|
|||
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
|
||||
end
|
||||
|
||||
RSpec.describe "Methods arrays" do
|
||||
|
@ -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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,14 +32,11 @@ 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
|
||||
end
|
||||
|
||||
it "returns value passed as a parameter" do
|
||||
object = rand
|
||||
|
@ -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|<pre>[red]<kbd style="color:red">"hello"</kbd>[/red]</pre>|)
|
||||
else
|
||||
expect(out).to eq(%Q|<pre>[red]"hello"[/red]</pre>|)
|
||||
end
|
||||
end
|
||||
|
||||
it "shoud not raise ArgumentError when formatting HTML (shade color)" do
|
||||
|
|
Loading…
Reference in a new issue