spec/shelly/cli/main_spec.rb in shelly-0.0.50 vs spec/shelly/cli/main_spec.rb in shelly-0.0.51.pre
- old
+ new
@@ -272,10 +272,11 @@
@app.stub(:git_url).and_return("git@git.shellycloud.com:foooo.git")
Shelly::App.stub(:inside_git_repository?).and_return(true)
Shelly::App.stub(:new).and_return(@app)
@client.stub(:token).and_return("abc")
@app.stub(:attributes).and_return({"trial" => false})
+ @app.stub(:git_remote_exist?).and_return(false)
end
# This spec tests inside_git_repository? hook
it "should exit with message if command run outside git repository" do
Shelly::App.stub(:inside_git_repository?).and_return(false)
@@ -326,21 +327,21 @@
end
end
end
it "should use code name provided by user" do
- $stdout.should_receive(:print).with("Cloud code name (foo-production - default): ")
+ $stdout.should_receive(:print).with("Cloud code name (foo-staging - default): ")
@app.should_receive(:code_name=).with("mycodename")
fake_stdin(["mycodename", ""]) do
invoke(@main, :add)
end
end
context "when user provided empty code name" do
it "should use 'current_dirname-purpose' as default" do
- $stdout.should_receive(:print).with("Cloud code name (foo-production - default): ")
- @app.should_receive(:code_name=).with("foo-production")
+ $stdout.should_receive(:print).with("Cloud code name (foo-staging - default): ")
+ @app.should_receive(:code_name=).with("foo-staging")
fake_stdin(["", ""]) do
invoke(@main, :add)
end
end
end
@@ -391,11 +392,11 @@
@client.stub(:shellyapp_url).and_return("http://example.com")
@app.should_receive(:create)
$stdout.should_receive(:puts).with(green "Billing information")
$stdout.should_receive(:puts).with("Cloud created with 20 Euro credit.")
$stdout.should_receive(:puts).with("Remember to provide billing details before trial ends.")
- $stdout.should_receive(:puts).with("http://example.com/apps/foo-production/billing/edit")
+ $stdout.should_receive(:puts).with("http://example.com/apps/foo-staging/billing/edit")
fake_stdin(["", ""]) do
invoke(@main, :add)
end
end
@@ -413,11 +414,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-production --databases=postgresql --domains=foo-production.shellyapp.com\e[0m")
+ $stdout.should_receive(:puts).with("\e[31mshelly add --code-name=foo-staging --databases=postgresql --domains=foo-staging.shellyapp.com\e[0m")
lambda {
fake_stdin(["", ""]) do
invoke(@main, :add)
end
}.should raise_error(SystemExit)
@@ -434,16 +435,44 @@
invoke(@main, :add)
end
}.should raise_error(SystemExit)
end
- it "should add git remote" do
- $stdout.should_receive(:puts).with("\e[32mAdding remote production git@git.shellycloud.com:foooo.git\e[0m")
- @app.should_receive(:add_git_remote)
- fake_stdin(["foooo", ""]) do
- invoke(@main, :add)
+ context "git remote" do
+ it "should add one if it doesn't exist" do
+ $stdout.should_receive(:puts).with("\e[32mAdding remote foooo git@git.shellycloud.com:foooo.git\e[0m")
+ @app.should_receive(:add_git_remote)
+ fake_stdin(["foooo", ""]) do
+ invoke(@main, :add)
+ end
end
+
+ context "does exist" do
+ before do
+ @app.stub(:git_remote_exist?).and_return(true)
+ end
+
+ it "should ask if one exist and overwrite" do
+ $stdout.should_receive(:print).with("Git remote foooo exists, overwrite (yes/no): ")
+ $stdout.should_receive(:puts).with(green "Adding remote foooo git@git.shellycloud.com:foooo.git")
+ @app.should_receive(:add_git_remote)
+ fake_stdin(["foooo", "", "yes"]) do
+ invoke(@main, :add)
+ end
+ end
+
+ it "should ask if one exist and not overwrite" do
+ $stdout.should_receive(:print).with("Git remote foooo exists, overwrite (yes/no): ")
+ $stdout.should_receive(:puts).with("You have to manually add git remote:")
+ $stdout.should_receive(:puts).with("`git remote add NAME git@git.shellycloud.com:foooo.git`")
+ @app.should_not_receive(:add_git_remote)
+ fake_stdin(["foooo", "", "no"]) do
+ invoke(@main, :add)
+ end
+ end
+
+ end
end
it "should create Cloudfile" do
File.exists?("/projects/foo/Cloudfile").should be_false
fake_stdin(["foooo", ""]) do
@@ -464,12 +493,12 @@
it "should display info on how to deploy to ShellyCloud" do
$stdout.should_receive(:puts).with("\e[32mWhen you make sure all settings are correct please issue following commands:\e[0m")
$stdout.should_receive(:puts).with(" git add .")
$stdout.should_receive(:puts).with(' git commit -m "Application added to Shelly Cloud"')
$stdout.should_receive(:puts).with(" git push")
- $stdout.should_receive(:puts).with("\e[32mDeploy to production using:\e[0m")
- $stdout.should_receive(:puts).with(" git push production master")
+ $stdout.should_receive(:puts).with("\e[32mDeploy to your cloud using:\e[0m")
+ $stdout.should_receive(:puts).with(" git push foooo master")
fake_stdin(["foooo", "none"]) do
invoke(@main, :add)
end
end
end
@@ -547,12 +576,12 @@
end
context "single cloud in Cloudfile" do
it "should start the cloud" do
@client.stub(:start_cloud)
- $stdout.should_receive(:puts).with(green "Starting cloud foo-production. Check status with:")
- $stdout.should_receive(:puts).with(" shelly list")
+ $stdout.should_receive(:puts).with(green "Starting cloud foo-production.")
+ $stdout.should_receive(:puts).with("Check status with: `shelly list`")
invoke(@main, :start)
end
end
context "multiple clouds in Cloudfile" do
@@ -569,12 +598,12 @@
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
end
it "should fetch from command line which cloud to start" do
@client.should_receive(:start_cloud).with("foo-staging")
- $stdout.should_receive(:puts).with(green "Starting cloud foo-staging. Check status with:")
- $stdout.should_receive(:puts).with(" shelly list")
+ $stdout.should_receive(:puts).with(green "Starting cloud foo-staging.")
+ $stdout.should_receive(:puts).with("Check status with: `shelly list`")
@main.options = {:cloud => "foo-staging"}
invoke(@main, :start)
end
end
@@ -612,17 +641,24 @@
end
end
it "should show that winnie is out of resources" do
raise_conflict("state" => "not_enough_resources")
- $stdout.should_receive(:puts).with(red "Sorry, There are no resources for your servers. We have been notified about it. We will be adding new resources shortly")
+ $stdout.should_receive(:puts).with(red "Sorry, There are no resources for your servers.
+We have been notified about it. We will be adding new resources shortly")
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
end
it "should show messages about billing" do
raise_conflict("state" => "no_billing")
$stdout.should_receive(:puts).with(red "Please fill in billing details to start foo-production.")
@client.stub(:shellyapp_url).and_return("http://example.com")
+ lambda { invoke(@main, :start) }.should raise_error(SystemExit)
+ end
+
+ it "should show messge about payment declined" do
+ raise_conflict("state" => "payment_declined")
+ $stdout.should_receive(:puts).with(red "Not starting. Invoice for cloud 'foo-production' was declined.")
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
end
def raise_conflict(options = {})
body = {"state" => "no_code"}.merge(options)