shelly 0.0.57 → 0.0.58

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ describe Shelly::CLI::Deploys do
10
10
  Shelly::Client.stub(:new).and_return(@client)
11
11
  $stdout.stub(:puts)
12
12
  $stdout.stub(:print)
13
+ @app = Shelly::App.new("foo-staging")
13
14
  end
14
15
 
15
16
  describe "#list" do
@@ -24,8 +25,12 @@ describe Shelly::CLI::Deploys do
24
25
  hooks(@deploys, :list).should include(:logged_in?)
25
26
  end
26
27
 
27
- it "should ensure that Cloudfile is present" do
28
- hooks(@deploys, :list).should include(:cloudfile_present?)
28
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
29
+ it "should ensure multiple_clouds check" do
30
+ @client.should_receive(:deploy_logs).with("foo-staging").and_return([
31
+ {"failed" => false, "created_at" => "2011-12-12-14-14-59"}])
32
+ @deploys.should_receive(:multiple_clouds).and_return(@app)
33
+ invoke(@deploys, :list)
29
34
  end
30
35
 
31
36
  it "should exit if user doesn't have access to cloud in Cloudfile" do
@@ -34,39 +39,14 @@ describe Shelly::CLI::Deploys do
34
39
  lambda { invoke(@deploys, :list) }.should raise_error(SystemExit)
35
40
  end
36
41
 
37
- context "multiple clouds" do
38
- before do
39
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
40
- end
41
-
42
- it "should show information to select specific cloud and exit" do
43
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
44
- $stdout.should_receive(:puts).with("Select cloud using `shelly deploys list --cloud foo-production`")
45
- $stdout.should_receive(:puts).with("Available clouds:")
46
- $stdout.should_receive(:puts).with(" * foo-production")
47
- $stdout.should_receive(:puts).with(" * foo-staging")
48
- lambda { invoke(@deploys, :list) }.should raise_error(SystemExit)
49
- end
50
-
51
- it "should take cloud from command line for which to show logs" do
52
- @client.should_receive(:deploy_logs).with("foo-staging").and_return([{"failed" => false, "created_at" => "2011-12-12-14-14-59"}])
53
- $stdout.should_receive(:puts).with(green "Available deploy logs")
54
- $stdout.should_receive(:puts).with(" * 2011-12-12-14-14-59")
55
- @deploys.options = {:cloud => "foo-staging"}
56
- invoke(@deploys, :list)
57
- end
58
- end
59
-
60
- context "single cloud" do
61
- it "should display available logs" do
62
- @client.should_receive(:deploy_logs).with("foo-staging").and_return([
63
- {"failed" => false, "created_at" => "2011-12-12-14-14-59"},
64
- {"failed" => true, "created_at" => "2011-12-12-15-14-59"}])
65
- $stdout.should_receive(:puts).with(green "Available deploy logs")
66
- $stdout.should_receive(:puts).with(" * 2011-12-12-14-14-59")
67
- $stdout.should_receive(:puts).with(" * 2011-12-12-15-14-59 (failed)")
68
- invoke(@deploys, :list)
69
- end
42
+ it "should display available logs" do
43
+ @client.should_receive(:deploy_logs).with("foo-staging").and_return([
44
+ {"failed" => false, "created_at" => "2011-12-12-14-14-59"},
45
+ {"failed" => true, "created_at" => "2011-12-12-15-14-59"}])
46
+ $stdout.should_receive(:puts).with(green "Available deploy logs")
47
+ $stdout.should_receive(:puts).with(" * 2011-12-12-14-14-59")
48
+ $stdout.should_receive(:puts).with(" * 2011-12-12-15-14-59 (failed)")
49
+ invoke(@deploys, :list)
70
50
  end
71
51
  end
72
52
 
@@ -82,8 +62,11 @@ describe Shelly::CLI::Deploys do
82
62
  hooks(@deploys, :show).should include(:logged_in?)
83
63
  end
84
64
 
