Skip to content

Commit f8d24e2

Browse files
committed
(maint) Add ability to unindent text blocks in spec-tests.
There are many times when indentation matters but yet, it's desirable to indent the actual definition of something in an indented fashion. Times when indentation matters is for instance when comparing output or when defining the content of a yaml file. This commit adds the method 'unindent' to the String class when running spec tests.
1 parent 5893637 commit f8d24e2

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

spec/lib/puppet_spec/unindent.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class String
2+
def unindent
3+
gsub(/^#{scan(/^\s*/).min_by{ |l| l.length }}/, '')
4+
end
5+
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module PuppetSpec
3333
require 'puppet_spec/settings'
3434
require 'puppet_spec/fixtures'
3535
require 'puppet_spec/matchers'
36+
require 'puppet_spec/unindent'
3637
require 'puppet/test/test_helper'
3738

3839
Pathname.glob("#{dir}/shared_contexts/*.rb") do |file|

0 commit comments

Comments
 (0)