diff --git a/spec/unit/application/string_base_spec.rb b/spec/unit/application/string_base_spec.rb index 37f6fddcb..20185b526 100755 --- a/spec/unit/application/string_base_spec.rb +++ b/spec/unit/application/string_base_spec.rb @@ -1,142 +1,150 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/application/string_base' require 'tmpdir' class Puppet::Application::StringBase::Basetest < Puppet::Application::StringBase option("--[no-]foo") end describe Puppet::Application::StringBase 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')" end end after :all do FileUtils.remove_entry_secure @dir $LOAD_PATH.pop end let :app do app = Puppet::Application::StringBase::Basetest.new app.stubs(:exit) app.stubs(:puts) app.command_line.stubs(:subcommand_name).returns 'subcommand' app.command_line.stubs(:args).returns [] Puppet::Util::Log.stubs(:newdestination) app end describe "#preinit" do before :each do app.command_line.stubs(:args).returns %w{} end - it "should set the string based on the type" - it "should set the format based on the string default" - describe "parsing the command line" do before :all do Puppet::String[:basetest, '0.0.1'].action :foo do option "--foo" - invoke do |options| - options - end + invoke { |options| options } end end - it "should find the action" do - app.command_line.stubs(:args).returns %w{foo} - app.preinit - app.action.should be - app.action.name.should == :foo + context "with just an action" do + before :all do + app.command_line.stubs(:args).returns %w{foo} + app.preinit + end + + it "should set the string based on the type" do + app.string.name.should == :basetest + end + + it "should set the format based on the string default" do + app.format.should == :pson + end + + it "should find the action" do + app.action.should be + app.action.name.should == :foo + end end it "should fail if no action is given" do expect { app.preinit }. should raise_error ArgumentError, /No action given/ end it "should report a sensible error when options with = fail" do app.command_line.stubs(:args).returns %w{--foo=bar foo} expect { app.preinit }. should raise_error ArgumentError, /Unknown option "--foo"/ end it "should fail if an action option is before the action" do app.command_line.stubs(:args).returns %w{--foo foo} expect { app.preinit }. should raise_error ArgumentError, /Unknown option "--foo"/ end it "should fail if an unknown option is before the action" do app.command_line.stubs(:args).returns %w{--bar foo} expect { app.preinit }. should raise_error ArgumentError, /Unknown option "--bar"/ end it "should not fail if an unknown option is after the action" 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.action.should_not be_option :bar end end end describe "when calling main" do # before do # @app.verb = :find # @app.arguments = ["myname", "myarg"] # @app.string.stubs(:find) # end it "should send the specified verb and name to the string" do pending "REVISIT: disabled, needs to be rewritten for the new introspection model. --daniel 2011-03-31" @app.string.expects(:find).with("myname", "myarg") app.main end it "should use its render method to render any result" it "should exit with the current exit code" end describe "during setup" do before do app.command_line.stubs(:args).returns(["find", "myname", "myarg"]) app.stubs(:validate) end it "should set the verb from the command line arguments" do pending "REVISIT: needs updating too..." @app.setup @app.verb.should == "find" end it "should make sure arguments are an array" do pending "REVISIT: needs updating too..." @app.command_line.stubs(:args).returns(["find", "myname", "myarg"]) @app.setup @app.arguments.should == ["myname", "myarg", {}] end it "should pass options as the last argument" do pending "REVISIT: needs updating too..." @app.command_line.stubs(:args).returns(["find", "myname", "myarg", "--foo"]) @app.parse_options @app.setup @app.arguments.should == ["myname", "myarg", { :foo => true }] end end end diff --git a/spec/unit/string/indirector_spec.rb b/spec/unit/string/indirector_spec.rb index 29e8e7086..cb85eaa05 100755 --- a/spec/unit/string/indirector_spec.rb +++ b/spec/unit/string/indirector_spec.rb @@ -1,56 +1,56 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/string/indirector' describe Puppet::String::Indirector do subject do instance = Puppet::String::Indirector.new(:test, '0.0.1') indirection = stub('indirection', :name => :stub_indirection, :reset_terminus_class => nil) instance.stubs(:indirection).returns indirection instance end it "should be able to return a list of indirections" do Puppet::String::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") 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) end end [:find, :search, :save, :destroy].each do |method| it "should define a '#{method}' action" do Puppet::String::Indirector.should be_action(method) end it "should call the indirection method when the '#{method}' action is invoked" do subject.indirection.expects(method).with(:test, "myargs") subject.send(method, :test, "myargs") end end it "should be able to override its indirection name" do - @instance.set_indirection_name :foo - @instance.indirection_name.should == :foo + subject.set_indirection_name :foo + subject.indirection_name.should == :foo end it "should be able to set its terminus class" do - @instance.indirection.expects(:terminus_class=).with(:myterm) - @instance.set_terminus(:myterm) + subject.indirection.expects(:terminus_class=).with(:myterm) + subject.set_terminus(:myterm) end it "should define a class-level 'info' action" do Puppet::String::Indirector.should be_action(:info) end end