85
- it "should ensure that Cloudfile is present" do
86
- hooks(@deploys, :show).should include(:cloudfile_present?)
65
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
66
+ it "should ensure multiple_clouds check" do
67
+ @client.should_receive(:deploy_log).with("foo-staging", "last").and_return(response)
68
+ @deploys.should_receive(:multiple_clouds).and_return(@app)
69
+ invoke(@deploys, :show, "last")
87
70
  end
88
71
 
89
72
  context "user doesn't have access to cloud" do
@@ -104,28 +87,6 @@ describe Shelly::CLI::Deploys do
104
87
  end
105
88
  end
106
89
 
107
- context "multiple clouds" do
108
- before do
109
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
110
- end
111
-
112
- it "should show information to select specific cloud and exit" do
113
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
114
- $stdout.should_receive(:puts).with("Select cloud using `shelly deploys show last --cloud foo-production`")
115
- $stdout.should_receive(:puts).with("Available clouds:")
116
- $stdout.should_receive(:puts).with(" * foo-production")
117
- $stdout.should_receive(:puts).with(" * foo-staging")
118
- lambda { invoke(@deploys, :show, "last") }.should raise_error(SystemExit)
119
- end
120
-
121
- it "should render the logs" do
122
- @client.should_receive(:deploy_log).with("foo-staging", "last").and_return(response)
123
- expected_output
124
- @deploys.options = {:cloud => "foo-staging"}
125
- invoke(@deploys, :show, "last")
126
- end
127
- end
128
-
129
90
  context "single cloud" do
130
91
  it "should render logs without passing cloud" do
131
92
  @client.should_receive(:deploy_log).with("foo-staging", "last").and_return(response)
@@ -553,20 +553,12 @@ OUT
553
553
  Dir.chdir("/projects/foo")
554
554
  File.open("Cloudfile", 'w') {|f| f.write("foo-production:\n") }
555
555
  Shelly::User.stub(:new).and_return(@user)
556
- @client.stub(:apps).and_return([{"code_name" => "foo-production"}, {"code_name" => "foo-staging"}])
556
+ @client.stub(:apps).and_return([{"code_name" => "foo-production", "state" => "running"},
557
+ {"code_name" => "foo-staging", "state" => "no_code"}])
557
558
  @app = Shelly::App.new
558
559
  Shelly::App.stub(:new).and_return(@app)
559
560
  end
560
561
 
561
- # This spec tests cloudfile_present? hook
562
- it "should exit if there is no Cloudfile" do
563
- File.delete("Cloudfile")
564
- $stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
565
- lambda {
566
- invoke(@main, :start)
567
- }.should raise_error(SystemExit)
568
- end
569
-
570
562
  it "should ensure user has logged in" do
571
563
  hooks(@main, :start).should include(:logged_in?)
572
564
  end
@@ -588,6 +580,29 @@ OUT
588
580
  end
589
581
  end
590
582
 
583
+ # this tests multiple_clouds method used in majority of tasks
584
+ context "without Cloudfile" do
585
+ it "should use cloud from params" do
586
+ Dir.chdir("/projects")
587
+ @client.stub(:start_cloud)
588
+ $stdout.should_receive(:puts).with(green "Starting cloud foo-production.")
589
+ @main.options = {:cloud => "foo-production"}
590
+ invoke(@main, :start)
591
+ end
592
+
593
+ it "should ask user to specify cloud, list all clouds and exit" do
594
+ Dir.chdir("/projects")
595
+ @client.stub(:start_cloud)
596
+ $stdout.should_receive(:puts).with(red "You have to specify cloud.")
597
+ $stdout.should_receive(:puts).with("Select cloud using `shelly start --cloud CLOUD_NAME`")
598
+ $stdout.should_receive(:puts).with(green "You have following clouds available:")
599
+ $stdout.should_receive(:puts).with(" foo-production | running")
600
+ $stdout.should_receive(:puts).with(" foo-staging | no code")
601
+ lambda { invoke(@main, :start) }.should raise_error(SystemExit)
602
+ end
603
+ end
604
+
605
+ # this tests multiple_clouds method used in majority of tasks
591
606
  context "multiple clouds in Cloudfile" do
