Created
October 14, 2009 07:29
-
-
Save tkareine/209844 to your computer and use it in GitHub Desktop.
Test Ruby executable with code injection to have stubs/mocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
puts "from original executable, args: #{ARGV.join(" ")}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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