From 65b9a3c4f4e6830ed094d46381050dfa72c7eccd Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Fri, 29 Apr 2011 15:19:24 -0700 Subject: (#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 --- spec/shared_behaviours/documentation_on_faces.rb | 67 +++++++++++++++++++----- 1 file changed, 53 insertions(+), 14 deletions(-) (limited to 'spec') 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 -- cgit