592
607
  before do
593
608
  File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
@@ -692,8 +707,13 @@ We have been notified about it. We will be adding new resources shortly")
692
707
  hooks(@main, :stop).should include(:logged_in?)
693
708
  end
694
709
 
695
- it "should ensure that Cloudfile is present" do
696
- hooks(@main, :stop).should include(:cloudfile_present?)
710
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
711
+ it "should ensure multiple_clouds check" do
712
+ @client.stub(:stop_cloud)
713
+ @main.should_receive(:multiple_clouds).and_return(@app)
714
+ fake_stdin(["yes"]) do
715
+ invoke(@main, :stop)
716
+ end
697
717
  end
698
718
 
699
719
  it "should exit if user doesn't have access to clouds in Cloudfile" do
@@ -706,48 +726,21 @@ We have been notified about it. We will be adding new resources shortly")
706
726
  }.should raise_error(SystemExit)
707
727
  end
708
728
 
709
- context "single cloud in Cloudfile" do
710
- it "should stop the cloud" do
711
- @client.stub(:stop_cloud)
712
- $stdout.should_receive(:print).with("Are you sure you want to shut down your application (yes/no): ")
713
- $stdout.should_receive(:puts).with("\n")
714
- $stdout.should_receive(:puts).with("Cloud 'foo-production' stopped")
715
- fake_stdin(["yes"]) do
716
- invoke(@main, :stop)
717
- end
729
+ it "should stop the cloud" do
730
+ @client.stub(:stop_cloud)
731
+ $stdout.should_receive(:print).with("Are you sure you want to shut down your application (yes/no): ")
732
+ $stdout.should_receive(:puts).with("\n")
733
+ $stdout.should_receive(:puts).with("Cloud 'foo-production' stopped")
734
+ fake_stdin(["yes"]) do
735
+ invoke(@main, :stop)
718
736
  end
719
737
  end
720
738
 
721
- context "multiple clouds in Cloudfile" do
722
- before do
723
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
724
- end
725
-
726
- it "should show information to stop specific cloud and exit" do
727
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
728
- $stdout.should_receive(:puts).with("Select cloud using `shelly stop --cloud foo-production`")
729
- $stdout.should_receive(:puts).with("Available clouds:")
730
- $stdout.should_receive(:puts).with(" * foo-production")
731
- $stdout.should_receive(:puts).with(" * foo-staging")
732
- lambda { invoke(@main, :stop) }.should raise_error(SystemExit)
733
- end
734
-
735
- it "should fetch from command line which cloud to stop" do
736
- @client.should_receive(:stop_cloud).with("foo-staging")
737
- $stdout.should_receive(:print).with("Are you sure you want to shut down your application (yes/no): ")
738
- $stdout.should_receive(:puts).with("\n")
739
- $stdout.should_receive(:puts).with("Cloud 'foo-staging' stopped")
740
- @main.options = {:cloud => "foo-staging"}
741
- fake_stdin(["yes"]) do
742
- invoke(@main, :stop)
743
- end
744
- end
745
- end
746
739
  end
747
740
 
748
741
  describe "#ip" do
749
742
  before do
750
- File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
743
+ File.open("Cloudfile", 'w') {|f| f.write("foo-production:\n") }
751
744
  @main.stub(:logged_in?).and_return(true)
752
745
  end
753
746
 
@@ -755,8 +748,12 @@ We have been notified about it. We will be adding new resources shortly")
755
748
  hooks(@main, :ip).should include(:logged_in?)
756
749
  end
757
750
 
