spec/shelly/cli/main_spec.rb in shelly-0.0.48 vs spec/shelly/cli/main_spec.rb in shelly-0.0.49.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,10 +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-staging/billing/edit")
fake_stdin(["", ""]) do
invoke(@main, :add)
end
end
@@ -412,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)
@@ -433,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
@@ -463,11 +493,11 @@
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