diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-03-28 21:37:05 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-02 15:51:23 -0700 |
| commit | 05b434dca10bbc18d794358a9d08db89a46424f9 (patch) | |
| tree | 1191c7fa664da4795a489c7dd08969e0757f9a1e /spec | |
| parent | a3f5f974251e14f02e8f83e12f4589581dd21828 (diff) | |
(#6758) Pass options as an argument to string actions.
Earlier in their implementation the String prototype would set global state on
a String object to reflect options set on the command line. As we move
strings away from a CLI-only prototype, this becomes troublesome because we
can easily have, for example, HTTP access to a string, which means load
balancers can really make this confusing.
It also encourages global state pollution, where one invocation can adversely
influence another. A better approach is that we pass options to the string
action invocation directly; this makes the interaction stateless.
Changes required to your code to adapt to the new world:
- action(:foo) do |some, args|
+ action(:foo) do |some, args, options={}|
if options[:whatever] then
Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/application/string_base_spec.rb | 11 | ||||
| -rwxr-xr-x | spec/unit/string/action_spec.rb | 2 |
2 files changed, 7 insertions, 6 deletions
diff --git a/spec/unit/application/string_base_spec.rb b/spec/unit/application/string_base_spec.rb index 86f9c09aa..65cadb8fd 100755 --- a/spec/unit/application/string_base_spec.rb +++ b/spec/unit/application/string_base_spec.rb @@ -5,6 +5,7 @@ require 'puppet/application/string_base' require 'tmpdir' class Puppet::Application::StringBase::Basetest < Puppet::Application::StringBase + option("--[no-]foo") end describe Puppet::Application::StringBase do @@ -61,14 +62,14 @@ describe Puppet::Application::StringBase do it "should make sure arguments are an array" do @app.command_line.stubs(:args).returns(["find", "myname", "myarg"]) @app.setup - @app.arguments.should == ["myname", "myarg"] + @app.arguments.should == ["myname", "myarg", {}] end - it "should set the options on the string" do - @app.options[:foo] = "bar" + it "should pass options as the last argument" do + @app.command_line.stubs(:args).returns(["find", "myname", "myarg", "--foo"]) + @app.parse_options @app.setup - - @app.string.options.should == @app.options + @app.arguments.should == ["myname", "myarg", { :foo => true }] end end end diff --git a/spec/unit/string/action_spec.rb b/spec/unit/string/action_spec.rb index caf3291b6..f4ca8316d 100755 --- a/spec/unit/string/action_spec.rb +++ b/spec/unit/string/action_spec.rb @@ -7,7 +7,7 @@ describe Puppet::String::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::Interface::Action.new(nil, input) }. + expect { Puppet::String::Action.new(nil, input) }. should raise_error(/is an invalid action name/) end end |
