Created
October 19, 2012 00:58
-
-
Save martinos/3915664 to your computer and use it in GitHub Desktop.
Helper for testing executable in gem.
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 'open3' | |
def ruby_run(cmd, stdin_str) | |
bundler_gem = '-r bundler/setup' if Gem.loaded_specs.keys.include?('bundler') | |
libs = '-I ./lib' | |
full_cmd = %{ruby #{libs} #{bundler_gem} ./bin/#{cmd}} | |
stdout_str, stderr_str = ['', ''] | |
exit_code = 0 | |
Open3.popen3(full_cmd) do |stdin, stdout, stderr, wait_thr| | |
stdin.write stdin_str | |
stdin.close | |
stdout_str = stdout.read | |
stderr_str = stderr.read | |
exit_code = wait_thr.value | |
end | |
[stdout_str, stderr_str, exit_code] | |
end | |
ruby_run("rubyc map -o StringEncoder 'l.upcase'", "tata") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment