Skip to content

Commit

Permalink
tweak run command output, fixing variable scope issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ddollar committed May 7, 2012
1 parent 6eb4eb7 commit f9bec03
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/heroku/command/run.rb
Expand Up @@ -13,10 +13,12 @@ def index
command = args.join(" ")
fail "Usage: heroku run COMMAND" if command.empty?
opts = { :attach => true, :command => command, :ps_env => get_terminal_environment }
action("Running #{command} attached to terminal") do
ps = action("Running #{command} attached to terminal", :success => "up") do
ps = heroku.ps_run(app, opts)
status ps["process"]
ps
end
rendezvous_session(ps["rendezvous_url"]) { display "up, #{ps["process"]}" }
rendezvous_session(ps["rendezvous_url"])
end

# run:detached COMMAND
Expand All @@ -26,12 +28,13 @@ def index
def detached
command = args.join(" ")
fail "Usage: heroku run COMMAND" if command.empty?
opts = { :command => command }
action("Running #{command}") do
opts = { :attach => false, :command => command }
ps = action("Running #{command}", :success => "up") do
ps = heroku.ps_run(app, opts)
status("up, #{ps["process"]}")
status ps["process"]
ps
end
puts "Use 'heroku logs -p #{ps["process"]}' to view the log output."
puts "Use `heroku logs -p #{ps["process"]}` to view the output."
end

# run:rake COMMAND
Expand Down
28 changes: 28 additions & 0 deletions spec/heroku/command/run_spec.rb
Expand Up @@ -2,6 +2,34 @@
require "heroku/command/run"

describe Heroku::Command::Run do
describe "run" do
it "runs a command" do
stub_core.ps_run("myapp", :attach => true, :command => "bin/foo", :ps_env => get_terminal_environment).returns("process" => "run.1", "rendezvous_url" => "rendezvous://s1.runtime.heroku.com:5000/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
stub_rendezvous.start { $stdout.puts "output" }

stderr, stdout = execute("run bin/foo")
stderr.should == ""
stdout.should == <<-STDOUT
Running bin/foo attached to terminal... up, run.1
output
STDOUT
end
end

describe "run:detached" do
it "runs a command detached" do
stub_core.ps_run("myapp", :attach => false, :command => "bin/foo").returns("process" => "run.1")
stub_rendezvous.start { $stdout.puts "output" }

stderr, stdout = execute("run:detached bin/foo")
stderr.should == ""
stdout.should == <<-STDOUT
Running bin/foo... up, run.1
Use `heroku logs -p run.1` to view the output.
STDOUT
end
end

describe "run:rake" do
it "runs a rake command" do
stub_core.ps_run("myapp", :attach => true, :command => "rake foo", :ps_env => get_terminal_environment, :type => "rake").returns("rendezvous_url" => "rendezvous://s1.runtime.heroku.com:5000/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
Expand Down

0 comments on commit f9bec03

Please sign in to comment.