758
- it "should ensure that Cloudfile is present" do
759
- hooks(@main, :ip).should include(:cloudfile_present?)
751
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
752
+ it "should ensure multiple_clouds check" do
753
+ @app.should_receive(:web_server_ip).and_return("11.11")
754
+ @app.should_receive(:mail_server_ip).and_return("22.22")
755
+ @main.should_receive(:multiple_clouds).and_return(@app)
756
+ invoke(@main, :ip)
760
757
  end
761
758
 
762
759
  context "on success" do
@@ -777,8 +774,8 @@ We have been notified about it. We will be adding new resources shortly")
777
774
  it "should raise an error if user does not have access to cloud" do
778
775
  exception = Shelly::Client::NotFoundException.new("resource" => "cloud")
779
776
  @client.stub(:app).and_raise(exception)
780
- $stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
781
- invoke(@main, :ip)
777
+ $stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile")
778
+ lambda { invoke(@main, :ip) }.should raise_error(SystemExit)
782
779
  end
783
780
  end
784
781
  end
@@ -803,13 +800,14 @@ We have been notified about it. We will be adding new resources shortly")
803
800
  hooks(@main, :setup).should include(:inside_git_repository?)
804
801
  end
805
802
 
806
- it "should ensure that cloudfile is present" do
807
- hooks(@main, :setup).should include(:cloudfile_present?)
803
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
804
+ it "should ensure multiple_clouds check" do
805
+ @main.should_receive(:multiple_clouds).and_return(@app)
806
+ invoke(@main, :setup)
808
807
  end
809
808
 
810
809
  it "should show info about adding remote and branch" do
811
- $stdout.should_receive(:puts).with("Investigating Cloudfile")
812
- $stdout.should_receive(:puts).with(green "Adding foo-staging cloud")
810
+ $stdout.should_receive(:puts).with(green "Setting up foo-staging cloud")
813
811
  $stdout.should_receive(:puts).with("git remote add foo-staging git_url")
814
812
  $stdout.should_receive(:puts).with("git fetch production")
815
813
  $stdout.should_receive(:puts).with("git checkout -b foo-staging --track foo-staging/master")
@@ -849,7 +847,7 @@ We have been notified about it. We will be adding new resources shortly")
849
847
  end
850
848
 
851
849
  context "and user answers no" do
852
- it "should display commands to perform manually " do
850
+ it "should display commands to perform manually" do
853
851
  @app.should_not_receive(:add_git_remote)
854
852
  @app.should_not_receive(:git_fetch_remote)
855
853
  @app.should_not_receive(:git_add_tracking_branch)
@@ -877,6 +875,15 @@ We have been notified about it. We will be adding new resources shortly")
877
875
  hooks(@main, :delete).should include(:logged_in?)
878
876
  end
879
877
 
878
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
879
+ it "should ensure multiple_clouds check" do
880
+ @client.stub(:delete)
881
+ @main.should_receive(:multiple_clouds).and_return(@app)
882
+ fake_stdin(["yes", "yes", "yes"]) do
883
+ invoke(@main, :delete)
884
+ end
885
+ end
886
+
880
887
  context "when cloud is given" do
881
888
  before do
