Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #255 from opscode/jdmundrawala/exec-version
Browse files Browse the repository at this point in the history
Pass version to command when execing
  • Loading branch information
jaym committed Dec 6, 2014
2 parents 0cd8dd9 + 66fc747 commit 9203008
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/chef-dk/command/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def run(params)
exec(*params)
raise "Exec failed without an exception, your ruby is buggy" # should never get here
end

def needs_version?(params)
# Force version to get passed down to command
false
end

def needs_help?(params)
['-h', '--help'].include? params[0]
end
end
end
end
Expand Down
43 changes: 42 additions & 1 deletion spec/unit/command/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
let(:command_options) { [] }

def run_command
command_instance.run(command_options)
command_instance.run_with_default_options(command_options)
end

it "has a usage banner" do
Expand Down Expand Up @@ -97,6 +97,47 @@ def run_command
expect{ run_command }.to raise_error # XXX: this isn't a test we just need to swallow the exception
end

['-v', '--version', '-h', '--help'].each do |switch|
context "when running a command with #{switch}" do
let(:command_options) { %W[gem list #{switch}] }

it "should call exec to fire off the command with the correct environment" do
expect(ENV).to receive(:[]=).with("PATH", expected_PATH)
expect(ENV).to receive(:[]=).with("GEM_ROOT", expected_GEM_ROOT)
expect(ENV).to receive(:[]=).with("GEM_HOME", expected_GEM_HOME)
expect(ENV).to receive(:[]=).with("GEM_PATH", expected_GEM_PATH)

expect(command_instance).to receive(:exec).with(*command_options)
expect{ run_command }.to raise_error # XXX: this isn't a test we just need to swallow the exception
end
end
end

['-h', '--help'].each do |switch|
context "when running a exec with #{switch} and things after it" do
let(:command_options) { %W[#{switch} gem] }

it "should call not call exec, but it should print the banner" do
allow(command_instance).to receive(:msg)
expect(ENV).not_to receive(:[]=)
expect(command_instance).to receive(:banner)
expect(command_instance).not_to receive(:exec)
run_command
end
end

context "when running a exec with #{switch}" do
let(:command_options) { ["#{switch}"] }

it "should call not call exec, but it should print the banner" do
allow(command_instance).to receive(:msg)
expect(ENV).not_to receive(:[]=)
expect(command_instance).to receive(:banner)
expect(command_instance).not_to receive(:exec)
run_command
end
end
end
end

context "when running command that does not exist" do
Expand Down

0 comments on commit 9203008

Please sign in to comment.