[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Daniel Pittman
daniel at puppetlabs.com
Tue May 10 08:16:27 UTC 2011
The following commit has been merged in the experimental branch:
commit 32c667c79bc0d5151580ea79719f28739945bfb1
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Sun Apr 17 18:51:09 2011 -0700
(#7132) Reject 'summary' text with newlines embedded.
Our summary documentation is used to provide single-line context to faces,
actions, and other items. To support this we hard-fail if someone tries to
use the summary to embed the long documentation, and point them to the right
place to add the extended text.
Reviewed-By: Max Martin <max at puppetlabs.com>
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 5e93550..4a36b50 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -70,9 +70,16 @@ class Puppet::Interface
attr_accessor :summary
def summary(value = nil)
- @summary = value unless value.nil?
+ value.nil? or summary = value
@summary
end
+ def summary=(value)
+ value = value.to_s
+ value =~ /\n/ and
+ raise ArgumentError, "Face summary should be a single line; put the long text in 'description' instead."
+
+ @summary = value
+ end
attr_reader :name, :version
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index b942989..d2d4fac 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -24,8 +24,21 @@ class Puppet::Interface::Action
attr_reader :name
def to_s() "#{@face}##{@name}" end
- attr_accessor :default, :summary
+ attr_accessor :default
+ ########################################################################
+ # Documentation stuff, whee!
+ attr_accessor :summary
+ def summary=(value)
+ value = value.to_s
+ value =~ /\n/ and
+ raise ArgumentError, "Face summary should be a single line; put the long text in 'description' instead."
+
+ @summary = value
+ end
+
+
+ ########################################################################
# Initially, this was defined to allow the @action.invoke pattern, which is
# a very natural way to invoke behaviour given our introspection
# capabilities. Heck, our initial plan was to have the faces delegate to
diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb
index 4be6a1c..602e513 100755
--- a/spec/unit/interface/action_spec.rb
+++ b/spec/unit/interface/action_spec.rb
@@ -348,4 +348,32 @@ describe Puppet::Interface::Action do
end
end
end
+
+ context "documentation" do
+ subject do
+ face = Puppet::Interface.new(:action_documentation, '0.0.1') do
+ action :documentation do end
+ end
+ face.get_action(:documentation)
+ end
+
+ describe "#summary" do
+ it "should accept a summary" do
+ text = "this is my summary"
+ expect { subject.summary = text }.not_to raise_error
+ subject.summary.should == text
+ end
+
+ it "should accept a long, long, long summary" do
+ text = "I never know when to stop with the word banana" + ("na" * 1000)
+ expect { subject.summary = text }.not_to raise_error
+ subject.summary.should == text
+ end
+
+ it "should reject a summary with a newline" do
+ expect { subject.summary = "with\nnewlines" }.
+ to raise_error ArgumentError, /summary should be a single line/
+ end
+ end
+ end
end
diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb
index e52b45d..036372e 100755
--- a/spec/unit/interface_spec.rb
+++ b/spec/unit/interface_spec.rb
@@ -50,24 +50,6 @@ describe Puppet::Interface do
subject.new(:foo, '1.0.0').should respond_to(:summary).with(0).arguments
subject.new(:foo, '1.0.0').should respond_to(:summary=).with(1).arguments
end
-
- it "should set the summary text" do
- text = "hello, freddy, my little pal"
- subject.define(:face_test_summary, '1.0.0') do
- summary text
- end
- subject[:face_test_summary, '1.0.0'].summary.should == text
- end
-
- it "should support mutating the summary" do
- text = "hello, freddy, my little pal"
- subject.define(:face_test_summary, '1.0.0') do
- summary text
- end
- subject[:face_test_summary, '1.0.0'].summary.should == text
- subject[:face_test_summary, '1.0.0'].summary = text + text
- subject[:face_test_summary, '1.0.0'].summary.should == text + text
- end
end
describe "#initialize" do
@@ -204,4 +186,29 @@ describe Puppet::Interface do
end
end
end
+
+ context "documentation" do
+ subject do
+ Puppet::Interface.new(:face_documentation, '0.0.1')
+ end
+
+ describe "#summary" do
+ it "should accept a summary" do
+ text = "this is my summary"
+ expect { subject.summary = text }.not_to raise_error
+ subject.summary.should == text
+ end
+
+ it "should accept a long, long, long summary" do
+ text = "I never know when to stop with the word banana" + ("na" * 1000)
+ expect { subject.summary = text }.not_to raise_error
+ subject.summary.should == text
+ end
+
+ it "should reject a summary with a newline" do
+ expect { subject.summary = "with \n embedded \n newlines" }.
+ to raise_error ArgumentError, /summary should be a single line/
+ end
+ end
+ end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list