diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-07 15:53:17 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-07 15:53:17 -0700 |
| commit | a35fa519c85a761ac8bed3be8fde2d6523cae474 (patch) | |
| tree | 36f3583ee364ba1d68467a2b614a8dfcf9ed43ae /spec/unit | |
| parent | 3d5ec4f61fee08552767e950ac021752c202a599 (diff) | |
| parent | 87ed3188e65d3f5f9c2c32a409b271d1b39684b9 (diff) | |
Merge branch 'refactor/master/7012-rename-strings-to-interfaces-and-faces'
Diffstat (limited to 'spec/unit')
37 files changed, 374 insertions, 399 deletions
diff --git a/spec/unit/application/certificate_spec.rb b/spec/unit/application/certificate_spec.rb index 3d2215ded..6153d9538 100755 --- a/spec/unit/application/certificate_spec.rb +++ b/spec/unit/application/certificate_spec.rb @@ -1,12 +1,9 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/application/certificate' describe Puppet::Application::Certificate do it "should have a 'ca-location' option" do - # REVISIT: This is delegated from the string, and we will have a test - # there, so is this actually a valuable test? + # REVISIT: This is delegated from the face, and we will have a test there, + # so is this actually a valuable test? --daniel 2011-04-07 subject.command_line.stubs(:args).returns %w{list} subject.preinit subject.should respond_to(:handle_ca_location) diff --git a/spec/unit/application/config_spec.rb b/spec/unit/application/config_spec.rb index a45adc8d3..066df6a51 100755 --- a/spec/unit/application/config_spec.rb +++ b/spec/unit/application/config_spec.rb @@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/application/config' describe Puppet::Application::Config do - it "should be a subclass of Puppet::Application::StringBase" do - Puppet::Application::Config.superclass.should equal(Puppet::Application::StringBase) + it "should be a subclass of Puppet::Application::FacesBase" do + Puppet::Application::Config.superclass.should equal(Puppet::Application::FacesBase) end end diff --git a/spec/unit/application/string_base_spec.rb b/spec/unit/application/faces_base_spec.rb index 3f8ae73b6..6d8815f44 100755 --- a/spec/unit/application/string_base_spec.rb +++ b/spec/unit/application/faces_base_spec.rb @@ -1,22 +1,22 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/application/string_base' +require 'puppet/application/faces_base' require 'tmpdir' -class Puppet::Application::StringBase::Basetest < Puppet::Application::StringBase +class Puppet::Application::FacesBase::Basetest < Puppet::Application::FacesBase end -describe Puppet::Application::StringBase do +describe Puppet::Application::FacesBase do before :all do @dir = Dir.mktmpdir $LOAD_PATH.push(@dir) - FileUtils.mkdir_p(File.join @dir, 'puppet', 'string') - File.open(File.join(@dir, 'puppet', 'string', 'basetest.rb'), 'w') do |f| - f.puts "Puppet::String.define(:basetest, '0.0.1')" + FileUtils.mkdir_p(File.join @dir, 'puppet', 'faces') + File.open(File.join(@dir, 'puppet', 'faces', 'basetest.rb'), 'w') do |f| + f.puts "Puppet::Faces.define(:basetest, '0.0.1')" end - Puppet::String.define(:basetest, '0.0.1') do + Puppet::Faces.define(:basetest, '0.0.1') do option("--[no-]boolean") option("--mandatory MANDATORY") option("--optional [OPTIONAL]") @@ -34,7 +34,7 @@ describe Puppet::Application::StringBase do end let :app do - app = Puppet::Application::StringBase::Basetest.new + app = Puppet::Application::FacesBase::Basetest.new app.stubs(:exit) app.stubs(:puts) app.command_line.stubs(:subcommand_name).returns 'subcommand' @@ -63,11 +63,11 @@ describe Puppet::Application::StringBase do app.preinit end - it "should set the string based on the type" do - app.string.name.should == :basetest + it "should set the faces based on the type" do + app.face.name.should == :basetest end - it "should set the format based on the string default" do + it "should set the format based on the faces default" do app.format.should == :pson end @@ -104,7 +104,7 @@ describe Puppet::Application::StringBase do app.command_line.stubs(:args).returns %w{foo --bar} app.preinit app.action.name.should == :foo - app.string.should_not be_option :bar + app.face.should_not be_option :bar app.action.should_not be_option :bar end @@ -166,14 +166,14 @@ describe Puppet::Application::StringBase do describe "#main" do before do - app.string = Puppet::String[:basetest, '0.0.1'] - app.action = app.string.get_action(:foo) + app.face = Puppet::Faces[:basetest, '0.0.1'] + app.action = app.face.get_action(:foo) app.format = :pson app.arguments = ["myname", "myarg"] end - it "should send the specified verb and name to the string" do - app.string.expects(:foo).with(*app.arguments) + it "should send the specified verb and name to the faces" do + app.face.expects(:foo).with(*app.arguments) app.main end diff --git a/spec/unit/application/faces_spec.rb b/spec/unit/application/faces_spec.rb new file mode 100755 index 000000000..d945c40b5 --- /dev/null +++ b/spec/unit/application/faces_spec.rb @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/application/faces' + +describe Puppet::Application::Faces do + it "should be an application" do + Puppet::Application::Faces.superclass.should equal(Puppet::Application) + end +end diff --git a/spec/unit/application/indirection_base_spec.rb b/spec/unit/application/indirection_base_spec.rb index 66b3009fb..a73cf4fca 100755 --- a/spec/unit/application/indirection_base_spec.rb +++ b/spec/unit/application/indirection_base_spec.rb @@ -2,19 +2,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/application/indirection_base' -require 'puppet/string/indirector' +require 'puppet/faces/indirector' ######################################################################## # Stub for testing; the names are critical, sadly. --daniel 2011-03-30 class Puppet::Application::TestIndirection < Puppet::Application::IndirectionBase end -string = Puppet::String::Indirector.define(:testindirection, '0.0.1') do +face = Puppet::Faces::Indirector.define(:testindirection, '0.0.1') do end # REVISIT: This horror is required because we don't allow anything to be # :current except for if it lives on, and is loaded from, disk. --daniel 2011-03-29 -string.version = :current -Puppet::String.register(string) +face.version = :current +Puppet::Faces.register(face) ######################################################################## diff --git a/spec/unit/application/string_spec.rb b/spec/unit/application/string_spec.rb deleted file mode 100755 index 13af0a546..000000000 --- a/spec/unit/application/string_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/application/string' - -describe Puppet::Application::String do - it "should be an application" do - Puppet::Application::String.superclass.should equal(Puppet::Application) - end -end diff --git a/spec/unit/faces/catalog_spec.rb b/spec/unit/faces/catalog_spec.rb new file mode 100755 index 000000000..71972194a --- /dev/null +++ b/spec/unit/faces/catalog_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Faces[:catalog, '0.0.1'] do + it "should actually have some testing..." +end diff --git a/spec/unit/faces/certificate_request_spec.rb b/spec/unit/faces/certificate_request_spec.rb new file mode 100755 index 000000000..1a71a8379 --- /dev/null +++ b/spec/unit/faces/certificate_request_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Faces[:certificate_request, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/faces/certificate_revocation_list_spec.rb b/spec/unit/faces/certificate_revocation_list_spec.rb new file mode 100755 index 000000000..4f41edef6 --- /dev/null +++ b/spec/unit/faces/certificate_revocation_list_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Faces[:certificate_revocation_list, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/string/certificate_spec.rb b/spec/unit/faces/certificate_spec.rb index 9fdc5aab8..ba264f967 100755 --- a/spec/unit/string/certificate_spec.rb +++ b/spec/unit/faces/certificate_spec.rb @@ -1,12 +1,12 @@ require 'puppet/ssl/host' -describe Puppet::String[:certificate, '0.0.1'] do +describe Puppet::Faces[:certificate, '0.0.1'] do it "should have a ca-location option" do subject.should be_option :ca_location end it "should set the ca location when invoked" do - pending "#6983: This is broken in the actual string..." + pending "#6983: This is broken in the actual faces..." Puppet::SSL::Host.expects(:ca_location=).with(:foo) Puppet::SSL::Host.indirection.expects(:save) subject.sign :ca_location => :foo diff --git a/spec/unit/string/config_spec.rb b/spec/unit/faces/config_spec.rb index 9919fef87..2eb04a81b 100755 --- a/spec/unit/string/config_spec.rb +++ b/spec/unit/faces/config_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::String[:config, '0.0.1'] do +describe Puppet::Faces[:config, '0.0.1'] do it "should use Settings#print_config_options when asked to print" do Puppet.settings.stubs(:puts) Puppet.settings.expects(:print_config_options) diff --git a/spec/unit/string/configurer_spec.rb b/spec/unit/faces/configurer_spec.rb index 1b428ef20..270888ca1 100755 --- a/spec/unit/string/configurer_spec.rb +++ b/spec/unit/faces/configurer_spec.rb @@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/indirector/catalog/rest' require 'tempfile' -describe Puppet::String[:configurer, '0.0.1'] do +describe Puppet::Faces[:configurer, '0.0.1'] do describe "#synchronize" do it "should retrieve and apply a catalog and return a report" do dirname = Dir.mktmpdir("puppetdir") diff --git a/spec/unit/string/facts_spec.rb b/spec/unit/faces/facts_spec.rb index 9b7024724..480f463e4 100755 --- a/spec/unit/string/facts_spec.rb +++ b/spec/unit/faces/facts_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::String[:facts, '0.0.1'] do +describe Puppet::Faces[:facts, '0.0.1'] do it "should define an 'upload' fact" do subject.should be_action(:upload) end diff --git a/spec/unit/faces/file_spec.rb b/spec/unit/faces/file_spec.rb new file mode 100755 index 000000000..fcb52c67e --- /dev/null +++ b/spec/unit/faces/file_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Faces[:file, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/string/indirector_spec.rb b/spec/unit/faces/indirector_spec.rb index cb85eaa05..218694bd9 100755 --- a/spec/unit/string/indirector_spec.rb +++ b/spec/unit/faces/indirector_spec.rb @@ -1,11 +1,11 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/string/indirector' +require 'puppet/faces/indirector' -describe Puppet::String::Indirector do +describe Puppet::Faces::Indirector do subject do - instance = Puppet::String::Indirector.new(:test, '0.0.1') + instance = Puppet::Faces::Indirector.new(:test, '0.0.1') indirection = stub('indirection', :name => :stub_indirection, :reset_terminus_class => nil) @@ -14,24 +14,24 @@ describe Puppet::String::Indirector do end it "should be able to return a list of indirections" do - Puppet::String::Indirector.indirections.should be_include("catalog") + Puppet::Faces::Indirector.indirections.should be_include("catalog") end it "should be able to return a list of terminuses for a given indirection" do - Puppet::String::Indirector.terminus_classes(:catalog).should be_include("compiler") + Puppet::Faces::Indirector.terminus_classes(:catalog).should be_include("compiler") end describe "as an instance" do it "should be able to determine its indirection" do # Loading actions here an get, um, complicated - Puppet::String.stubs(:load_actions) - Puppet::String::Indirector.new(:catalog, '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection) + Puppet::Faces.stubs(:load_actions) + Puppet::Faces::Indirector.new(:catalog, '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection) end end [:find, :search, :save, :destroy].each do |method| it "should define a '#{method}' action" do - Puppet::String::Indirector.should be_action(method) + Puppet::Faces::Indirector.should be_action(method) end it "should call the indirection method when the '#{method}' action is invoked" do @@ -51,6 +51,6 @@ describe Puppet::String::Indirector do end it "should define a class-level 'info' action" do - Puppet::String::Indirector.should be_action(:info) + Puppet::Faces::Indirector.should be_action(:info) end end diff --git a/spec/unit/faces/key_spec.rb b/spec/unit/faces/key_spec.rb new file mode 100755 index 000000000..9b7a58706 --- /dev/null +++ b/spec/unit/faces/key_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Faces[:key, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/string/node_spec.rb b/spec/unit/faces/node_spec.rb index 520cc0f5e..4639bdf63 100755 --- a/spec/unit/string/node_spec.rb +++ b/spec/unit/faces/node_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::String[:node, '0.0.1'] do +describe Puppet::Faces[:node, '0.0.1'] do it "should set its default format to :yaml" do subject.default_format.should == :yaml end diff --git a/spec/unit/faces/report_spec.rb b/spec/unit/faces/report_spec.rb new file mode 100755 index 000000000..30897d5e7 --- /dev/null +++ b/spec/unit/faces/report_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Faces[:report, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/faces/resource_spec.rb b/spec/unit/faces/resource_spec.rb new file mode 100755 index 000000000..e3f2e1c62 --- /dev/null +++ b/spec/unit/faces/resource_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Faces[:resource, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/faces/resource_type_spec.rb b/spec/unit/faces/resource_type_spec.rb new file mode 100755 index 000000000..fcbf07520 --- /dev/null +++ b/spec/unit/faces/resource_type_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Faces[:resource_type, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/string/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb index 5f6f1c08f..ae9cc83d4 100755 --- a/spec/unit/string/action_builder_spec.rb +++ b/spec/unit/interface/action_builder_spec.rb @@ -1,53 +1,53 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/string/action_builder' +require 'puppet/interface/action_builder' -describe Puppet::String::ActionBuilder do +describe Puppet::Interface::ActionBuilder do describe "::build" do it "should build an action" do - action = Puppet::String::ActionBuilder.build(nil, :foo) do + action = Puppet::Interface::ActionBuilder.build(nil, :foo) do end - action.should be_a(Puppet::String::Action) + action.should be_a(Puppet::Interface::Action) action.name.should == :foo end - it "should define a method on the string which invokes the action" do - string = Puppet::String.new(:action_builder_test_string, '0.0.1') - action = Puppet::String::ActionBuilder.build(string, :foo) do + it "should define a method on the face which invokes the action" do + face = Puppet::Interface.new(:action_builder_test_interface, '0.0.1') + action = Puppet::Interface::ActionBuilder.build(face, :foo) do when_invoked do "invoked the method" end end - string.foo.should == "invoked the method" + face.foo.should == "invoked the method" end it "should require a block" do - lambda { Puppet::String::ActionBuilder.build(nil, :foo) }. + expect { Puppet::Interface::ActionBuilder.build(nil, :foo) }. should raise_error("Action :foo must specify a block") end describe "when handling options" do - let :string do Puppet::String.new(:option_handling, '0.0.1') end + let :face do Puppet::Interface.new(:option_handling, '0.0.1') end it "should have a #option DSL function" do method = nil - Puppet::String::ActionBuilder.build(string, :foo) do + Puppet::Interface::ActionBuilder.build(face, :foo) do method = self.method(:option) end method.should be end it "should define an option without a block" do - action = Puppet::String::ActionBuilder.build(string, :foo) do + action = Puppet::Interface::ActionBuilder.build(face, :foo) do option "--bar" end action.should be_option :bar end it "should accept an empty block" do - action = Puppet::String::ActionBuilder.build(string, :foo) do + action = Puppet::Interface::ActionBuilder.build(face, :foo) do option "--bar" do # This space left deliberately blank. end diff --git a/spec/unit/string/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb index b8baf80a5..50bea5f89 100755 --- a/spec/unit/string/action_manager_spec.rb +++ b/spec/unit/interface/action_manager_spec.rb @@ -2,14 +2,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -# This is entirely an internal class for String, so we have to load it instead of our class. -require 'puppet/string' +# This is entirely an internal class for Interface, so we have to load it instead of our class. +require 'puppet/interface' class ActionManagerTester - include Puppet::String::ActionManager + include Puppet::Interface::ActionManager end -describe Puppet::String::ActionManager do +describe Puppet::Interface::ActionManager do subject { ActionManagerTester.new } describe "when included in a class" do @@ -73,7 +73,7 @@ describe Puppet::String::ActionManager do end describe "when used to extend a class" do - subject { Class.new.extend(Puppet::String::ActionManager) } + subject { Class.new.extend(Puppet::Interface::ActionManager) } it "should be able to define an action" do subject.action(:foo) do @@ -102,8 +102,8 @@ describe Puppet::String::ActionManager do describe "when used both at the class and instance level" do before do @klass = Class.new do - include Puppet::String::ActionManager - extend Puppet::String::ActionManager + include Puppet::Interface::ActionManager + extend Puppet::Interface::ActionManager end @instance = @klass.new end @@ -216,7 +216,7 @@ describe Puppet::String::ActionManager do describe "#get_action" do let :parent_class do - parent_class = Class.new(Puppet::String) + parent_class = Class.new(Puppet::Interface) parent_class.action(:foo) {} parent_class end diff --git a/spec/unit/string/action_spec.rb b/spec/unit/interface/action_spec.rb index b6fe87a63..4801a3cc8 100755 --- a/spec/unit/string/action_spec.rb +++ b/spec/unit/interface/action_spec.rb @@ -1,13 +1,13 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/string/action' +require 'puppet/interface/action' -describe Puppet::String::Action do +describe Puppet::Interface::Action do describe "when validating the action name" do [nil, '', 'foo bar', '-foobar'].each do |input| it "should treat #{input.inspect} as an invalid name" do - expect { Puppet::String::Action.new(nil, input) }. + expect { Puppet::Interface::Action.new(nil, input) }. should raise_error(/is an invalid action name/) end end @@ -15,7 +15,7 @@ describe Puppet::String::Action do describe "when invoking" do it "should be able to call other actions on the same object" do - string = Puppet::String.new(:my_string, '0.0.1') do + face = Puppet::Interface.new(:my_face, '0.0.1') do action(:foo) do when_invoked { 25 } end @@ -24,8 +24,8 @@ describe Puppet::String::Action do when_invoked { "the value of foo is '#{foo}'" } end end - string.foo.should == 25 - string.bar.should == "the value of foo is '25'" + face.foo.should == 25 + face.bar.should == "the value of foo is '25'" end # bar is a class action calling a class action @@ -33,7 +33,7 @@ describe Puppet::String::Action do # baz is an instance action calling a class action # qux is an instance action calling an instance action it "should be able to call other actions on the same object when defined on a class" do - class Puppet::String::MyStringBaseClass < Puppet::String + class Puppet::Interface::MyInterfaceBaseClass < Puppet::Interface action(:foo) do when_invoked { 25 } end @@ -47,7 +47,7 @@ describe Puppet::String::Action do end end - string = Puppet::String::MyStringBaseClass.new(:my_inherited_string, '0.0.1') do + face = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_face, '0.0.1') do action(:baz) do when_invoked { "the value of foo in baz is '#{foo}'" } end @@ -56,16 +56,16 @@ describe Puppet::String::Action do when_invoked { baz } end end - string.foo.should == 25 - string.bar.should == "the value of foo is '25'" - string.quux.should == "qux told me the value of foo in baz is '25'" - string.baz.should == "the value of foo in baz is '25'" - string.qux.should == "the value of foo in baz is '25'" + face.foo.should == 25 + face.bar.should == "the value of foo is '25'" + face.quux.should == "qux told me the value of foo in baz is '25'" + face.baz.should == "the value of foo in baz is '25'" + face.qux.should == "the value of foo in baz is '25'" end context "when calling the Ruby API" do - let :string do - Puppet::String.new(:ruby_api, '1.0.0') do + let :face do + Puppet::Interface.new(:ruby_api, '1.0.0') do action :bar do when_invoked do |options| options @@ -75,12 +75,12 @@ describe Puppet::String::Action do end it "should work when no options are supplied" do - options = string.bar + options = face.bar options.should == {} end it "should work when options are supplied" do - options = string.bar :bar => "beer" + options = face.bar :bar => "beer" options.should == { :bar => "beer" } end end @@ -88,7 +88,7 @@ describe Puppet::String::Action do describe "with action-level options" do it "should support options with an empty block" do - string = Puppet::String.new(:action_level_options, '0.0.1') do + face = Puppet::Interface.new(:action_level_options, '0.0.1') do action :foo do option "--bar" do # this line left deliberately blank @@ -96,33 +96,33 @@ describe Puppet::String::Action do end end - string.should_not be_option :bar - string.get_action(:foo).should be_option :bar + face.should_not be_option :bar + face.get_action(:foo).should be_option :bar end - it "should return only action level options when there are no string options" do - string = Puppet::String.new(:action_level_options, '0.0.1') do + it "should return only action level options when there are no face options" do + face = Puppet::Interface.new(:action_level_options, '0.0.1') do action :foo do option "--bar" end end - string.get_action(:foo).options.should =~ [:bar] + face.get_action(:foo).options.should =~ [:bar] end - describe "with both string and action options" do - let :string do - Puppet::String.new(:action_level_options, '0.0.1') do + describe "with both face and action options" do + let :face do + Puppet::Interface.new(:action_level_options, '0.0.1') do action :foo do option "--bar" end action :baz do option "--bim" end option "--quux" end end - it "should return combined string and action options" do - string.get_action(:foo).options.should =~ [:bar, :quux] + it "should return combined face and action options" do + face.get_action(:foo).options.should =~ [:bar, :quux] end - it "should fetch options that the string inherited" do - parent = Class.new(Puppet::String) + it "should fetch options that the face inherited" do + parent = Class.new(Puppet::Interface) parent.option "--foo" child = parent.new(:inherited_options, '0.0.1') do option "--bar" @@ -133,37 +133,37 @@ describe Puppet::String::Action do action.should be [:baz, :bar, :foo].each do |name| - action.get_option(name).should be_an_instance_of Puppet::String::Option + action.get_option(name).should be_an_instance_of Puppet::Interface::Option end end it "should get an action option when asked" do - string.get_action(:foo).get_option(:bar). - should be_an_instance_of Puppet::String::Option + face.get_action(:foo).get_option(:bar). + should be_an_instance_of Puppet::Interface::Option end - it "should get a string option when asked" do - string.get_action(:foo).get_option(:quux). - should be_an_instance_of Puppet::String::Option + it "should get a face option when asked" do + face.get_action(:foo).get_option(:quux). + should be_an_instance_of Puppet::Interface::Option end it "should return options only for this action" do - string.get_action(:baz).options.should =~ [:bim, :quux] + face.get_action(:baz).options.should =~ [:bim, :quux] end end it_should_behave_like "things that declare options" do def add_options_to(&block) - string = Puppet::String.new(:with_options, '0.0.1') do + face = Puppet::Interface.new(:with_options, '0.0.1') do action(:foo, &block) end - string.get_action(:foo) + face.get_action(:foo) end end - it "should fail when a string option duplicates an action option" do + it "should fail when a face option duplicates an action option" do expect { - Puppet::String.new(:action_level_options, '0.0.1') do + Puppet::Interface.new(:action_level_options, '0.0.1') do option "--foo" action :bar do option "--foo" end end diff --git a/spec/unit/string/string_collection_spec.rb b/spec/unit/interface/face_collection_spec.rb index fab647da0..de6d29cee 100755 --- a/spec/unit/string/string_collection_spec.rb +++ b/spec/unit/interface/face_collection_spec.rb @@ -3,22 +3,22 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'tmpdir' -describe Puppet::String::StringCollection do +describe Puppet::Interface::FaceCollection do # To avoid cross-pollution we have to save and restore both the hash - # containing all the string data, and the array used by require. Restoring + # containing all the interface data, and the array used by require. Restoring # both means that we don't leak side-effects across the code. --daniel 2011-04-06 before :each do - @original_strings = subject.instance_variable_get("@strings").dup + @original_faces = subject.instance_variable_get("@faces").dup @original_required = $".dup - subject.instance_variable_get("@strings").clear + subject.instance_variable_get("@faces").clear end after :each do - subject.instance_variable_set("@strings", @original_strings) + subject.instance_variable_set("@faces", @original_faces) $".clear ; @original_required.each do |item| $" << item end end - describe "::strings" do + describe "::faces" do it "REVISIT: should have some tests here, if we describe it" end @@ -50,12 +50,12 @@ describe Puppet::String::StringCollection do describe "::[]" do before :each do - subject.instance_variable_get("@strings")[:foo]['0.0.1'] = 10 + subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10 end before :each do @dir = Dir.mktmpdir - @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'string') + @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'faces') $LOAD_PATH.push(@dir) end @@ -64,95 +64,95 @@ describe Puppet::String::StringCollection do $LOAD_PATH.pop end - it "should return the string with the given name" do + it "should return the faces with the given name" do subject["foo", '0.0.1'].should == 10 end - it "should attempt to load the string if it isn't found" do - subject.expects(:require).with('puppet/string/bar') + it "should attempt to load the faces if it isn't found" do + subject.expects(:require).with('puppet/faces/bar') subject["bar", '0.0.1'] end - it "should attempt to load the default string for the specified version :current" do + it "should attempt to load the default faces for the specified version :current" do subject.expects(:require).never # except... - subject.expects(:require).with('puppet/string/fozzie') + subject.expects(:require).with('puppet/faces/fozzie') subject['fozzie', :current] end end - describe "::string?" do + describe "::face?" do before :each do - subject.instance_variable_get("@strings")[:foo]['0.0.1'] = 10 + subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10 end - it "should return true if the string specified is registered" do - subject.string?("foo", '0.0.1').should == true + it "should return true if the faces specified is registered" do + subject.face?("foo", '0.0.1').should == true end - it "should attempt to require the string if it is not registered" do + it "should attempt to require the faces if it is not registered" do subject.expects(:require).with do |file| - subject.instance_variable_get("@strings")[:bar]['0.0.1'] = true - file == 'puppet/string/bar' + subject.instance_variable_get("@faces")[:bar]['0.0.1'] = true + file == 'puppet/faces/bar' end - subject.string?("bar", '0.0.1').should == true + subject.face?("bar", '0.0.1').should == true end - it "should return true if requiring the string registered it" do + it "should return true if requiring the faces registered it" do subject.stubs(:require).with do - subject.instance_variable_get("@strings")[:bar]['0.0.1'] = 20 + subject.instance_variable_get("@faces")[:bar]['0.0.1'] = 20 end end - it "should return false if the string is not registered" do + it "should return false if the faces is not registered" do subject.stubs(:require).returns(true) - subject.string?("bar", '0.0.1').should be_false + subject.face?("bar", '0.0.1').should be_false end - it "should return false if the string file itself is missing" do + it "should return false if the faces file itself is missing" do subject.stubs(:require). - raises(LoadError, 'no such file to load -- puppet/string/bar') - subject.string?("bar", '0.0.1').should be_false + raises(LoadError, 'no such file to load -- puppet/faces/bar') + subject.face?("bar", '0.0.1').should be_false end it "should register the version loaded by `:current` as `:current`" do subject.expects(:require).with do |file| - subject.instance_variable_get("@strings")[:huzzah]['2.0.1'] = :huzzah_string - file == 'puppet/string/huzzah' + subject.instance_variable_get("@faces")[:huzzah]['2.0.1'] = :huzzah_faces + file == 'puppet/faces/huzzah' end - subject.string?("huzzah", :current) - subject.instance_variable_get("@strings")[:huzzah][:current].should == :huzzah_string + subject.face?("huzzah", :current) + subject.instance_variable_get("@faces")[:huzzah][:current].should == :huzzah_faces end context "with something on disk" do before :each do - write_scratch_string :huzzah do |fh| + write_scratch_faces :huzzah do |fh| fh.puts <<EOF -Puppet::String.define(:huzzah, '2.0.1') do +Puppet::Faces.define(:huzzah, '2.0.1') do action :bar do "is where beer comes from" end end EOF end end - it "should register the version loaded from `puppet/string/{name}` as `:current`" do - subject.should be_string "huzzah", '2.0.1' - subject.should be_string "huzzah", :current - Puppet::String[:huzzah, '2.0.1'].should == Puppet::String[:huzzah, :current] + it "should register the version loaded from `puppet/faces/{name}` as `:current`" do + subject.should be_face "huzzah", '2.0.1' + subject.should be_face "huzzah", :current + Puppet::Faces[:huzzah, '2.0.1'].should == Puppet::Faces[:huzzah, :current] end it "should index :current when the code was pre-required" do - subject.instance_variable_get("@strings")[:huzzah].should_not be_key :current - require 'puppet/string/huzzah' - subject.string?(:huzzah, :current).should be_true + subject.instance_variable_get("@faces")[:huzzah].should_not be_key :current + require 'puppet/faces/huzzah' + subject.face?(:huzzah, :current).should be_true end end end describe "::register" do - it "should store the string by name" do - string = Puppet::String.new(:my_string, '0.0.1') - subject.register(string) - subject.instance_variable_get("@strings").should == {:my_string => {'0.0.1' => string}} + it "should store the faces by name" do + faces = Puppet::Faces.new(:my_faces, '0.0.1') + subject.register(faces) + subject.instance_variable_get("@faces").should == {:my_faces => {'0.0.1' => faces}} end end @@ -177,7 +177,7 @@ EOF faulty.each do |input| it "should fail when presented with #{input.inspect} (#{input.class})" do expect { subject.underscorize(input) }. - should raise_error ArgumentError, /not a valid string name/ + should raise_error ArgumentError, /not a valid face name/ end end end diff --git a/spec/unit/interface/option_builder_spec.rb b/spec/unit/interface/option_builder_spec.rb new file mode 100644 index 000000000..fae48324e --- /dev/null +++ b/spec/unit/interface/option_builder_spec.rb @@ -0,0 +1,29 @@ +require 'puppet/interface/option_builder' + +describe Puppet::Interface::OptionBuilder do + let :face do Puppet::Interface.new(:option_builder_testing, '0.0.1') end + + it "should be able to construct an option without a block" do + Puppet::Interface::OptionBuilder.build(face, "--foo"). + should be_an_instance_of Puppet::Interface::Option + end + + describe "when using the DSL block" do + it "should work with an empty block" do + option = Puppet::Interface::OptionBuilder.build(face, "--foo") do + # This block deliberately left blank. + end + + 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 + end + option.should be_an_instance_of Puppet::Interface::Option + option.desc.should == text + end + end +end diff --git a/spec/unit/string/option_spec.rb b/spec/unit/interface/option_spec.rb index f4f62ec37..3bcd121e2 100644 --- a/spec/unit/string/option_spec.rb +++ b/spec/unit/interface/option_spec.rb @@ -1,14 +1,14 @@ -require 'puppet/string/option' +require 'puppet/interface/option' -describe Puppet::String::Option do - let :string do Puppet::String.new(:option_testing, '0.0.1') end +describe Puppet::Interface::Option do + let :face do Puppet::Interface.new(:option_testing, '0.0.1') end describe "#optparse_to_name" do ["", "=BAR", " BAR", "=bar", " bar"].each do |postfix| { "--foo" => :foo, "-f" => :f }.each do |base, expect| input = base + postfix it "should map #{input.inspect} to #{expect.inspect}" do - option = Puppet::String::Option.new(string, input) + option = Puppet::Interface::Option.new(face, input) option.name.should == expect end end @@ -16,58 +16,58 @@ describe Puppet::String::Option do [:foo, 12, nil, {}, []].each do |input| it "should fail sensible when given #{input.inspect}" do - expect { Puppet::String::Option.new(string, input) }. + expect { Puppet::Interface::Option.new(face, input) }. should raise_error ArgumentError, /is not valid for an option argument/ end end ["-foo", "-foo=BAR", "-foo BAR"].each do |input| it "should fail with a single dash for long option #{input.inspect}" do - expect { Puppet::String::Option.new(string, input) }. + expect { Puppet::Interface::Option.new(face, input) }. should raise_error ArgumentError, /long options need two dashes \(--\)/ end end end - it "requires a string when created" do - expect { Puppet::String::Option.new }. + it "requires a face when created" do + expect { Puppet::Interface::Option.new }. should raise_error ArgumentError, /wrong number of arguments/ end it "also requires some declaration arguments when created" do - expect { Puppet::String::Option.new(string) }. + expect { Puppet::Interface::Option.new(face) }. should raise_error ArgumentError, /No option declarations found/ end it "should infer the name from an optparse string" do - option = Puppet::String::Option.new(string, "--foo") + option = Puppet::Interface::Option.new(face, "--foo") option.name.should == :foo end - it "should infer the name when multiple optparse strings are given" do - option = Puppet::String::Option.new(string, "--foo", "-f") + it "should infer the name when multiple optparse string are given" do + option = Puppet::Interface::Option.new(face, "--foo", "-f") option.name.should == :foo end it "should prefer the first long option name over a short option name" do - option = Puppet::String::Option.new(string, "-f", "--foo") + option = Puppet::Interface::Option.new(face, "-f", "--foo") option.name.should == :foo end - it "should create an instance when given a string and name" do - Puppet::String::Option.new(string, "--foo"). - should be_instance_of Puppet::String::Option + it "should create an instance when given a face and name" do + Puppet::Interface::Option.new(face, "--foo"). + should be_instance_of Puppet::Interface::Option end describe "#to_s" do it "should transform a symbol into a string" do - option = Puppet::String::Option.new(string, "--foo") + option = Puppet::Interface::Option.new(face, "--foo") option.name.should == :foo option.to_s.should == "foo" end it "should use - rather than _ to separate words in strings but not symbols" do - option = Puppet::String::Option.new(string, "--foo-bar") + option = Puppet::Interface::Option.new(face, "--foo-bar") option.name.should == :foo_bar option.to_s.should == "foo-bar" end diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb new file mode 100755 index 000000000..afcf95dcf --- /dev/null +++ b/spec/unit/interface_spec.rb @@ -0,0 +1,146 @@ +require 'puppet/faces' +require 'puppet/interface' + +describe Puppet::Interface do + subject { Puppet::Interface } + + before :all do + @faces = Puppet::Interface::FaceCollection.instance_variable_get("@faces").dup + end + + before :each do + Puppet::Interface::FaceCollection.instance_variable_get("@faces").clear + end + + after :all do + Puppet::Interface::FaceCollection.instance_variable_set("@faces", @faces) + end + + describe "#define" do + it "should register the face" do + face = subject.define(:face_test_register, '0.0.1') + face.should == subject[:face_test_register, '0.0.1'] + end + + it "should load actions" do + subject.any_instance.expects(:load_actions) + subject.define(:face_test_load_actions, '0.0.1') + end + + it "should require a version number" do + expect { subject.define(:no_version) }.should raise_error ArgumentError + end + end + + describe "#initialize" do + it "should require a version number" do + expect { subject.new(:no_version) }.should raise_error ArgumentError + end + + it "should require a valid version number" do + expect { subject.new(:bad_version, 'Rasins') }. + should raise_error ArgumentError + end + + it "should instance-eval any provided block" do + face = subject.new(:face_test_block, '0.0.1') do + action(:something) do + when_invoked { "foo" } + end + end + + face.something.should == "foo" + end + end + + it "should have a name" do + subject.new(:me, '0.0.1').name.should == :me + end + + it "should stringify with its own name" do + subject.new(:me, '0.0.1').to_s.should =~ /\bme\b/ + end + + it "should allow overriding of the default format" do + face = subject.new(:me, '0.0.1') + face.set_default_format :foo + face.default_format.should == :foo + end + + it "should default to :pson for its format" do + subject.new(:me, '0.0.1').default_format.should == :pson + end + + # Why? + it "should create a class-level autoloader" do + subject.autoloader.should be_instance_of(Puppet::Util::Autoload) + end + + it "should try to require faces that are not known" do + subject::FaceCollection.expects(:require).with "puppet/faces/foo" + subject[:foo, '0.0.1'] + end + + it "should be able to load all actions in all search paths" + + + it_should_behave_like "things that declare options" do + def add_options_to(&block) + subject.new(:with_options, '0.0.1', &block) + end + end + + describe "with face-level options" do + it "should not return any action-level options" do + face = subject.new(:with_options, '0.0.1') do + option "--foo" + option "--bar" + action :baz do + option "--quux" + end + end + face.options.should =~ [:foo, :bar] + end + + it "should fail when a face option duplicates an action option" do + expect { + subject.new(:action_level_options, '0.0.1') do + action :bar do option "--foo" end + option "--foo" + end + }.should raise_error ArgumentError, /Option foo conflicts with existing option foo on/i + end + + it "should work when two actions have the same option" do + face = subject.new(:with_options, '0.0.1') do + action :foo do option "--quux" end + action :bar do option "--quux" end + end + + face.get_action(:foo).options.should =~ [:quux] + face.get_action(:bar).options.should =~ [:quux] + end + end + + describe "with inherited options" do + let :face do + parent = Class.new(subject) + parent.option("--inherited") + face = parent.new(:example, '0.2.1') + face.option("--local") + face + end + + describe "#options" do + it "should list inherited options" do + face.options.should =~ [:inherited, :local] + end + end + + describe "#get_option" do + it "should return an inherited option object" do + face.get_option(:inherited).should be_an_instance_of subject::Option + end + end + end +end diff --git a/spec/unit/string/catalog_spec.rb b/spec/unit/string/catalog_spec.rb deleted file mode 100755 index 70dadd54b..000000000 --- a/spec/unit/string/catalog_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::String[:catalog, '0.0.1'] do -end diff --git a/spec/unit/string/certificate_request_spec.rb b/spec/unit/string/certificate_request_spec.rb deleted file mode 100755 index d0a8288b3..000000000 --- a/spec/unit/string/certificate_request_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::String[:certificate_request, '0.0.1'] do -end diff --git a/spec/unit/string/certificate_revocation_list_spec.rb b/spec/unit/string/certificate_revocation_list_spec.rb deleted file mode 100755 index 9168fb8ce..000000000 --- a/spec/unit/string/certificate_revocation_list_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::String[:certificate_revocation_list, '0.0.1'] do -end diff --git a/spec/unit/string/file_spec.rb b/spec/unit/string/file_spec.rb deleted file mode 100755 index f1b9302be..000000000 --- a/spec/unit/string/file_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::String[:file, '0.0.1'] do -end diff --git a/spec/unit/string/key_spec.rb b/spec/unit/string/key_spec.rb deleted file mode 100755 index fe3532d23..000000000 --- a/spec/unit/string/key_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::String[:key, '0.0.1'] do -end diff --git a/spec/unit/string/option_builder_spec.rb b/spec/unit/string/option_builder_spec.rb deleted file mode 100644 index 9e913c29c..000000000 --- a/spec/unit/string/option_builder_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'puppet/string/option_builder' - -describe Puppet::String::OptionBuilder do - let :string do Puppet::String.new(:option_builder_testing, '0.0.1') end - - it "should be able to construct an option without a block" do - Puppet::String::OptionBuilder.build(string, "--foo"). - should be_an_instance_of Puppet::String::Option - end - - describe "when using the DSL block" do - it "should work with an empty block" do - option = Puppet::String::OptionBuilder.build(string, "--foo") do - # This block deliberately left blank. - end - - option.should be_an_instance_of Puppet::String::Option - end - - it "should support documentation declarations" do - text = "this is the description" - option = Puppet::String::OptionBuilder.build(string, "--foo") do - desc text - end - option.should be_an_instance_of Puppet::String::Option - option.desc.should == text - end - end -end diff --git a/spec/unit/string/report_spec.rb b/spec/unit/string/report_spec.rb deleted file mode 100755 index 2e206dd06..000000000 --- a/spec/unit/string/report_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::String[:report, '0.0.1'] do -end diff --git a/spec/unit/string/resource_spec.rb b/spec/unit/string/resource_spec.rb deleted file mode 100755 index f4e618616..000000000 --- a/spec/unit/string/resource_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::String[:resource, '0.0.1'] do -end diff --git a/spec/unit/string/resource_type_spec.rb b/spec/unit/string/resource_type_spec.rb deleted file mode 100755 index d12ec00ce..000000000 --- a/spec/unit/string/resource_type_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::String[:resource_type, '0.0.1'] do -end diff --git a/spec/unit/string_spec.rb b/spec/unit/string_spec.rb deleted file mode 100755 index 9b7cd887c..000000000 --- a/spec/unit/string_spec.rb +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') - -describe Puppet::String do - before :all do - @strings = Puppet::String::StringCollection.instance_variable_get("@strings").dup - end - - before :each do - Puppet::String::StringCollection.instance_variable_get("@strings").clear - end - - after :all do - Puppet::String::StringCollection.instance_variable_set("@strings", @strings) - end - - describe "#define" do - it "should register the string" do - string = Puppet::String.define(:string_test_register, '0.0.1') - string.should == Puppet::String[:string_test_register, '0.0.1'] - end - - it "should load actions" do - Puppet::String.any_instance.expects(:load_actions) - Puppet::String.define(:string_test_load_actions, '0.0.1') - end - - it "should require a version number" do - proc { Puppet::String.define(:no_version) }.should raise_error(ArgumentError) - end - end - - describe "#initialize" do - it "should require a version number" do - proc { Puppet::String.new(:no_version) }.should raise_error(ArgumentError) - end - - it "should require a valid version number" do - proc { Puppet::String.new(:bad_version, 'Rasins') }.should raise_error(ArgumentError) - end - - it "should instance-eval any provided block" do - face = Puppet::String.new(:string_test_block, '0.0.1') do - action(:something) do - when_invoked { "foo" } - end - end - - face.something.should == "foo" - end - end - - it "should have a name" do - Puppet::String.new(:me, '0.0.1').name.should == :me - end - - it "should stringify with its own name" do - Puppet::String.new(:me, '0.0.1').to_s.should =~ /\bme\b/ - end - - it "should allow overriding of the default format" do - face = Puppet::String.new(:me, '0.0.1') - face.set_default_format :foo - face.default_format.should == :foo - end - - it "should default to :pson for its format" do - Puppet::String.new(:me, '0.0.1').default_format.should == :pson - end - - # Why? - it "should create a class-level autoloader" do - Puppet::String.autoloader.should be_instance_of(Puppet::Util::Autoload) - end - - it "should try to require strings that are not known" do - Puppet::String::StringCollection.expects(:require).with "puppet/string/foo" - Puppet::String[:foo, '0.0.1'] - end - - it "should be able to load all actions in all search paths" - - - it_should_behave_like "things that declare options" do - def add_options_to(&block) - Puppet::String.new(:with_options, '0.0.1', &block) - end - end - - describe "with string-level options" do - it "should not return any action-level options" do - string = Puppet::String.new(:with_options, '0.0.1') do - option "--foo" - option "--bar" - action :baz do - option "--quux" - end - end - string.options.should =~ [:foo, :bar] - end - - it "should fail when a string option duplicates an action option" do - expect { - Puppet::String.new(:action_level_options, '0.0.1') do - action :bar do option "--foo" end - option "--foo" - end - }.should raise_error ArgumentError, /Option foo conflicts with existing option foo on/i - end - - it "should work when two actions have the same option" do - string = Puppet::String.new(:with_options, '0.0.1') do - action :foo do option "--quux" end - action :bar do option "--quux" end - end - - string.get_action(:foo).options.should =~ [:quux] - string.get_action(:bar).options.should =~ [:quux] - end - end - - describe "with inherited options" do - let :string do - parent = Class.new(Puppet::String) - parent.option("--inherited") - string = parent.new(:example, '0.2.1') - string.option("--local") - string - end - - describe "#options" do - it "should list inherited options" do - string.options.should =~ [:inherited, :local] - end - end - - describe "#get_option" do - it "should return an inherited option object" do - string.get_option(:inherited).should be_an_instance_of Puppet::String::Option - end - end - end -end |
