spec/api-client/dispatcher_spec.rb in api-client-1.5.4 vs spec/api-client/dispatcher_spec.rb in api-client-1.6.0
- old
+ new
@@ -1,103 +1,37 @@
require 'spec_helper'
describe ApiClient::Dispatcher do
- describe "#get" do
- before :each do
- FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "200")
- end
+ before :each do
+ stub_request(:any, "http://api.example.com/user/5").to_return(:body => "asd")
+ end
+ describe "#get" do
it "should return the request" do
- ApiClient::Dispatcher.get("http://api.example.com/user/5", {}).should be_a(Net::HTTPOK)
+ ApiClient::Dispatcher.get("http://api.example.com/user/5", {}).body.should == ("asd")
end
-
- context "when connection is refused" do
- before :each do
- FakeWeb.register_uri(:get, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
- end
-
- it "should return a ConnectionRefused exception" do
- lambda { ApiClient::Dispatcher.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
- end
- end
end
describe "#post" do
- before :each do
- FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201")
- end
-
it "should return the request" do
- ApiClient::Dispatcher.post("http://api.example.com/user/5", {}, {}).should be_a(Net::HTTPCreated)
+ ApiClient::Dispatcher.post("http://api.example.com/user/5", {}, {}).body.should == ("asd")
end
-
- context "when connection is refused" do
- before :each do
- FakeWeb.register_uri(:post, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
- end
-
- it "should return a ConnectionRefused exception" do
- lambda { ApiClient::Dispatcher.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
- end
- end
end
describe "#put" do
- before :each do
- FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "200")
- end
-
it "should return the request" do
- ApiClient::Dispatcher.put("http://api.example.com/user/5", {}, {}).should be_a(Net::HTTPOK)
+ ApiClient::Dispatcher.put("http://api.example.com/user/5", {}, {}).body.should == ("asd")
end
-
- context "when connection is refused" do
- before :each do
- FakeWeb.register_uri(:put, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
- end
-
- it "should return a ConnectionRefused exception" do
- lambda { ApiClient::Dispatcher.put('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
- end
- end
end
describe "#patch" do
- before :each do
- FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "200")
- end
-
it "should return the request" do
- ApiClient::Dispatcher.patch("http://api.example.com/user/5", {}, {}).should be_a(Net::HTTPOK)
+ ApiClient::Dispatcher.patch("http://api.example.com/user/5", {}, {}).body.should == ("asd")
end
+ end if ApiClient::Dispatcher.respond_to?(:patch)
- context "when connection is refused" do
- before :each do
- FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
- end
-
- it "should return a ConnectionRefused exception" do
- lambda { ApiClient::Dispatcher.patch('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
- end
- end
- end
-
describe "#delete" do
- before :each do
- FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :status => "200")
- end
-
it "should return the request" do
- ApiClient::Dispatcher.delete("http://api.example.com/user/5", {}).should be_a(Net::HTTPOK)
- end
-
- context "when connection is refused" do
- before :each do
- FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
- end
-
- it "should return a ConnectionRefused exception" do
- lambda { ApiClient::Dispatcher.delete('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
- end
+ ApiClient::Dispatcher.delete("http://api.example.com/user/5", {}).body.should == ("asd")
end
end
end
\ No newline at end of file