spec/shelly/cli/main_spec.rb in shelly-0.0.26 vs spec/shelly/cli/main_spec.rb in shelly-0.0.27
- old
+ new
@@ -23,10 +23,11 @@
it "should display available commands" do
expected = <<-OUT
Tasks:
shelly add # Adds new cloud to Shelly Cloud
shelly help [TASK] # Describe available tasks or one specific task
+ shelly ip # Lists clouds IP's
shelly list # Lists all your clouds
shelly login [EMAIL] # Logs user in to Shelly Cloud
shelly register [EMAIL] # Registers new user account on Shelly Cloud
shelly user <command> # Manages users using this cloud
shelly version # Displays shelly version
@@ -437,8 +438,61 @@
@main.list
}.should raise_error(SystemExit)
end
end
+ end
+
+ describe "#ips" do
+ before do
+ File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
+ Shelly::App.stub(:inside_git_repository?).and_return(true)
+ end
+
+ it "should exit with message if command run outside git repository" do
+ Shelly::App.stub(:inside_git_repository?).and_return(false)
+ $stdout.should_receive(:puts).with("\e[31mMust be run inside your project git repository\e[0m")
+ lambda {
+ @main.ip
+ }.should raise_error(SystemExit)
+ end
+
+ it "should exit with message if there is no Cloudfile" do
+ File.delete("Cloudfile")
+ $stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
+ lambda {
+ @main.ip
+ }.should raise_error(SystemExit)
+ end
+
+ context "on success" do
+ it "should display mail and web server ip's" do
+ @client.should_receive(:apps).and_return([{"code_name" => "foo-production"},{"code_name" => "foo-staging"}])
+ @client.stub(:apps_ips).and_return(response)
+ $stdout.should_receive(:puts).with("Cloud foo-production:")
+ $stdout.should_receive(:puts).with("Web server IP : 22.22.22.22")
+ $stdout.should_receive(:puts).with("Mail server IP: 11.11.11.11")
+ @main.ip
+ end
+ end
+
+ def response
+ [{'code_name' => 'foo-production', 'mail_server_ip' => '11.11.11.11', 'web_server_ip' => '22.22.22.22'}]
+ end
+
+ context "on failure" do
+ it "should raise an error if user is not in git repository" do
+ Shelly::App.stub(:inside_git_repository?).and_return(false)
+ $stdout.should_receive(:puts).with("\e[31mMust be run inside your project git repository\e[0m")
+ lambda { @main.ip }.should raise_error(SystemExit)
+ end
+
+ it "should raise an error if user does not have access to cloud" do
+ @client.should_receive(:apps).and_return([{"code_name" => "foo-production"}])
+ @client.stub(:apps_users).and_return(response)
+ $stdout.should_receive(:puts).with("\e[31mYou have no access to 'foo-staging' cloud defined in Cloudfile\e[0m")
+ lambda { @main.ip }.should raise_error(SystemExit)
+ end
+ end
end
end