spec/bugsnag/api/client_spec.rb in bugsnag-api-2.0.1 vs spec/bugsnag/api/client_spec.rb in bugsnag-api-2.0.2
- old
+ new
@@ -1,5 +1,6 @@
+require "spec_helper"
require "json"
describe Bugsnag::Api::Client do
before do
Bugsnag::Api.reset!
@@ -43,11 +44,11 @@
Bugsnag::Api.reset!
end
it "handles query params", :vcr do
Bugsnag::Api.get bugsnag_url("/"), :foo => "bar"
- assert_requested :get, "https://api.bugsnag.com?foo=bar"
+ assert_requested :get, bugsnag_url("?foo=bar")
end
it "handles headers" do
request = stub_get("/zen").
with(:query => {:foo => "bar"}, :headers => {:accept => "text/plain"})
@@ -79,24 +80,85 @@
client = Bugsnag::Api::Client.new(:auth_token => "example")
expect(client.token_authenticated?).to be true
end
end
+ describe ".deep_merge" do
+ it "returns a merged hash" do
+ client = Bugsnag::Api::Client.new(:auth_token => "example")
+ lhs = {
+ :foo => "foo"
+ }
+ rhs = {
+ :bar => "bar"
+ }
+ merged = client.deep_merge(lhs, rhs)
+ expect(merged).to_not eq(lhs)
+ expect(merged).to_not eq(rhs)
+ expect(merged).to eq({
+ :foo => "foo",
+ :bar => "bar"
+ })
+ end
+
+ it "favors rhs over lhs" do
+ client = Bugsnag::Api::Client.new(:auth_token => "example")
+ lhs = {
+ :foo => "foo"
+ }
+ rhs = {
+ :foo => "bar"
+ }
+ merged = client.deep_merge(lhs, rhs)
+ expect(merged).to eq({:foo => "bar"})
+ end
+
+ it "recursively merges hashes" do
+ client = Bugsnag::Api::Client.new(:auth_token => "example")
+ lhs = {
+ :foo => {
+ :bar => "bar"
+ }
+ }
+ rhs = {
+ :foo => {
+ :foobar => "foobar"
+ }
+ }
+ merged = client.deep_merge(lhs, rhs)
+ expect(merged).to eq(
+ {:foo => {
+ :bar => "bar",
+ :foobar => "foobar"
+ }
+ })
+ end
+ end
+
context "error handling" do
+
+ before do
+ VCR.turn_off!
+ end
+
+ after do
+ VCR.turn_on!
+ end
+
it "raises on 404" do
stub_get('/booya').to_return(:status => 404)
- expect { Bugsnag::Api.get('/booya') }.to raise_error(Bugsnag::Api::NotFound)
+ expect { Bugsnag::Api.get(bugsnag_url('/booya')) }.to raise_error(Bugsnag::Api::NotFound)
end
it "raises on 429" do
stub_get('/test').to_return(:status => 429)
- expect { Bugsnag::Api.get('/test') }.to raise_error(Bugsnag::Api::RateLimitExceeded)
+ expect { Bugsnag::Api.get(bugsnag_url('/test')) }.to raise_error(Bugsnag::Api::RateLimitExceeded)
end
it "raises on 500" do
stub_get('/boom').to_return(:status => 500)
- expect { Bugsnag::Api.get('/boom') }.to raise_error(Bugsnag::Api::InternalServerError)
+ expect { Bugsnag::Api.get(bugsnag_url('/boom')) }.to raise_error(Bugsnag::Api::InternalServerError)
end
it "includes an error" do
stub_get('/boom').
to_return \
@@ -104,11 +166,11 @@
:headers => {
:content_type => "application/json",
},
:body => {:error => "Comments must contain a message"}.to_json
begin
- Bugsnag::Api.get('/boom')
+ Bugsnag::Api.get(bugsnag_url('/boom'))
rescue Bugsnag::Api::UnprocessableEntity => e
expect(e.message).to include("Error: Comments must contain a message")
end
end
@@ -117,19 +179,19 @@
:status => 418,
:headers => {
:content_type => "application/json",
},
:body => {:message => "I'm a teapot"}.to_json
- expect { Bugsnag::Api.get('/user') }.to raise_error(Bugsnag::Api::ClientError)
+ expect { Bugsnag::Api.get(bugsnag_url('/user')) }.to raise_error(Bugsnag::Api::ClientError)
end
it "raises on unknown server errors" do
stub_get('/user').to_return \
:status => 509,
:headers => {
:content_type => "application/json",
},
:body => {:message => "Bandwidth exceeded"}.to_json
- expect { Bugsnag::Api.get('/user') }.to raise_error(Bugsnag::Api::ServerError)
+ expect { Bugsnag::Api.get(bugsnag_url('/user')) }.to raise_error(Bugsnag::Api::ServerError)
end
end
end