summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-27 12:12:05 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-27 12:12:05 -0700
commitebf49f98357f93b33e09c0ecbdee1c5c2db87569 (patch)
tree8500c7f7c87ca5f32f22a70fde97b738c0427f54 /spec
parent1aaf5fdc51e165c7d0f377450016cd4fb3767c02 (diff)
parent0256d67e1a51a37f2c87ec197bdff6ef3a6b269f (diff)
downloadpuppet-ebf49f98357f93b33e09c0ecbdee1c5c2db87569.tar.gz
puppet-ebf49f98357f93b33e09c0ecbdee1c5c2db87569.tar.xz
puppet-ebf49f98357f93b33e09c0ecbdee1c5c2db87569.zip
Merge branch 'feature/2.7.x/6962-finish-documentation-api-for-faces' into 2.7.x
Diffstat (limited to 'spec')
-rwxr-xr-xspec/integration/faces/documentation_spec.rb55
-rwxr-xr-xspec/lib/puppet/face/basetest.rb2
-rwxr-xr-xspec/lib/puppet/face/huzzah.rb2
-rw-r--r--spec/lib/puppet/face/version_matching.rb2
-rw-r--r--spec/shared_behaviours/documentation_on_faces.rb222
-rwxr-xr-xspec/shared_behaviours/things_that_declare_options.rb2
-rwxr-xr-xspec/unit/interface/option_builder_spec.rb14
-rwxr-xr-xspec/unit/interface_spec.rb6
8 files changed, 278 insertions, 27 deletions
diff --git a/spec/integration/faces/documentation_spec.rb b/spec/integration/faces/documentation_spec.rb
new file mode 100755
index 000000000..9ddf2f1b3
--- /dev/null
+++ b/spec/integration/faces/documentation_spec.rb
@@ -0,0 +1,55 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+require 'puppet/face'
+
+describe "documentation of faces" do
+ it "should generate global help" do
+ help = nil
+ expect { help = Puppet::Face[:help, :current].help }.not_to raise_error
+ help.should be_an_instance_of String
+ help.length.should be > 200
+ end
+
+ ########################################################################
+ # Can we actually generate documentation for the face, and the actions it
+ # has? This avoids situations where the ERB template turns out to have a
+ # bug in it, triggered in something the user might do.
+ Puppet::Face.faces.sort.each do |face_name|
+ # REVISIT: We should walk all versions of the face here...
+ let :help do Puppet::Face[:help, :current] end
+
+ context "generating help" do
+ it "for #{face_name}" do
+ expect {
+ text = help.help(face_name)
+ text.should be_an_instance_of String
+ text.length.should be > 100
+ }.not_to raise_error
+ end
+
+ Puppet::Face[face_name, :current].actions.sort.each do |action_name|
+ it "for #{face_name}.#{action_name}" do
+ expect {
+ text = help.help(face_name, action_name)
+ text.should be_an_instance_of String
+ text.length.should be > 100
+ }.not_to raise_error
+ end
+ end
+ end
+
+ ########################################################################
+ # Ensure that we have authorship and copyright information in *our* faces;
+ # if you apply this to third party faces you might well be disappointed.
+ context "licensing of Puppet Labs face '#{face_name}'" do
+ subject { Puppet::Face[face_name, :current] }
+ its :license do should =~ /Apache\s*2/ end
+ its :copyright do should =~ /Puppet Labs/ end
+
+ # REVISIT: This is less that ideal, I think, but right now I am more
+ # comfortable watching us ship with some copyright than without any; we
+ # can redress that when it becomes appropriate. --daniel 2011-04-27
+ its :copyright do should =~ /2011/ end
+ end
+ end
+end
diff --git a/spec/lib/puppet/face/basetest.rb b/spec/lib/puppet/face/basetest.rb
index a98bc382f..41a4ef3f9 100755
--- a/spec/lib/puppet/face/basetest.rb
+++ b/spec/lib/puppet/face/basetest.rb
@@ -1,6 +1,8 @@
require 'puppet/face'
Puppet::Face.define(:basetest, '0.0.1') do
+ copyright "Puppet Labs", 2011
+ license "Apache 2 license; see COPYING"
summary "This is just so tests don't fail"
option "--[no-]boolean"
diff --git a/spec/lib/puppet/face/huzzah.rb b/spec/lib/puppet/face/huzzah.rb
index 3428c6816..2c2b7aa8d 100755
--- a/spec/lib/puppet/face/huzzah.rb
+++ b/spec/lib/puppet/face/huzzah.rb
@@ -1,5 +1,7 @@
require 'puppet/face'
Puppet::Face.define(:huzzah, '2.0.1') do
+ copyright "Puppet Labs", 2011
+ license "Apache 2 license; see COPYING"
summary "life is a thing for celebration"
action :bar do "is where beer comes from" end
end
diff --git a/spec/lib/puppet/face/version_matching.rb b/spec/lib/puppet/face/version_matching.rb
index bfd0013f7..52bc71dbd 100644
--- a/spec/lib/puppet/face/version_matching.rb
+++ b/spec/lib/puppet/face/version_matching.rb
@@ -4,6 +4,8 @@ require 'puppet/face'
# change this you need to ensure that is still correct. --daniel 2011-04-21
['1.0.0', '1.0.1', '1.1.0', '1.1.1', '2.0.0'].each do |version|
Puppet::Face.define(:version_matching, version) do
+ copyright "Puppet Labs", 2011
+ license "Apache 2 license; see COPYING"
summary "version matching face #{version}"
script :version do version end
end
diff --git a/spec/shared_behaviours/documentation_on_faces.rb b/spec/shared_behaviours/documentation_on_faces.rb
index 41b4015c9..dd2bd3110 100644
--- a/spec/shared_behaviours/documentation_on_faces.rb
+++ b/spec/shared_behaviours/documentation_on_faces.rb
@@ -1,34 +1,216 @@
# encoding: UTF-8
shared_examples_for "documentation on faces" do
- context "description" do
- describe "#summary" do
- it "should accept a summary" do
- text = "this is my summary"
- expect { subject.summary = text }.to_not raise_error
- subject.summary.should == text
+ defined?(Attrs) or
+ Attrs = [:summary, :description, :examples, :short_description, :notes, :author]
+
+ defined?(SingleLineAttrs) or
+ SingleLineAttrs = [:summary, :author]
+
+ # Simple, procedural tests that apply to a bunch of methods.
+ Attrs.each do |attr|
+ it "should accept a #{attr}" do
+ expect { subject.send("#{attr}=", "hello") }.not_to raise_error
+ subject.send(attr).should == "hello"
+ end
+
+ it "should accept a long (single line) value for #{attr}" do
+ text = "I never know when to stop with the word banana" + ("na" * 1000)
+ expect { subject.send("#{attr}=", text) }.to_not raise_error
+ subject.send(attr).should == text
+ 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
+ end
+ end
+ end
+
+ describe "#short_description" do
+ it "should return the set value if set after description" do
+ subject.description = "hello\ngoodbye"
+ subject.short_description = "whatever"
+ subject.short_description.should == "whatever"
+ end
+
+ it "should return the set value if set before description" do
+ subject.short_description = "whatever"
+ subject.description = "hello\ngoodbye"
+ subject.short_description.should == "whatever"
+ end
+
+ it "should return nothing if not set and no description" do
+ subject.short_description.should be_nil
+ end
+
+ it "should return the first paragraph of description if not set (where it is one line long)" do
+ subject.description = "hello"
+ subject.short_description.should == subject.description
+ end
+
+ it "should return the first paragraph of description if not set (where there is no paragraph break)" do
+ subject.description = "hello\ngoodbye"
+ subject.short_description.should == subject.description
+ end
+
+ it "should return the first paragraph of description if not set (where there is a paragraph break)" do
+ subject.description = "hello\ngoodbye\n\nmore\ntext\nhere\n\nfinal\nparagraph"
+ subject.short_description.should == "hello\ngoodbye"
+ end
+
+ it "should trim a very, very long first paragraph" do
+ line = "this is a very, very, very long long line full of text\n"
+ subject.description = line * 20 + "\n\nwhatever, dude."
+
+ subject.short_description.should == (line * 5).chomp
+ end
+ end
+
+ describe "multiple authors" do
+ authors = %w{John Paul George Ringo}
+
+ context "in the DSL" do
+ it "should support multiple authors" do
+
+ authors.each {|name| subject.author name }
+ subject.authors.should =~ authors
+
+ subject.author.should == authors.join("\n")
+ end
+
+ it "should reject author as an array" do
+ expect { subject.author ["Foo", "Bar"] }.
+ to raise_error ArgumentError, /author must be a string/
+ end
+ end
+
+ context "#author=" do
+ it "should accept a single name" do
+ subject.author = "Fred"
+ subject.author.should == "Fred"
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 }.to_not raise_error
- subject.summary.should == text
+ it "should accept an array of names" do
+ subject.author = authors
+ subject.authors.should =~ authors
+ subject.author.should == authors.join("\n")
+ end
+
+ it "should not append when set multiple times" do
+ subject.author = "Fred"
+ subject.author = "John"
+ subject.author.should == "John"
+ end
+
+ it "should reject arrays with embedded newlines" do
+ expect { subject.author = ["Fred\nJohn"] }.
+ to raise_error ArgumentError, /author should be a single line/
+ end
+ end
+ end
+
+ describe "#license" do
+ it "should default to reserving rights" do
+ subject.license.should =~ /All Rights Reserved/
+ end
+
+ it "should accept an arbitrary license string on the object" do
+ subject.license = "foo"
+ subject.license.should == "foo"
+ end
+
+ it "should accept symbols to specify existing licenses..."
+ end
+
+ describe "#copyright" do
+ it "should fail with just a name" do
+ expect { subject.copyright("invalid") }.
+ to raise_error ArgumentError, /copyright takes the owners names, then the years covered/
+ end
+
+ [1997, "1997"].each do |year|
+ it "should accept an entity name and a #{year.class.name} year" do
+ subject.copyright("me", year)
+ subject.copyright.should =~ /\bme\b/
+ subject.copyright.should =~ /#{year}/
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/
+ it "should accept multiple entity names and a #{year.class.name} year" do
+ subject.copyright ["me", "you"], year
+ subject.copyright.should =~ /\bme\b/
+ subject.copyright.should =~ /\byou\b/
+ subject.copyright.should =~ /#{year}/
end
end
- describe "#description" do
- it "should accept a description" do
- subject.description = "hello"
- subject.description.should == "hello"
+ ["1997-2003", "1997 - 2003", 1997..2003].each do |range|
+ it "should accept a #{range.class.name} range of years" do
+ subject.copyright("me", range)
+ subject.copyright.should =~ /\bme\b/
+ subject.copyright.should =~ /1997-2003/
+ end
+
+ it "should accept a #{range.class.name} range of years" do
+ subject.copyright ["me", "you"], range
+ subject.copyright.should =~ /\bme\b/
+ subject.copyright.should =~ /\byou\b/
+ subject.copyright.should =~ /1997-2003/
+ end
+ end
+
+ [[1997, 2003], ["1997", 2003], ["1997", "2003"]].each do |input|
+ it "should accept the set of years #{input.inspect} in an array" do
+ subject.copyright "me", input
+ subject.copyright.should =~ /\bme\b/
+ subject.copyright.should =~ /1997, 2003/
+ end
+
+ it "should accept the set of years #{input.inspect} in an array" do
+ subject.copyright ["me", "you"], input
+ subject.copyright.should =~ /\bme\b/
+ subject.copyright.should =~ /\byou\b/
+ subject.copyright.should =~ /1997, 2003/
+ end
+ end
+
+ it "should warn if someone does math accidentally on the range of years" do
+ expect { subject.copyright "me", 1997-2003 }.
+ to raise_error ArgumentError, /copyright with a year before 1970 is very strange; did you accidentally add or subtract two years\?/
+ end
+
+ it "should accept complex copyright years" do
+ years = [1997, 1999, 2000..2002, 2005].reverse
+ subject.copyright "me", years
+ subject.copyright.should =~ /\bme\b/
+ subject.copyright.should =~ /1997, 1999, 2000-2002, 2005/
+ end
+ end
+
+ # Things that are automatically generated.
+ [:name, :options, :synopsis].each do |attr|
+ describe "##{attr}" do
+ it "should not allow you to set #{attr}" do
+ subject.should_not respond_to :"#{attr}="
+ end
+
+ it "should have a #{attr}" do
+ subject.send(attr).should_not be_nil
end
- it "should accept a description with a newline" do
- subject.description = "hello \n my \n fine \n friend"
- subject.description.should == "hello \n my \n fine \n friend"
+ it "'s #{attr} should not be empty..." do
+ subject.send(attr).should_not == ''
end
end
end
diff --git a/spec/shared_behaviours/things_that_declare_options.rb b/spec/shared_behaviours/things_that_declare_options.rb
index 5300a159a..3d33bab7f 100755
--- a/spec/shared_behaviours/things_that_declare_options.rb
+++ b/spec/shared_behaviours/things_that_declare_options.rb
@@ -28,6 +28,8 @@ shared_examples_for "things that declare options" do
thing = add_options_to do
option "--foo" do
desc text
+ description text
+ summary text
end
end
diff --git a/spec/unit/interface/option_builder_spec.rb b/spec/unit/interface/option_builder_spec.rb
index e9346852c..3e91c683b 100755
--- a/spec/unit/interface/option_builder_spec.rb
+++ b/spec/unit/interface/option_builder_spec.rb
@@ -16,13 +16,15 @@ describe Puppet::Interface::OptionBuilder do
option.should be_an_instance_of Puppet::Interface::Option
end
- it "should support documentation declarations" do
- text = "this is the description"
- option = Puppet::Interface::OptionBuilder.build(face, "--foo") do
- desc text
+ [:description, :summary].each do |doc|
+ it "should support #{doc} declarations" do
+ text = "this is the #{doc}"
+ option = Puppet::Interface::OptionBuilder.build(face, "--foo") do
+ self.send doc, text
+ end
+ option.should be_an_instance_of Puppet::Interface::Option
+ option.send(doc).should == text
end
- option.should be_an_instance_of Puppet::Interface::Option
- option.desc.should == text
end
context "before_action hook" do
diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb
index a1d70cf64..27da39766 100755
--- a/spec/unit/interface_spec.rb
+++ b/spec/unit/interface_spec.rb
@@ -76,7 +76,11 @@ describe Puppet::Interface do
# Required documentation methods...
{ :summary => "summary",
- :description => "This is the description of the stuff\n\nWhee"
+ :description => "This is the description of the stuff\n\nWhee",
+ :examples => "This is my example",
+ :short_description => "This is my custom short description",
+ :notes => "These are my notes...",
+ :author => "This is my authorship data",
}.each do |attr, value|
it "should support #{attr} in the builder" do
face = subject.new(:builder, '1.0.0') do