diff --git a/lib/puppet/faces/help.rb b/lib/puppet/faces/help.rb index e986d19b3..229a0dc81 100644 --- a/lib/puppet/faces/help.rb +++ b/lib/puppet/faces/help.rb @@ -1,52 +1,52 @@ require 'puppet/faces' Puppet::Faces.define(:help, '0.0.1') do summary "Displays help about puppet subcommands" action(:help) do option "--version VERSION" do desc "Which version of the interface to show help for" end when_invoked do |*args| # Check our invocation, because we want varargs and can't do defaults # yet. REVISIT: when we do option defaults, and positional options, we # should rewrite this to use those. --daniel 2011-04-04 options = args.pop if options.nil? or args.length > 2 then raise ArgumentError, "help only takes two (optional) arguments, a face name, and an action" end if options[:version] and options[:version] !~ /^current$/i then version = options[:version] else version = :current end message = [] if args.length == 0 then message << "Use: puppet [options] " message << "" - message << "Available commands, from Puppet Faces:" + message << "Available subcommands, from Puppet Faces:" Puppet::Faces.faces.sort.each do |name| face = Puppet::Faces[name, :current] - message << format(" %-15s %s", face.name, 'REVISIT: face.desc') + message << format(" %-15s %s", face.name, face.summary) end else face = Puppet::Faces[args[0].to_sym, version] if args[1] then action = face.get_action args[1].to_sym else action = nil end help = [] face.actions.each do |action| help << "Action: #{action}" end end message end end end diff --git a/spec/lib/puppet/faces/huzzah.rb b/spec/lib/puppet/faces/huzzah.rb index 735004475..e86730250 100644 --- a/spec/lib/puppet/faces/huzzah.rb +++ b/spec/lib/puppet/faces/huzzah.rb @@ -1,4 +1,5 @@ require 'puppet/faces' Puppet::Faces.define(:huzzah, '2.0.1') do + summary "life is a thing for celebration" action :bar do "is where beer comes from" end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d28cb2504..1187c1caf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,67 +1,74 @@ dir = File.expand_path(File.dirname(__FILE__)) $LOAD_PATH.unshift File.join(dir, 'lib') # Don't want puppet getting the command line arguments for rake or autotest ARGV.clear require 'puppet' require 'mocha' gem 'rspec', '>=2.0.0' +require 'rspec/expectations' # So everyone else doesn't have to include this base constant. module PuppetSpec FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR) end require 'pathname' require 'tmpdir' require 'lib/puppet_spec/verbose' require 'lib/puppet_spec/files' require 'lib/puppet_spec/fixtures' require 'monkey_patches/alias_should_to_must' require 'monkey_patches/publicize_methods' Pathname.glob("#{dir}/shared_behaviours/**/*.rb") do |behaviour| require behaviour.relative_path_from(Pathname.new(dir)) end RSpec.configure do |config| include PuppetSpec::Fixtures config.mock_with :mocha config.before :each do GC.disable # these globals are set by Application $puppet_application_mode = nil $puppet_application_name = nil Signal.stubs(:trap) # Set the confdir and vardir to gibberish so that tests # have to be correctly mocked. Puppet[:confdir] = "/dev/null" Puppet[:vardir] = "/dev/null" # Avoid opening ports to the outside world Puppet.settings[:bindaddress] = "127.0.0.1" @logs = [] Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs)) end config.after :each do Puppet.settings.clear Puppet::Node::Environment.clear Puppet::Util::Storage.clear Puppet::Util::ExecutionStub.reset PuppetSpec::Files.cleanup @logs.clear Puppet::Util::Log.close_all GC.enable end end + +RSpec::Matchers.define :have_matching_element do |expected| + match do |actual| + actual.any? { |item| item =~ expected } + end +end diff --git a/spec/unit/faces/help_spec.rb b/spec/unit/faces/help_spec.rb index 5b611a0ad..ad553dc3a 100644 --- a/spec/unit/faces/help_spec.rb +++ b/spec/unit/faces/help_spec.rb @@ -1,44 +1,65 @@ require 'spec_helper' require 'puppet/faces/help' describe Puppet::Faces[:help, '0.0.1'] do it "should have a help action" do subject.should be_action :help end it "should have a default action of help" do pending "REVISIT: we don't support default actions yet" end it "should accept a call with no arguments" do expect { subject.help() }.should_not raise_error end it "should accept a face name" do expect { subject.help(:help) }.should_not raise_error end it "should accept a face and action name" do expect { subject.help(:help, :help) }.should_not raise_error end it "should fail if more than a face and action are given" do expect { subject.help(:help, :help, :for_the_love_of_god) }. should raise_error ArgumentError end it "should treat :current and 'current' identically" do subject.help(:help, :current).should == subject.help(:help, 'current') end it "should complain when the request version of a face is missing" do expect { subject.help(:huzzah, :bar, :version => '17.0.0') }. should raise_error Puppet::Error end it "should find a face by version" do face = Puppet::Faces[:huzzah, :current] subject.help(:huzzah, face.version).should == subject.help(:huzzah, :current) end + + context "when listing subcommands" do + subject { Puppet::Faces[:help, :current].help } + + # Check a precondition for the next block; if this fails you have + # something odd in your set of faces, and we skip testing things that + # matter. --daniel 2011-04-10 + it "should have at least one face with a summary" do + Puppet::Faces.faces.should be_any do |name| + Puppet::Faces[name, :current].summary + end + end + + Puppet::Faces.faces.each do |name| + face = Puppet::Faces[name, :current] + summary = face.summary + + it { should have_matching_element %r{ #{name} } } + it { should have_matching_element %r{ #{name} +#{summary}} } if summary + end + end end