Skip to content

Commit

Permalink
Merge pull request guard#1 from jacortinas/command_formatting
Browse files Browse the repository at this point in the history
Command formatting to be more robust, based on the arguments that IO.popen can accept
  • Loading branch information
mrkcor committed Jul 8, 2011
2 parents 3c05619 + fb4460f commit 5988fb5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/guard/process.rb
Expand Up @@ -6,8 +6,8 @@ class Process < Guard
def initialize(watchers = [], options = {})
@process = nil
@pid = nil
@command = options[:command]
@env = options[:env]
@command = options.fetch(:command).split
@env = options[:env]
@name = options[:name]
@stop_signal = options[:stop_signal] || "TERM"
super
Expand All @@ -23,7 +23,8 @@ def process_running?

def start
UI.info("Starting process #{@name}")
@process = @env ? IO.popen([@env, @command]) : IO.popen(@command)
@command.unshift(@env) if @env
@process = IO.popen(@command)
UI.info("Started process #{@name}")
@pid = @process.pid
end
Expand Down
18 changes: 17 additions & 1 deletion test/guard/process_test.rb
Expand Up @@ -13,7 +13,7 @@ def teardown
@guard.stop if @guard.process_running?
ENV['GUARD_ENV'] = nil
end

def test_run_all_returns_true
assert @guard.run_all
end
Expand Down Expand Up @@ -47,4 +47,20 @@ def test_reload_stops_and_starts_command
@guard.reload
assert @guard.process_running?
end

def test_commands_are_formatted_correctly_with_and_without_env
@options = {:command => 'echo test test', :name => 'EchoProcess'}
@env = {'VAR3' => 'VALUE 3'}

IO.expects(:popen).with(["echo", "test", "test"]).returns(stub_everything)
IO.expects(:popen).with([@env, "echo", "test", "test"]).returns(stub_everything)

@guard = Guard::Process.new([], @options)
@guard.start and @guard.stop

@options[:env] = @env

@guard = Guard::Process.new([], @options)
@guard.start and @guard.stop
end
end

0 comments on commit 5988fb5

Please sign in to comment.