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

Add missing String methods to make all specs pass with Ruby 1.8.6

This commit is contained in:
Mike Dvorkin 2011-05-13 13:22:01 -07:00
parent a861908fb7
commit 62c07edea2

View file

@ -17,6 +17,35 @@ def stub_dotfile!
File.should_receive(:readable?).at_least(:once).with(dotfile).and_return(false)
end
# Infinity Test runs tests as subprocesses, which sets STDOUT.tty? to false and
# would otherwise prematurely disallow colors. We'll test the defaults later.
# The following is needed for the Infinity Test. It runs tests as subprocesses,
# which sets STDOUT.tty? to false and would otherwise prematurely disallow colors.
AwesomePrint.force_colors!
# Ruby 1.8.6 only: define missing String methods that are needed for the specs to pass.
if RUBY_VERSION < '1.8.7'
class String
def shellescape # Taken from Ruby 1.9.2 standard library, see lib/shellwords.rb.
return "''" if self.empty?
str = self.dup
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
str.gsub!(/\n/, "'\n'")
str
end
def start_with?(*prefixes)
prefixes.each do |prefix|
prefix = prefix.to_s
return true if prefix == self[0, prefix.size]
end
false
end
def end_with?(*suffixes)
suffixes.each do |suffix|
suffix = suffix.to_s
return true if suffix == self[-suffix.size, suffix.size]
end
false
end
end
end