diff options
-rw-r--r-- | lib/alaveteli_external_command.rb | 19 | ||||
-rw-r--r-- | spec/script/handle-mail-replies_spec.rb | 11 | ||||
-rw-r--r-- | spec/script/mailin_spec.rb | 4 |
3 files changed, 11 insertions, 23 deletions
diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb index fc8e31368..548a509b6 100644 --- a/lib/alaveteli_external_command.rb +++ b/lib/alaveteli_external_command.rb @@ -5,6 +5,7 @@ module AlaveteliExternalCommand # Final argument can be a hash of options. # Valid options are: # :append_to - string to append the output of the process to + # :append_errors_to - string to append the errors produced by the process to # :stdin_string - stdin string to pass to the process # :binary_output - boolean flag for treating the output as binary or text encoded with # the default external encoding (only significant in ruby 1.9 and above) @@ -12,6 +13,7 @@ module AlaveteliExternalCommand # the default external encoding (only significant in ruby 1.9 and above) # :memory_limit - maximum amount of memory (in bytes) available to the process # :timeout - maximum amount of time (in s) to allow the process to run for + # :env - hash of environment variables to set for the process def run(program_name, *args) # Run an external program, and return its output. # Standard error is suppressed unless the program @@ -22,23 +24,8 @@ module AlaveteliExternalCommand end program_path = find_program(program_name) - xc = ExternalCommand.new(program_path, *args) - if opts.has_key? :append_to - xc.out = opts[:append_to] - end - if opts.has_key? :binary_output - xc.binary_output = opts[:binary_output] - end - if opts.has_key? :binary_input - xc.binary_input = opts[:binary_input] - end - if opts.has_key? :memory_limit - xc.memory_limit = opts[:memory_limit] - end - - - xc.run(opts[:stdin_string] || "", opts[:env] || {}) + xc.run if !xc.exited # Crash or timeout diff --git a/spec/script/handle-mail-replies_spec.rb b/spec/script/handle-mail-replies_spec.rb index 90a8de27c..62d5c1dab 100644 --- a/spec/script/handle-mail-replies_spec.rb +++ b/spec/script/handle-mail-replies_spec.rb @@ -3,9 +3,9 @@ require "external_command" def mail_reply_test(email_filename) Dir.chdir Rails.root do - xc = ExternalCommand.new("script/handle-mail-replies", "--test") - xc.run(load_file_fixture(email_filename)) - + xc = ExternalCommand.new("script/handle-mail-replies", "--test", + :stdin_string => load_file_fixture(email_filename)) + xc.run xc.err.should == "" return xc end @@ -13,8 +13,9 @@ end describe "When filtering" do it "should not fail when not in test mode" do - xc = ExternalCommand.new("script/handle-mail-replies") - xc.run(load_file_fixture("track-response-exim-bounce.email")) + xc = ExternalCommand.new("script/handle-mail-replies", + { :stdin_string => load_file_fixture("track-response-exim-bounce.email") }) + xc.run xc.err.should == "" end diff --git a/spec/script/mailin_spec.rb b/spec/script/mailin_spec.rb index 46ad39f7f..0ff094c2b 100644 --- a/spec/script/mailin_spec.rb +++ b/spec/script/mailin_spec.rb @@ -3,12 +3,12 @@ require "external_command" def mailin_test(email_filename) Dir.chdir Rails.root do - xc = ExternalCommand.new("script/mailin") + mail = load_file_fixture(email_filename) ir = info_requests(:other_request) mail.gsub!('EMAIL_TO', ir.incoming_email) mail.gsub!('EMAIL_FROM', 'responder@localhost') - xc.run(mail) + xc = ExternalCommand.new("script/mailin", :stdin_string => mail).run xc.err.should == "" return xc end |