882
889
  File.open("Cloudfile", 'w') {|f|
@@ -1021,8 +1028,11 @@ We have been notified about it. We will be adding new resources shortly")
1021
1028
  hooks(@main, :logs).should include(:logged_in?)
1022
1029
  end
1023
1030
 
1024
- it "should ensure that Cloudfile is present" do
1025
- hooks(@main, :logs).should include(:cloudfile_present?)
1031
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
1032
+ it "should ensure multiple_clouds check" do
1033
+ @client.stub(:application_logs).and_return(["log1"])
1034
+ @main.should_receive(:multiple_clouds).and_return(@app)
1035
+ invoke(@main, :logs)
1026
1036
  end
1027
1037
 
1028
1038
  it "should exit if user doesn't have access to clouds in Cloudfile" do
@@ -1033,40 +1043,12 @@ We have been notified about it. We will be adding new resources shortly")
1033
1043
  lambda { invoke(@main, :logs) }.should raise_error(SystemExit)
1034
1044
  end
1035
1045
 
1036
- context "single cloud in Cloudfile" do
1037
- it "should show logs for the cloud" do
1038
- @client.stub(:application_logs).and_return(["log1"])
1039
- $stdout.should_receive(:puts).with(green "Cloud foo-production:")
1040
- $stdout.should_receive(:puts).with(green "Instance 1:")
1041
- $stdout.should_receive(:puts).with("log1")
1042
- invoke(@main, :logs)
1043
- end
1044
- end
1045
-
1046
- context "multiple clouds in Cloudfile" do
1047
- before do
1048
- File.open("Cloudfile", 'w') {|f|
1049
- f.write("foo-staging:\nfoo-production:\n") }
1050
- end
1051
-
1052
- it "should show information to print logs for specific cloud and exit" do
1053
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
1054
- $stdout.should_receive(:puts).with("Select cloud using `shelly logs --cloud foo-production`")
1055
- $stdout.should_receive(:puts).with("Available clouds:")
1056
- $stdout.should_receive(:puts).with(" * foo-production")
1057
- $stdout.should_receive(:puts).with(" * foo-staging")
1058
- lambda { invoke(@main, :logs) }.should raise_error(SystemExit)
1059
- end
1060
-
1061
- it "should fetch from command line which cloud to start" do
1062
- @client.should_receive(:application_logs).with("foo-staging").
1063
- and_return(["log1"])
1064
- $stdout.should_receive(:puts).with(green "Cloud foo-staging:")
1065
- $stdout.should_receive(:puts).with(green "Instance 1:")
1066
- $stdout.should_receive(:puts).with("log1")
1067
- @main.options = {:cloud => "foo-staging"}
1068
- invoke(@main, :logs)
1069
- end
1046
+ it "should show logs for the cloud" do
1047
+ @client.stub(:application_logs).and_return(["log1"])
1048
+ $stdout.should_receive(:puts).with(green "Cloud foo-production:")
1049
+ $stdout.should_receive(:puts).with(green "Instance 1:")
1050
+ $stdout.should_receive(:puts).with("log1")
1051
+ invoke(@main, :logs)
1070
1052
  end
1071
1053
 
1072
1054
  context "multiple instances" do
@@ -1092,7 +1074,7 @@ We have been notified about it. We will be adding new resources shortly")
1092
1074
  Shelly::User.stub(:new).and_return(@user)
1093
1075
  @client.stub(:apps).and_return([{"code_name" => "foo-production"},
1094
1076
  {"code_name" => "foo-staging"}])
1095
- @app = Shelly::App.new
1077
+ @app = Shelly::App.new("foo-production")
1096
1078
  Shelly::App.stub(:new).and_return(@app)
1097
1079
  File.open("to_execute.rb", 'w') {|f| f.write("User.count") }
1098
1080
  end
@@ -1101,51 +1083,26 @@ We have been notified about it. We will be adding new resources shortly")
1101
1083
  hooks(@main, :execute).should include(:logged_in?)
1102
1084
  end
1103
1085
 
1104
- it "should ensure cloudfile present" do
1105
- hooks(@main, :execute).should include(:cloudfile_present?)
1086
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
1087
+ it "should ensure multiple_clouds check" do
1088
+ @client.should_receive(:command).with("foo-production", "User.count", :ruby).
1089
+ and_return({"result" => "3"})
1090
+ @main.should_receive(:multiple_clouds).and_return(@app)
1091
+ invoke(@main, :execute, "to_execute.rb")
1106
1092
  end
1107
1093
 
1108
- context "single cloud in Cloudfile" do
1109
- it "should execute code for the cloud" do
1110
- @client.should_receive(:command).with("foo-production", "User.count", :ruby).
1111
- and_return({"result" => "3"})
1112
- $stdout.should_receive(:puts).with("3")
1113
- invoke(@main, :execute, "to_execute.rb")
1114
- end
1094
+ it "should execute code for the cloud" do
1095
+ @client.should_receive(:command).with("foo-production", "User.count", :ruby).
1096
+ and_return({"result" => "3"})
1097
+ $stdout.should_receive(:puts).with("3")
1098
+ invoke(@main, :execute, "to_execute.rb")
1115
1099
  end
1116
1100
 
1117
- context "multiple clouds in Cloudfile" do
1118
- before do
1119
- File.open("Cloudfile", 'w') {|f|
1120
- f.write("foo-staging:\nfoo-production:\n") }
1121
- end
1122
-
1123
- it "should show information to print logs for specific cloud and exit" do
1124
- $stdout.should_receive(:puts).
1125
- with(red "You have multiple clouds in Cloudfile.")
1126
- $stdout.should_receive(:puts).
1127
- with("Select cloud using `shelly execute --cloud foo-production`")
1128
- $stdout.should_receive(:puts).with("Available clouds:")
1129
- $stdout.should_receive(:puts).with(" * foo-production")
1130
- $stdout.should_receive(:puts).with(" * foo-staging")
1131
- lambda { invoke(@main, :execute, "to_execute.rb") }.should raise_error(SystemExit)
1132
- end
1133
-
1134
- it "should fetch from command line which cloud to start" do
1135
- @client.should_receive(:command).with("foo-staging", "User.count", :ruby).
1136
- and_return({"result" => "3"})
1137
- $stdout.should_receive(:puts).with("3")
1138
- @main.options = {:cloud => "foo-staging"}
1139
- invoke(@main, :execute, "to_execute.rb")
1140
- end
1141
-
1142
- it "should run code when no file from parameter is found" do
1143
- @client.should_receive(:command).with("foo-staging", "2 + 2", :ruby).
1144
- and_return({"result" => "4"})
1145
- $stdout.should_receive(:puts).with("4")
1146
- @main.options = {:cloud => "foo-staging"}
1147
- invoke(@main, :execute, "2 + 2")
1148
- end
1101
+ it "should run code when no file from parameter is found" do
1102
+ @client.should_receive(:command).with("foo-production", "2 + 2", :ruby).
1103
+ and_return({"result" => "4"})
1104
+ $stdout.should_receive(:puts).with("4")
1105
+ invoke(@main, :execute, "2 + 2")
1149
1106
  end
1150
1107
 
1151
1108
  context "cloud is not in running state" do
@@ -1176,7 +1133,7 @@ We have been notified about it. We will be adding new resources shortly")
1176
1133
  @user = Shelly::User.new
1177
1134
  @user.stub(:token)
1178
1135
  Shelly::User.stub(:new).and_return(@user)
1179
- @app = Shelly::App.new
1136
+ @app = Shelly::App.new("foo-production")
1180
1137
  Shelly::App.stub(:new).and_return(@app)
1181
1138
  @main.stub(:rake_args).and_return(%w(db:migrate))
1182
1139
  end
@@ -1185,8 +1142,12 @@ We have been notified about it. We will be adding new resources shortly")
1185
1142
  hooks(@main, :rake).should include(:logged_in?)
1186
1143
  end
1187
1144
 
1188
- it "should ensure cloudfile present" do
1189
- hooks(@main, :execute).should include(:cloudfile_present?)
1145
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
1146
+ it "should ensure multiple_clouds check" do
1147
+ @client.should_receive(:command).with("foo-production", "db:migrate", :rake).
1148
+ and_return({"result" => "OK"})
1149
+ @main.should_receive(:multiple_clouds).and_return(@app)
1150
+ invoke(@main, :rake, "db:migrate")
1190
1151
  end
1191
1152
 
1192
1153
  it "should invoke :command on app with rake task" do
@@ -1227,45 +1188,26 @@ We have been notified about it. We will be adding new resources shortly")
1227
1188
  lambda { invoke(@main, :rake, "db:migrate") }.should raise_error(SystemExit)
1228
1189
  end
1229
1190
  end
1230
-
1231
- context "multiple clouds in Cloudfile" do
1232
- before do
1233
- File.open("Cloudfile", 'w') {|f|
1234
- f.write("foo-staging:\nfoo-production:\n") }
1235
- end
1236
-
1237
- it "should show information to run rake task for specific cloud and exit" do
1238
- $stdout.should_receive(:puts).
1239
- with(red "You have multiple clouds in Cloudfile.")
1240
- $stdout.should_receive(:puts).
1241
- with("Select cloud using `shelly rake db:migrate --cloud foo-production`")
1242
- $stdout.should_receive(:puts).with("Available clouds:")
1243
- $stdout.should_receive(:puts).with(" * foo-production")
1244
- $stdout.should_receive(:puts).with(" * foo-staging")
1245
- lambda { invoke(@main, :rake, "db:migrate") }.should raise_error(SystemExit)
1246
- end
1247
-
1248
- it "should fetch from command line for which cloud run rake task" do
1249
- @client.should_receive(:command).with("foo-staging", "db:migrate", :rake).
1250
- and_return({"result" => "3"})
1251
- $stdout.should_receive(:puts).with("3")
1252
- @main.options = {:cloud => "foo-staging"}
1253
- invoke(@main, :rake, "db:migrate")
1254
- end
1255
- end
1256
1191
  end
1257
1192
 
1258
1193
  describe "#redeploy" do
1259
1194
  before do
1260
1195
  @user = Shelly::User.new
1261
1196
  @client.stub(:token).and_return("abc")
1262
- @app = Shelly::App.new
1197
+ @app = Shelly::App.new("foo-production")
1263
1198
  Shelly::App.stub(:new).and_return(@app)
1264
1199
  FileUtils.mkdir_p("/projects/foo")
1265
1200
  Dir.chdir("/projects/foo")
1266
1201
  File.open("Cloudfile", 'w') { |f| f.write("foo-production:\n") }
1267
1202
  end
1268
1203
 
1204
+ # multiple_clouds is tested in main_spec.rb in describe "#start" block
1205
+ it "should ensure multiple_clouds check" do
1206
+ @client.stub(:redeploy)
1207
+ @main.should_receive(:multiple_clouds).and_return(@app)
1208
+ invoke(@main, :redeploy)
1209
+ end
1210
+
1269
1211
  it "should redeploy the application" do
1270
1212
  $stdout.should_receive(:puts).with(green "Redeploying your application for cloud 'foo-production'")
1271
1213
  @app.should_receive(:redeploy)
@@ -1308,27 +1250,5 @@ We have been notified about it. We will be adding new resources shortly")
1308
1250
  }.should raise_error(Shelly::Client::ConflictException)
