spec/shelly/cli/backup_spec.rb in shelly-0.0.40 vs spec/shelly/cli/backup_spec.rb in shelly-0.0.41.pre
- old
+ new
@@ -28,12 +28,11 @@
invoke(@backup, :list)
}.should raise_error(SystemExit)
end
it "should exit if user doesn't have access to cloud in Cloudfile" do
- response = {"message" => "Cloud foo-staging not found"}
- exception = Shelly::Client::APIError.new(response.to_json, 401)
+ exception = Shelly::Client::APIError.new(404, {"message" => "Couldn't find Cloud with"})
@client.stub(:database_backups).and_raise(exception)
$stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
lambda { invoke(@backup, :list) }.should raise_error(SystemExit)
end
@@ -102,21 +101,21 @@
invoke(@backup, :get, "last")
end
context "on backup not found" do
it "it should display error message" do
- exception = Shelly::Client::APIError.new({}.to_json, 404)
+ exception = Shelly::Client::APIError.new(404, {"message" => "Couldn't find Backup with"})
@client.stub(:database_backup).and_raise(exception)
$stdout.should_receive(:puts).with(red "Backup not found")
$stdout.should_receive(:puts).with("You can list available backups with 'shelly backup list' command")
invoke(@backup, :get, "better.tar.gz")
end
end
context "on unsupported exception" do
it "should re-raise it" do
- exception = Shelly::Client::APIError.new({}.to_json, 500)
+ exception = Shelly::Client::APIError.new(500)
@client.stub(:database_backup).and_raise(exception)
$stdout.should_not_receive(:puts).with(red "Backup not found")
$stdout.should_not_receive(:puts).with("You can list available backups with 'shelly backup list' command")
lambda {
invoke(@backup, :get, "better.tar.gz")
@@ -132,19 +131,18 @@
Dir.chdir("/projects/foo")
File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\n") }
end
it "should exit if user doesn't have access to cloud in Cloudfile" do
- response = {"message" => "Cloud foo-staging not found"}
- exception = Shelly::Client::APIError.new(response.to_json, 404)
+ exception = Shelly::Client::APIError.new(404, {"message" => "Cloud foo-staging not found"})
@client.stub(:request_backup).and_raise(exception)
$stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
lambda { invoke(@backup, :create) }.should raise_error(SystemExit)
end
it "should display errors and exit 1 when kind is not valid" do
response = {"message" => "Wrong KIND argument. User one of following: postgresql, mongodb, redis"}
- exception = Shelly::Client::APIError.new(response.to_json, 422)
+ exception = Shelly::Client::APIError.new(422, response)
@client.should_receive(:request_backup).and_raise(exception)
$stdout.should_receive(:puts).with(red response["message"])
lambda { invoke(@backup, :create) }.should raise_error(SystemExit)
end