spec/shelly/cli/main_spec.rb in shelly-0.0.33 vs spec/shelly/cli/main_spec.rb in shelly-0.0.34
- old
+ new
@@ -170,11 +170,11 @@
end
context "on unsuccessful registration" do
it "should display errors and exit with 1" do
response = {"message" => "Validation Failed", "errors" => [["email", "has been already taken"]]}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 422)
@client.stub(:register_user).and_raise(exception)
$stdout.should_receive(:puts).with("\e[31mEmail has been already taken\e[0m")
lambda {
fake_stdin(["kate@example.com", "pass", "pass"]) do
@main.register
@@ -257,11 +257,11 @@
end
context "on unauthorized user" do
it "should exit with 1 and display error message" do
response = {"message" => "Unauthorized", "url" => "https://admin.winniecloud.com/users/password/new"}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 401)
@client.stub(:token).and_raise(exception)
$stdout.should_receive(:puts).with("\e[31mWrong email or password\e[0m")
$stdout.should_receive(:puts).with("\e[31mYou can reset password by using link:\e[0m")
$stdout.should_receive(:puts).with("\e[31mhttps://admin.winniecloud.com/users/password/new\e[0m")
lambda {
@@ -384,11 +384,11 @@
end
end
it "should display validation errors if they are any" do
response = {"message" => "Validation Failed", "errors" => [["code_name", "has been already taken"]]}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 422)
@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")
lambda {
@@ -473,11 +473,11 @@
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)
+ error = Shelly::Client::APIError.new(body.to_json, 401)
@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)
@@ -506,19 +506,19 @@
}.should raise_error(SystemExit)
end
it "should exit if user doesn't have access to clouds in Cloudfile" do
response = {"message" => "Cloud foo-production not found"}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 404)
@client.stub(:start_cloud).and_raise(exception)
$stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile")
lambda { @main.start }.should raise_error(SystemExit)
end
it "should exit if user is not logged in" do
response = {"message" => "Unauthorized"}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 401)
@client.stub(:token).and_raise(exception)
$stdout.should_receive(:puts).with(red "You are not logged in. To log in use:")
$stdout.should_receive(:puts).with(" shelly login")
lambda { @main.start }.should raise_error(SystemExit)
end
@@ -624,19 +624,19 @@
}.should raise_error(SystemExit)
end
it "should exit if user doesn't have access to clouds in Cloudfile" do
response = {"message" => "Cloud foo-production not found"}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 404)
@client.stub(:stop_cloud).and_raise(exception)
$stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile")
lambda { @main.stop }.should raise_error(SystemExit)
end
it "should exit if user is not logged in" do
response = {"message" => "Unauthorized"}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 401)
@client.stub(:token).and_raise(exception)
$stdout.should_receive(:puts).with(red "You are not logged in. To log in use:")
$stdout.should_receive(:puts).with(" shelly login")
lambda { @main.stop }.should raise_error(SystemExit)
end
@@ -715,11 +715,11 @@
lambda { @main.ip }.should raise_error(SystemExit)
end
it "should raise an error if user does not have access to cloud" do
response = {"message" => "Cloud foo-staging not found"}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 404)
@client.stub(:app_ips).and_raise(exception)
$stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
@main.ip
end
end
@@ -792,11 +792,11 @@
f.write("foo-staging:\n") }
end
it "should raise Client::APIError" do
response = {:message => "Application not found"}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 404)
@app.stub(:delete).and_raise(exception)
$stdout.should_receive(:puts).with("\e[31mApplication not found\e[0m")
lambda{
fake_stdin(["yes", "yes", "yes"]) do
@main.options = {:cloud => "foo-bar"}
@@ -852,19 +852,19 @@
}.should raise_error(SystemExit)
end
it "should exit if user doesn't have access to clouds in Cloudfile" do
response = {"message" => "Cloud foo-production not found"}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 404)
@client.stub(:application_logs).and_raise(exception)
$stdout.should_receive(:puts).
with(red "You have no access to cloud 'foo-production'")
lambda { @main.logs }.should raise_error(SystemExit)
end
it "should exit if user is not logged in" do
response = {"message" => "Unauthorized"}
- exception = Shelly::Client::APIError.new(response.to_json)
+ exception = Shelly::Client::APIError.new(response.to_json, 401)
@client.stub(:token).and_raise(exception)
$stdout.should_receive(:puts).
with(red "You are not logged in. To log in use:")
$stdout.should_receive(:puts).with(" shelly login")
lambda { @main.logs }.should raise_error(SystemExit)