diff options
Diffstat (limited to 'spec/lib/urkel/connection_spec.rb')
| -rw-r--r-- | spec/lib/urkel/connection_spec.rb | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/spec/lib/urkel/connection_spec.rb b/spec/lib/urkel/connection_spec.rb index ffd0ca5..509e2e4 100644 --- a/spec/lib/urkel/connection_spec.rb +++ b/spec/lib/urkel/connection_spec.rb @@ -5,6 +5,18 @@ module Urkel subject { Connection.new(configuration) } describe "#publish" do + let(:hostname) { Socket.gethostname } + let(:error_hash) do + { + "error"=> + { + "message" => error.message, + "hostname" => hostname, + "error_type" => error.class.name, + "backtrace" => error.backtrace.last + } + } + end let(:error) do begin 1/0 @@ -15,21 +27,26 @@ module Urkel context "given proper credentials" do let(:configuration) { Configuration.new('http://localhost:3000', '02513a35-b875-40a1-a1fc-f2d2582bdcc5') } - let(:hostname) { Socket.gethostname } it 'publishes a new error' do - stub_request(:post, "http://localhost:3000/api/v1/failures"). - with(body: { - "error"=> - { - "message" => error.message, - "hostname" => hostname, - "error_type" => error.class.name, - "backtrace" => error.backtrace - } - }, :headers => { 'Authorization'=>'Token token=02513a35-b875-40a1-a1fc-f2d2582bdcc5' }) + stub_request(:post, "http://localhost:3000/api/v1/failures") + .with(body: error_hash, headers: { 'Authorization'=>'Token token=02513a35-b875-40a1-a1fc-f2d2582bdcc5' }) .to_return(status: 200, body: "", headers: {}) - expect(subject.publish(error)).to be_truthy + expect(subject.publish(error)).to be_truthy + expect(subject.publish!(error)).to be_truthy + end + end + + context "when invalid credentials" do + let(:configuration) { Configuration.new('http://localhost:3000', 'blah') } + + it 'raises a meaningful error' do + stub_request(:post, "http://localhost:3000/api/v1/failures") + .with(body: error_hash, headers: { 'Authorization' => 'Token token=blah' }) + .to_return(status: 401, body: "HTTP Token: Access denied.", headers: {}) + + expect(subject.publish(error)).to be_falsey + expect(-> { subject.publish!(error) }).to raise_error(InvalidAPITokenError) end end end |
