spec/shelly/client_spec.rb in shelly-0.1.1 vs spec/shelly/client_spec.rb in shelly-0.1.2
- old
+ new
@@ -197,16 +197,16 @@
response = @client.command("staging-foo", "2 + 2", :ruby)
response.should == {"result" => "4"}
end
end
- describe "#console" do
+ describe "#node_and_port" do
it "should fetch instance data from API" do
body = {:port => "40010", :node_ip => "10.0.0.10", :user => "foo-production"}
FakeWeb.register_uri(:get, api_url("apps/staging-foo/console"),
:body => body.to_json)
- response = @client.console("staging-foo")
+ response = @client.node_and_port("staging-foo")
response.should == {"port" => "40010", "node_ip" => "10.0.0.10", "user"=>"foo-production"}
end
end
describe "#send_invitation" do
@@ -361,59 +361,68 @@
context "on 401 response" do
it "should raise UnauthorizedException" do
@response.stub(:code).and_return(401)
@response.stub(:body).and_return("")
+ @response.stub(:headers).and_return({})
lambda {
@client.post("/")
}.should raise_error(Shelly::Client::UnauthorizedException)
end
end
context "on 404 response" do
it "should raise NotFoundException" do
@response.stub(:code).and_return(404)
@response.stub(:body).and_return("")
+ @response.stub(:headers).and_return({})
lambda {
@client.post("/")
}.should raise_error(Shelly::Client::NotFoundException)
end
end
context "on 409 response" do
it "should raise ConflictException" do
@response.stub(:code).and_return(409)
@response.stub(:body).and_return("")
+ @response.stub(:headers).and_return({})
lambda {
@client.post("/")
}.should raise_error(Shelly::Client::ConflictException)
end
end
context "on 422 response" do
it "should raise ValidationException" do
@response.stub(:code).and_return(422)
@response.stub(:body).and_return("")
+ @response.stub(:headers).and_return({})
lambda {
@client.post("/")
}.should raise_error(Shelly::Client::ValidationException)
end
end
context "on unsupported response" do
it "should raise generic APIException" do
@response.stub(:code).and_return(500)
@response.stub(:body).and_return("")
+ @response.stub(:headers).and_return({:x_request_id => "id123"})
lambda {
@client.post("/")
- }.should raise_error(Shelly::Client::APIException)
+ }.should raise_error { |error|
+ error.should be_a(Shelly::Client::APIException)
+ error.request_id.should == "id123"
+ }
end
end
it "should return empty hash if response is not a valid JSON" do
JSON.should_receive(:parse).with("").and_raise(JSON::ParserError)
@response.stub(:code).and_return("204")
@response.stub(:body).and_return("")
+ @response.stub(:headers).and_return({})
@client.post("/api/apps/flower").should == {}
end
end
describe "#headers" do