let String#strip_heredoc handle blank lines even if they are not indented
This commit is contained in:
parent
58d0e2c23c
commit
b422cda2eb
|
@ -1,3 +1,5 @@
|
|||
require 'active_support/core_ext/object/try'
|
||||
|
||||
class String
|
||||
# Strips indentation in heredocs.
|
||||
#
|
||||
|
@ -18,7 +20,7 @@ class String
|
|||
# Technically, it looks for the least indented line in the whole string, and removes
|
||||
# that amount of leading whitespace.
|
||||
def strip_heredoc
|
||||
indent = chomp.scan(/^\s*/).min.size
|
||||
gsub(/^\s{#{indent}}/, '')
|
||||
indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0
|
||||
gsub(/^[ \t]{#{indent}}/, '')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,6 +33,15 @@ class StringInflectionsTest < Test::Unit::TestCase
|
|||
EOS
|
||||
end
|
||||
|
||||
def test_strip_heredoc_on_a_regular_indented_heredoc_with_blank_lines
|
||||
assert_equal "foo\n bar\n\nbaz\n", <<-EOS.strip_heredoc
|
||||
foo
|
||||
bar
|
||||
|
||||
baz
|
||||
EOS
|
||||
end
|
||||
|
||||
def test_pluralize
|
||||
SingularToPlural.each do |singular, plural|
|
||||
assert_equal(plural, singular.pluralize)
|
||||
|
|
Loading…
Reference in New Issue