Skip to content
Browse files

Allow default options for a named executable to be overriden.

  • Loading branch information...
1 parent 9a5f715 commit 38689261f75d1a606f6d79ea9f58abc79e893077 @alloy alloy committed
Showing with 9 additions and 4 deletions.
  1. +4 −4 lib/executioner.rb
  2. +5 −0 test/executioner_test.rb
View
8 lib/executioner.rb
@@ -56,8 +56,8 @@ def execute_queued(options={})
module ClassMethods
def executable(executable, options={})
- options[:switch_stdout_and_stderr] = false if options[:switch_stdout_and_stderr].nil?
- options[:use_queue] = false if options[:use_queue].nil?
+ options[:switch_stdout_and_stderr] ||= false
+ options[:use_queue] ||= false
executable = executable.to_s if executable.is_a? Symbol
use_queue = options.delete(:use_queue)
@@ -76,13 +76,13 @@ def executable(executable, options={})
if use_queue
body = "queue(\"#{executable_path} \#{args}\")"
else
- body = "execute(\"#{executable_path} \#{args}\", #{options.inspect})"
+ body = "execute(\"#{executable_path} \#{args}\", #{options.inspect}.merge(options))"
end
else
body = "raise Executioner::ExecutableNotFoundError, \"Unable to find the executable '#{executable}' in: #{Executioner::SEARCH_PATHS.join(', ')}\""
end
- class_eval "def #{executable.gsub(/-/, '_')}(args); #{body}; end", __FILE__, __LINE__
+ class_eval "def #{executable.gsub(/-/, '_')}(args, options = {}); #{body}; end", __FILE__, __LINE__
end
def find_executable(executable, advance_from = nil)
View
5 test/executioner_test.rb
@@ -154,6 +154,11 @@ def stub_popen3(stdout = '', stderr = '')
@object.with_env 'arg1'
end
+ it "should merge options onto the default options" do
+ @object.expects(:execute).with { |command, options| options[:env] == { :foo => 'foo' } }
+ @object.with_env 'arg1', :env => { :foo => 'foo' }
+ end
+
it "should be possible to find an executable" do
File.stubs(:exist?).with('/bin/sh').returns(true)
Executioner::ClassMethods.find_executable('sh').should == '/bin/sh'

0 comments on commit 3868926

Please sign in to comment.
Something went wrong with that request. Please try again.