Skip to content

Instantly share code, notes, and snippets.

@tkareine
Created October 14, 2009 07:29
Show Gist options
  • Save tkareine/209844 to your computer and use it in GitHub Desktop.
Save tkareine/209844 to your computer and use it in GitHub Desktop.
Test Ruby executable with code injection to have stubs/mocks
#!/usr/bin/env ruby
puts "from original executable, args: #{ARGV.join(" ")}"
require "open4"
exec = "foo.rb"
injection = "puts \\\"injected!\\\"" # useful for injecting stub/mock code
args = "passed args"
cmd = "ruby -e \"#{injection}; `cat #{exec}`\" -- #{args}"
Open4::popen4(cmd) { |p, i, o| puts o.readlines }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment