spec/shelly/cli/main_spec.rb in shelly-0.0.56 vs spec/shelly/cli/main_spec.rb in shelly-0.0.57

- old
+ new

@@ -39,11 +39,11 @@ shelly rake TASK # Run rake task shelly redeploy # Redeploy application shelly register [EMAIL] # Register new account shelly setup # Set up clouds shelly start # Start the cloud - shelly stop # Stop the cloud + shelly stop # Shutdown the cloud shelly user <command> # Manage collaborators shelly version # Display shelly version Options: [--debug] # Show debug information @@ -312,31 +312,31 @@ }.should raise_error(SystemExit) end context "command line options" do context "invalid params" do - it "should show help and exit if not all options are passed" do + it "should exit if databases are not valid" do $stdout.should_receive(:puts).with("\e[31mTry `shelly help add` for more information\e[0m") - @main.options = {"code-name" => "foo"} + @main.options = {"code-name" => "foo", "databases" => ["not existing"]} lambda { invoke(@main, :add) }.should raise_error(SystemExit) end - it "should exit if databases are not valid" do + it "should exit if size is not valid" do $stdout.should_receive(:puts).with("\e[31mTry `shelly help add` for more information\e[0m") - @main.options = {"code-name" => "foo", "databases" => ["not existing"]} + @main.options = {"size" => "wrong_size"} lambda { invoke(@main, :add) }.should raise_error(SystemExit) end end context "valid params" do it "should create app on shelly cloud" do @app.should_receive(:create) - @main.options = {"code-name" => "foo", "databases" => ["postgresql"]} + @main.options = {"code-name" => "foo", "databases" => ["postgresql"], "size" => "large"} invoke(@main, :add) end end end @@ -426,11 +426,11 @@ body = {"message" => "Validation Failed", "errors" => [["code_name", "has been already taken"]]} exception = Shelly::Client::ValidationException.new(body) @app.should_receive(:create).and_raise(exception) $stdout.should_receive(:puts).with("\e[31mCode name has been already taken\e[0m") $stdout.should_receive(:puts).with("\e[31mFix erros in the below command and type it again to create your cloud\e[0m") - $stdout.should_receive(:puts).with("\e[31mshelly add --code-name=foo-staging --databases=postgresql\e[0m") + $stdout.should_receive(:puts).with("\e[31mshelly add --code-name=foo-staging --databases=postgresql --size=large\e[0m") lambda { fake_stdin(["", ""]) do invoke(@main, :add) end }.should raise_error(SystemExit) @@ -628,11 +628,11 @@ it "should show information that cloud has no code" do raise_conflict("state" => "no_code") $stdout.should_receive(:puts).with(red "Not starting: no source code provided") $stdout.should_receive(:puts).with(red "Push source code using:") - $stdout.should_receive(:puts).with(" git push production master") + $stdout.should_receive(:puts).with(" git push foo-production master") lambda { invoke(@main, :start) }.should raise_error(SystemExit) end %w{deploy_failed configuration_failed}.each do |state| it "should show information that cloud #{state}" do @@ -697,39 +697,51 @@ end it "should exit if user doesn't have access to clouds in Cloudfile" do @client.stub(:stop_cloud).and_raise(Shelly::Client::NotFoundException.new("resource" => "cloud")) $stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile") - lambda { invoke(@main, :stop) }.should raise_error(SystemExit) + lambda { + fake_stdin(["yes"]) do + invoke(@main, :stop) + end + }.should raise_error(SystemExit) end context "single cloud in Cloudfile" do - it "should start the cloud" do + it "should stop the cloud" do @client.stub(:stop_cloud) + $stdout.should_receive(:print).with("Are you sure you want to shut down your application (yes/no): ") + $stdout.should_receive(:puts).with("\n") $stdout.should_receive(:puts).with("Cloud 'foo-production' stopped") - invoke(@main, :stop) + fake_stdin(["yes"]) do + invoke(@main, :stop) + end end end context "multiple clouds in Cloudfile" do before do File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") } end - it "should show information to start specific cloud and exit" do + it "should show information to stop specific cloud and exit" do $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.") $stdout.should_receive(:puts).with("Select cloud using `shelly stop --cloud foo-production`") $stdout.should_receive(:puts).with("Available clouds:") $stdout.should_receive(:puts).with(" * foo-production") $stdout.should_receive(:puts).with(" * foo-staging") lambda { invoke(@main, :stop) }.should raise_error(SystemExit) end - it "should fetch from command line which cloud to start" do + it "should fetch from command line which cloud to stop" do @client.should_receive(:stop_cloud).with("foo-staging") + $stdout.should_receive(:print).with("Are you sure you want to shut down your application (yes/no): ") + $stdout.should_receive(:puts).with("\n") $stdout.should_receive(:puts).with("Cloud 'foo-staging' stopped") @main.options = {:cloud => "foo-staging"} - invoke(@main, :stop) + fake_stdin(["yes"]) do + invoke(@main, :stop) + end end end end describe "#ip" do