1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-01-09 07:11:31 +00:00
rackstash/spec/rackstash/adapters/adapter_spec.rb
Holger Just b228494d14 Raise a custom Rackstash::NotImplementedHereError instead of NotImplementedError
Using the core `NotInmplementedError` is not desireable since its
documentation includes:

> Note that if `fork` raises a `NotImplementedError`, then
> `respond_to?(:fork)` returns `false`.

Since we are responding to the method but still raise an error, our
usage of the exception does not fulfill its documentation.

A custom error instead of a default `NoMethodError` is still desireable
since it significantly helps with debugging. With a different Exception,
we make it clear that a method is expected to be there and just wasn't
implemented by a subclass as opposed to the caller just using an object
wrong and calling entirely unexpected methods on it.
2017-08-01 12:28:58 +02:00

55 lines
1.2 KiB
Ruby

# frozen_string_literal: true
# Copyright 2017 Holger Just
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE.txt file for details.
require 'spec_helper'
require 'rackstash/adapters/adapter'
describe Rackstash::Adapters::Adapter do
let(:adapter) { described_class.new }
describe '#initialize' do
it 'accepts any arguments' do
described_class.new
described_class.new(:foo)
described_class.new(123, [:foo])
end
end
describe '.default_encoder' do
it 'returns an encoder' do
expect(adapter.default_encoder).to respond_to(:encode)
end
end
describe '#close' do
it 'does nothing' do
expect(adapter.close).to be nil
end
end
describe '#reopen' do
it 'does nothing' do
expect(adapter.reopen).to be nil
end
end
describe '#write' do
it 'calls write_single' do
expect(adapter).to receive(:write_single).with('a log line')
adapter.write('a log line')
end
end
describe '#write_single' do
it 'is not implemented in the abstract base class' do
expect { adapter.write('something') }
.to raise_error(Rackstash::NotImplementedHereError)
end
end
end