1309
1251
  end
1310
1252
  end
1311
-
1312
- context "on multiple clouds in Cloudfile" do
1313
- before do
1314
- File.open("Cloudfile", 'w') { |f| f.write("foo-staging:\nfoo-production:\n") }
1315
- end
1316
-
1317
- it "should show information to redeploy application for specific cloud and exit" do
1318
- $stdout.should_receive(:puts).with(red "You have multiple clouds in Cloudfile.")
1319
- $stdout.should_receive(:puts).with("Select cloud using `shelly redeploy --cloud foo-production`")
1320
- $stdout.should_receive(:puts).with("Available clouds:")
1321
- $stdout.should_receive(:puts).with(" * foo-production")
1322
- $stdout.should_receive(:puts).with(" * foo-staging")
1323
- lambda { invoke(@main, :redeploy) }.should raise_error(SystemExit)
1324
- end
1325
-
1326
- it "should fetch from command line which cloud to redeploy application for" do
1327
- @client.should_receive(:redeploy).with("foo-staging")
1328
- $stdout.should_receive(:puts).with(green "Redeploying your application for cloud 'foo-staging'")
1329
- @main.options = {:cloud => "foo-staging"}
1330
- invoke(@main, :redeploy)
1331
- end
1332
- end
1333
1253
  end
1334
1254
  end