diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-29 15:19:24 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-29 15:37:07 -0700 |
| commit | 65b9a3c4f4e6830ed094d46381050dfa72c7eccd (patch) | |
| tree | e7ec3a468bdcb5042a52fb8f997be52a3b9d81c2 /spec | |
| parent | 97ae812f0a67ef01daed4e9220981e2bc7c70603 (diff) | |
| download | puppet-65b9a3c4f4e6830ed094d46381050dfa72c7eccd.tar.gz puppet-65b9a3c4f4e6830ed094d46381050dfa72c7eccd.tar.xz puppet-65b9a3c4f4e6830ed094d46381050dfa72c7eccd.zip | |
(#7221) Strip bad whitespace from face and action docs.
We now strip whitespace in face (and related) documentation in two places:
We strip any trailing whitespace on each line, just because.
We strip any leading indent, but not all leading whitespace, from the text.
That is, we strip the *minimum* amount of whitespace that we can take from
every line in the documentation without changing the overall content.
Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/shared_behaviours/documentation_on_faces.rb | 67 |
1 files changed, 53 insertions, 14 deletions
diff --git a/spec/shared_behaviours/documentation_on_faces.rb b/spec/shared_behaviours/documentation_on_faces.rb index dd2bd3110..3cfb178f7 100644 --- a/spec/shared_behaviours/documentation_on_faces.rb +++ b/spec/shared_behaviours/documentation_on_faces.rb @@ -20,20 +20,59 @@ shared_examples_for "documentation on faces" do end end - # Should they accept multiple lines? - Attrs.each do |attr| - text = "with\nnewlines" - - if SingleLineAttrs.include? attr then - it "should not accept multiline values for #{attr}" do - expect { subject.send("#{attr}=", text) }. - to raise_error ArgumentError, /#{attr} should be a single line/ - subject.send(attr).should be_nil - end - else - it "should accept multiline values for #{attr}" do - expect { subject.send("#{attr}=", text) }.not_to raise_error - subject.send(attr).should == text + Attrs.each do |getter| + setter = "#{getter}=".to_sym + context "#{getter}" do + it "should strip leading whitespace on a single line" do + subject.send(setter, " death to whitespace") + subject.send(getter).should == "death to whitespace" + end + + it "should strip trailing whitespace on a single line" do + subject.send(setter, "death to whitespace ") + subject.send(getter).should == "death to whitespace" + end + + it "should strip whitespace at both ends at once" do + subject.send(setter, " death to whitespace ") + subject.send(getter).should == "death to whitespace" + end + + multiline_text = "with\nnewlines" + if SingleLineAttrs.include? getter then + it "should not accept multiline values" do + expect { subject.send(setter, multiline_text) }. + to raise_error ArgumentError, /#{getter} should be a single line/ + subject.send(getter).should be_nil + end + else + it "should accept multiline values" do + expect { subject.send(setter, multiline_text) }.not_to raise_error + subject.send(getter).should == multiline_text + end + + [1, 2, 4, 7, 25].each do |length| + context "#{length} chars indent" do + indent = ' ' * length + + it "should strip leading whitespace on multiple lines" do + text = "this\nis\the\final\outcome" + subject.send(setter, text.gsub(/^/, indent)) + subject.send(getter).should == text + end + + it "should not remove formatting whitespace, only global indent" do + text = "this\n is\n the\n ultimate\ntest\n" + subject.send(setter, text.gsub(/^/, indent)) + subject.send(getter).should == text + end + end + end + + it "should strip whitespace with a blank line" do + subject.send(setter, " this\n\n should outdent\n") + subject.send(getter).should == "this\n\nshould outdent\n" + end end end end |
