spec/shelly/cli/main_spec.rb in shelly-0.0.25 vs spec/shelly/cli/main_spec.rb in shelly-0.0.26
- 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 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
@@ -163,11 +164,12 @@
describe "#login" do
before do
@user = Shelly::User.new
@user.stub(:upload_ssh_key)
@client.stub(:token).and_return("abc")
- @client.stub(:apps).and_return([{"code_name" => "abc"}, {"code_name" => "fooo"}])
+ @client.stub(:apps).and_return([{"code_name" => "abc", "state" => "running"},
+ {"code_name" => "fooo", "state" => "no_code"},])
Shelly::User.stub(:new).and_return(@user)
end
it "should ask about email and password" do
fake_stdin(["megan@example.com", "secret"]) do
@@ -199,12 +201,12 @@
end
end
it "should display list of applications to which user has access" do
$stdout.should_receive(:puts).with("\e[32mYou have following clouds available:\e[0m")
- $stdout.should_receive(:puts).with(" abc")
- $stdout.should_receive(:puts).with(" fooo")
+ $stdout.should_receive(:puts).with(/ abc\s+\| running/)
+ $stdout.should_receive(:puts).with(/ fooo\s+\| no code/)
fake_stdin(["megan@example.com", "secret"]) do
@main.login
end
end
end
@@ -393,8 +395,50 @@
$stdout.should_receive(:puts).with(" git push production master")
fake_stdin(["foooo", "none"]) do
@main.add
end
end
+ end
+
+ describe "#list" do
+ before do
+ @user = Shelly::User.new
+ @client.stub(:token).and_return("abc")
+ @client.stub(:apps).and_return([{"code_name" => "abc", "state" => "running"},
+ {"code_name" => "fooo", "state" => "deploy_failed"}])
+ Shelly::User.stub(:new).and_return(@user)
+ end
+
+ it "should display user's clouds" do
+ $stdout.should_receive(:puts).with("\e[32mYou have following clouds available:\e[0m")
+ $stdout.should_receive(:puts).with(/abc\s+\| running/)
+ $stdout.should_receive(:puts).with(/fooo\s+\| deploy failed \(Support has been notified\)/)
+ @main.list
+ end
+
+ it "should display info that user has no clouds" do
+ @client.stub(:apps).and_return([])
+ $stdout.should_receive(:puts).with("\e[32mYou have no clouds yet\e[0m")
+ @main.list
+ end
+
+ it "should have a 'status' alias" do
+ @client.stub(:apps).and_return([])
+ $stdout.should_receive(:puts).with("\e[32mYou have no clouds yet\e[0m")
+ Shelly::CLI::Main.start(["status"])
+ end
+
+ context "on failure" do
+ it "should display info that user is not logged in" do
+ body = {"message" => "Unauthorized"}
+ error = Shelly::Client::APIError.new(body.to_json)
+ @client.stub(:token).and_raise(error)
+ $stdout.should_receive(:puts).with("\e[31mYou are not logged in, use `shelly login`\e[0m")
+ lambda {
+ @main.list
+ }.should raise_error(SystemExit)
+ end
+ end
+
end
end