spec/engineyard-visualvm_spec.rb in engineyard-visualvm-0.5.1 vs spec/engineyard-visualvm_spec.rb in engineyard-visualvm-0.5.2

- old
+ new

@@ -21,11 +21,11 @@ } end end describe EngineYard::VisualVM::CLI do - let(:script) { Class.new(EngineYard::VisualVM::CLI) } + let(:script) { Class.new(EngineYard::VisualVM::CLI) { include SystemDouble } } context "#help" do it "prints the default port" do capture { script.start(["help", "start"]) }.should =~ /Default:/ end @@ -40,10 +40,11 @@ capture { script.start(["url", "--port=1234"]) }.should =~ /service:jmx:rmi.*:1234/ end end context "#start" do + let(:system_double) { double("system").tap {|d| script.system_double = d } } let(:ssh_process) { double("ssh process double").tap {|d| d.should_receive(:start) } } let(:visualvm_process) do double("visualvm process double").tap {|d| d.should_receive(:start) d.should_receive(:exited?).and_return(true) @@ -81,10 +82,11 @@ end script.start(["start", "--host=example.com"]) end it "sets up an ssh tunnel if the user@host format is used" do + system_double.should_receive(:system).with("ssh user@example.com true").ordered.and_return true ChildProcess.should_receive(:build).ordered.and_return do |*args| args.join(' ').should =~ /ssh -NL.*user@example.com/ ssh_process end ChildProcess.should_receive(:build).ordered.and_return do |*args| @@ -95,10 +97,11 @@ script.start(["start", "--host=user@example.com"]) end it "allows an ssh tunnel to be forced" do + system_double.should_receive(:system).ordered.and_return true ChildProcess.should_receive(:build).ordered.and_return do |*args| args.join(' ').should =~ /ssh -NL/ ssh_process end ChildProcess.should_receive(:build).ordered.and_return do |*args| @@ -120,10 +123,11 @@ after :each do @server.close; @server = nil end it "finds an open port for the local side of the ssh tunnel" do + system_double.should_receive(:system).ordered.and_return true ChildProcess.should_receive(:build).ordered.and_return do |*args| args.join(' ').should =~ /ssh -NL #{@next_port}:localhost:#{@port}/ ssh_process end ChildProcess.should_receive(:build).ordered.and_return do |*args| @@ -137,11 +141,10 @@ end context "with --environment specified" do let(:environment) do double(:environment).tap {|e| - e.stub!(:load_balancer_ip_address).and_return "0.0.0.0" e.stub!(:username).and_return "deploy" } end before :each do env = environment @@ -149,11 +152,28 @@ no_tasks { define_method(:fetch_environment) { env } } end end it "sets the user to 'deploy' and the host to the load balancer IP address" do + environment.stub!(:load_balancer_ip_address).and_return "0.0.0.0" ChildProcess.should_receive(:build).ordered.and_return do |*args| args.join(' ').should =~ /ssh -NL.* deploy@0.0.0.0/ + ssh_process + end + ChildProcess.should_receive(:build).ordered.and_return do |*args| + args[2].should =~ /service:jmx:rmi.*localhost:/ + visualvm_process + end + ssh_process.should_receive(:stop) + + script.start(["start", "--environment=jruby"]) + end + + it "uses the public hostname of the first instance if no load balancer" do + environment.stub!(:load_balancer_ip_address).and_return nil + environment.stub!(:instances).and_return [double("instance").tap{|d| d.stub!(:public_hostname).and_return "example.com" }] + ChildProcess.should_receive(:build).ordered.and_return do |*args| + args.join(' ').should =~ /ssh -NL.* deploy@example.com/ ssh_process end ChildProcess.should_receive(:build).ordered.and_return do |*args| args[2].should =~ /service:jmx:rmi.*localhost:/ visualvm_process