Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #364 from smarterclayton/bug_952985_to_stage_fix_c…
Browse files Browse the repository at this point in the history
…ontext_arguments

Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Apr 17, 2013
2 parents 7b4699a + 0e97d0b commit 452a286
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/rhc/commands.rb
Expand Up @@ -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 =
Expand All @@ -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?
Expand Down
11 changes: 10 additions & 1 deletion spec/rhc/command_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 452a286

Please sign in to comment.