From 0e97d0b9d0acd539ef63a677d4e09cae73d999e9 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Wed, 17 Apr 2013 09:59:18 -0400 Subject: [PATCH] Bug 952985 - Context arguments broken due to optional list changes --- lib/rhc/commands.rb | 3 ++- spec/rhc/command_spec.rb | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/rhc/commands.rb b/lib/rhc/commands.rb index 41224be21..98394ff38 100644 --- a/lib/rhc/commands.rb +++ b/lib/rhc/commands.rb @@ -278,7 +278,6 @@ def self.fill_arguments(cmd, options, args_metadata, options_metadata, args) context_helper = arg[:context_helper] value = options.__hash__[option] if option - value = cmd.send(context_helper) if value.nil? and context_helper if value.nil? value = @@ -294,6 +293,8 @@ def self.fill_arguments(cmd, options, args_metadata, options_metadata, args) end end + value = cmd.send(context_helper) if value.nil? and context_helper + if value.nil? raise ArgumentError, "Missing required argument '#{arg[:name]}'." unless arg[:optional] break if available.empty? diff --git a/spec/rhc/command_spec.rb b/spec/rhc/command_spec.rb index 5a74f1227..790c2bad8 100644 --- a/spec/rhc/command_spec.rb +++ b/spec/rhc/command_spec.rb @@ -132,6 +132,10 @@ def execute_vararg(arg1, arg2, arg3); 1; end def execute_implicit end + argument :testarg, "Test arg", ["--testarg testarg"], :context => :context_var + summary "Test command execute" + def execute_context_arg(testarg); 1; end + def raise_error raise StandardError.new("test exception") end @@ -148,7 +152,7 @@ def context_var Static end - it("should register itself") { expect { subject }.to change(commands, :length).by(7) } + it("should register itself") { expect { subject }.to change(commands, :length).by(8) } it("should have an object name of the class") { subject.object_name.should == 'static' } context 'and when test is called' do @@ -196,6 +200,11 @@ def context_var it("calls the helper") { command_for('static', 'execute-implicit').send(:options).test_context.should == 'contextual' } end + context 'and when execute-context-arg is called with a contextual argument' do + it("calls the helper") { command_for('static', 'execute-context-arg').send(:options).test_context.should == 'contextual' } + it("takes the argument") { command_for('static', 'execute-context-arg', 'arg1').send(:options).testarg.should == 'arg1' } + end + context 'and when an error is raised in a call' do it { expects_running('static-raise-error').should raise_error(StandardError, "test exception") } end