mirror of
https://github.com/meineerde/rackstash.git
synced 2026-02-01 01:37:12 +00:00
Replace specific class-under-test with described_class in all specs
This commit is contained in:
parent
b6768c6547
commit
ca339a84fa
@ -10,13 +10,13 @@ require 'spec_helper'
|
||||
require 'rackstash/adapters/adapter'
|
||||
|
||||
describe Rackstash::Adapters::Adapter do
|
||||
let(:adapter) { Rackstash::Adapters::Adapter.new }
|
||||
let(:adapter) { described_class.new }
|
||||
|
||||
describe '#initialize' do
|
||||
it 'accepts any arguments' do
|
||||
Rackstash::Adapters::Adapter.new
|
||||
Rackstash::Adapters::Adapter.new(:foo)
|
||||
Rackstash::Adapters::Adapter.new(123, [:foo])
|
||||
described_class.new
|
||||
described_class.new(:foo)
|
||||
described_class.new(123, [:foo])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -11,23 +11,23 @@ require 'rackstash/adapters/callable'
|
||||
|
||||
describe Rackstash::Adapters::Callable do
|
||||
let(:callable) { ->(log) { log } }
|
||||
let(:adapter) { Rackstash::Adapters::Callable.new(callable) }
|
||||
let(:adapter) { described_class.new(callable) }
|
||||
|
||||
describe '#initialize' do
|
||||
it 'accepts a callable' do
|
||||
expect { Rackstash::Adapters::Callable.new(-> {}) }.not_to raise_error
|
||||
expect { Rackstash::Adapters::Callable.new(proc {}) }.not_to raise_error
|
||||
expect { Rackstash::Adapters::Callable.new(Struct.new(:call).new) }.not_to raise_error
|
||||
expect { described_class.new(-> {}) }.not_to raise_error
|
||||
expect { described_class.new(proc {}) }.not_to raise_error
|
||||
expect { described_class.new(Struct.new(:call).new) }.not_to raise_error
|
||||
|
||||
expect { Rackstash::Adapters::Callable.new { |log| log } }.not_to raise_error
|
||||
expect { described_class.new { |log| log } }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'rejects non-IO objects' do
|
||||
expect { Rackstash::Adapters::Callable.new(nil) }.to raise_error TypeError
|
||||
expect { Rackstash::Adapters::Callable.new('hello') }.to raise_error TypeError
|
||||
expect { Rackstash::Adapters::Callable.new(Object.new) }.to raise_error TypeError
|
||||
expect { Rackstash::Adapters::Callable.new([]) }.to raise_error TypeError
|
||||
expect { Rackstash::Adapters::Callable.new(Struct.new(:foo).new) }.to raise_error TypeError
|
||||
it 'rejects non-callable objects' do
|
||||
expect { described_class.new(nil) }.to raise_error TypeError
|
||||
expect { described_class.new('hello') }.to raise_error TypeError
|
||||
expect { described_class.new(Object.new) }.to raise_error TypeError
|
||||
expect { described_class.new([]) }.to raise_error TypeError
|
||||
expect { described_class.new(Struct.new(:foo).new) }.to raise_error TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -13,19 +13,19 @@ require 'rackstash/adapters/io'
|
||||
|
||||
describe Rackstash::Adapters::IO do
|
||||
let(:io) { StringIO.new }
|
||||
let(:adapter) { Rackstash::Adapters::IO.new(io) }
|
||||
let(:adapter) { described_class.new(io) }
|
||||
|
||||
describe '#initialize' do
|
||||
it 'accepts an IO object' do
|
||||
expect { Rackstash::Adapters::IO.new($stdout) }.not_to raise_error
|
||||
expect { Rackstash::Adapters::IO.new(StringIO.new) }.not_to raise_error
|
||||
expect { Rackstash::Adapters::IO.new(Tempfile.new('foo')) }.not_to raise_error
|
||||
expect { described_class.new($stdout) }.not_to raise_error
|
||||
expect { described_class.new(StringIO.new) }.not_to raise_error
|
||||
expect { described_class.new(Tempfile.new('foo')) }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'rejects non-IO objects' do
|
||||
expect { Rackstash::Adapters::IO.new(nil) }.to raise_error TypeError
|
||||
expect { Rackstash::Adapters::IO.new('hello') }.to raise_error TypeError
|
||||
expect { Rackstash::Adapters::IO.new(Object.new) }.to raise_error TypeError
|
||||
expect { described_class.new(nil) }.to raise_error TypeError
|
||||
expect { described_class.new('hello') }.to raise_error TypeError
|
||||
expect { described_class.new(Object.new) }.to raise_error TypeError
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -11,16 +11,16 @@ require 'rackstash/adapters'
|
||||
|
||||
describe Rackstash::Adapters do
|
||||
around(:each) do |example|
|
||||
types = Rackstash::Adapters.send(:adapter_types)
|
||||
schemes = Rackstash::Adapters.send(:adapter_schemes)
|
||||
types = described_class.send(:adapter_types)
|
||||
schemes = described_class.send(:adapter_schemes)
|
||||
|
||||
Rackstash::Adapters.instance_variable_set(:@adapter_types, nil)
|
||||
Rackstash::Adapters.instance_variable_set(:@adapter_schemes, nil)
|
||||
described_class.instance_variable_set(:@adapter_types, nil)
|
||||
described_class.instance_variable_set(:@adapter_schemes, nil)
|
||||
|
||||
example.run
|
||||
|
||||
Rackstash::Adapters.instance_variable_set(:@adapter_types, types)
|
||||
Rackstash::Adapters.instance_variable_set(:@adapter_schemes, schemes)
|
||||
described_class.instance_variable_set(:@adapter_types, types)
|
||||
described_class.instance_variable_set(:@adapter_schemes, schemes)
|
||||
end
|
||||
|
||||
let(:adapter) {
|
||||
@ -34,60 +34,60 @@ describe Rackstash::Adapters do
|
||||
describe '#register' do
|
||||
it 'can register a class' do
|
||||
expect {
|
||||
Rackstash::Adapters.register adapter, Class.new
|
||||
Rackstash::Adapters.register adapter, String
|
||||
Rackstash::Adapters.register adapter, Numeric
|
||||
Rackstash::Adapters.register adapter, Integer
|
||||
}.to change { Rackstash::Adapters.send(:adapter_types).size }
|
||||
described_class.register adapter, Class.new
|
||||
described_class.register adapter, String
|
||||
described_class.register adapter, Numeric
|
||||
described_class.register adapter, Integer
|
||||
}.to change { described_class.send(:adapter_types).size }
|
||||
.from(0).to(4)
|
||||
expect(Rackstash::Adapters.send(:adapter_schemes).size).to eql 0
|
||||
expect(described_class.send(:adapter_schemes).size).to eql 0
|
||||
end
|
||||
|
||||
it 'can register a class name (upper-case String)' do
|
||||
expect {
|
||||
Rackstash::Adapters.register adapter, '❤'
|
||||
Rackstash::Adapters.register adapter, ''
|
||||
Rackstash::Adapters.register adapter, 'Hello::World'
|
||||
}.to change { Rackstash::Adapters.send(:adapter_types).size }
|
||||
described_class.register adapter, '❤'
|
||||
described_class.register adapter, ''
|
||||
described_class.register adapter, 'Hello::World'
|
||||
}.to change { described_class.send(:adapter_types).size }
|
||||
.from(0).to(3)
|
||||
|
||||
# Registering 'Hello::World' a second time overwrites the first one
|
||||
expect {
|
||||
Rackstash::Adapters.register(adapter, 'Hello::World')
|
||||
}.not_to change { Rackstash::Adapters.send(:adapter_types).size }
|
||||
described_class.register(adapter, 'Hello::World')
|
||||
}.not_to change { described_class.send(:adapter_types).size }
|
||||
|
||||
expect(Rackstash::Adapters.send(:adapter_schemes).size).to eql 0
|
||||
expect(described_class.send(:adapter_schemes).size).to eql 0
|
||||
end
|
||||
|
||||
it 'can register a method name (symbol)' do
|
||||
expect {
|
||||
Rackstash::Adapters.register adapter, :foo
|
||||
}.to change { Rackstash::Adapters.send(:adapter_types).size }
|
||||
described_class.register adapter, :foo
|
||||
}.to change { described_class.send(:adapter_types).size }
|
||||
.from(0).to(1)
|
||||
expect(Rackstash::Adapters.send(:adapter_schemes).size).to eql 0
|
||||
expect(described_class.send(:adapter_schemes).size).to eql 0
|
||||
end
|
||||
|
||||
it 'can register a proc' do
|
||||
expect {
|
||||
Rackstash::Adapters.register adapter, ->(o) { o.respond_to?(:write) }
|
||||
Rackstash::Adapters.register adapter, -> {}
|
||||
}.to change { Rackstash::Adapters.send(:adapter_types).size }
|
||||
described_class.register adapter, ->(o) { o.respond_to?(:write) }
|
||||
described_class.register adapter, -> {}
|
||||
}.to change { described_class.send(:adapter_types).size }
|
||||
.from(0).to(2)
|
||||
expect(Rackstash::Adapters.send(:adapter_schemes).size).to eql 0
|
||||
expect(described_class.send(:adapter_schemes).size).to eql 0
|
||||
end
|
||||
|
||||
it 'can register a scheme (lower-case String)' do
|
||||
expect {
|
||||
Rackstash::Adapters.register adapter, 'customscheme'
|
||||
}.to change { Rackstash::Adapters.send(:adapter_schemes).size }
|
||||
described_class.register adapter, 'customscheme'
|
||||
}.to change { described_class.send(:adapter_schemes).size }
|
||||
.from(0).to(1)
|
||||
expect(Rackstash::Adapters.send(:adapter_types).size).to eql 0
|
||||
expect(described_class.send(:adapter_types).size).to eql 0
|
||||
end
|
||||
|
||||
it 'rejects invalid adapter classes' do
|
||||
expect { Rackstash::Adapters.register nil, :foo }
|
||||
expect { described_class.register nil, :foo }
|
||||
.to raise_error(TypeError)
|
||||
expect { Rackstash::Adapters.register Class.new, :foo }
|
||||
expect { described_class.register Class.new, :foo }
|
||||
.to raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
@ -97,7 +97,7 @@ describe Rackstash::Adapters do
|
||||
let(:device_class) { Class.new }
|
||||
|
||||
before do
|
||||
Rackstash::Adapters.register adapter, device_class
|
||||
described_class.register adapter, device_class
|
||||
end
|
||||
|
||||
it 'creates an adapter if the class was found' do
|
||||
@ -105,7 +105,7 @@ describe Rackstash::Adapters do
|
||||
|
||||
expect(device_class).to receive(:===).with(device).and_call_original
|
||||
expect(adapter).to receive(:new).with(device).and_call_original
|
||||
expect(Rackstash::Adapters[device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[device]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
|
||||
it 'creates an adapter if any parent class was found' do
|
||||
@ -113,12 +113,12 @@ describe Rackstash::Adapters do
|
||||
|
||||
expect(device_class).to receive(:===).with(inherited_device).and_call_original
|
||||
expect(adapter).to receive(:new).with(inherited_device).and_call_original
|
||||
expect(Rackstash::Adapters[inherited_device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[inherited_device]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
|
||||
it 'raises if no class was found' do
|
||||
expect(adapter).to_not receive(:new)
|
||||
expect { Rackstash::Adapters['foo'] }.to raise_error(ArgumentError)
|
||||
expect { described_class['foo'] }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
@ -127,7 +127,7 @@ describe Rackstash::Adapters do
|
||||
class SpecDevice; end
|
||||
class InheritedSpecDevice < SpecDevice; end
|
||||
|
||||
Rackstash::Adapters.register adapter, 'SpecDevice'
|
||||
described_class.register adapter, 'SpecDevice'
|
||||
end
|
||||
|
||||
after do
|
||||
@ -139,39 +139,39 @@ describe Rackstash::Adapters do
|
||||
device = SpecDevice.new
|
||||
|
||||
expect(adapter).to receive(:new).with(device).and_call_original
|
||||
expect(Rackstash::Adapters[device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[device]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
|
||||
it 'creates an adapter if any parent class was found' do
|
||||
inherited_device = InheritedSpecDevice.new
|
||||
|
||||
expect(adapter).to receive(:new).with(inherited_device).and_call_original
|
||||
expect(Rackstash::Adapters[inherited_device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[inherited_device]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
|
||||
it 'raises if no class was found' do
|
||||
expect(adapter).to_not receive(:new)
|
||||
expect { Rackstash::Adapters['foo'] }.to raise_error(ArgumentError)
|
||||
expect { described_class['foo'] }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a registered symbol' do
|
||||
before do
|
||||
Rackstash::Adapters.register adapter, :foo
|
||||
described_class.register adapter, :foo
|
||||
end
|
||||
|
||||
it 'creates an adapter if it responds to the registered method' do
|
||||
device = Struct.new(:foo).new('foo')
|
||||
|
||||
expect(adapter).to receive(:new).with(device).and_call_original
|
||||
expect(Rackstash::Adapters[device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[device]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
|
||||
it 'raises if it does not respond to the registered method' do
|
||||
device = Struct.new(:bar).new('bar')
|
||||
|
||||
expect(adapter).to_not receive(:new)
|
||||
expect { Rackstash::Adapters[device] }.to raise_error(ArgumentError)
|
||||
expect { described_class[device] }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
@ -180,52 +180,62 @@ describe Rackstash::Adapters do
|
||||
|
||||
it 'creates an adapter if the proc returns true' do
|
||||
checker = proc { true }
|
||||
Rackstash::Adapters.register adapter, checker
|
||||
described_class.register adapter, checker
|
||||
|
||||
expect(checker).to receive(:===).with(device).and_call_original
|
||||
expect(adapter).to receive(:new).with(device).and_call_original
|
||||
expect(Rackstash::Adapters[device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[device]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
|
||||
it 'does not create an adapter if the proc returns false' do
|
||||
checker = proc { false }
|
||||
Rackstash::Adapters.register adapter, checker
|
||||
described_class.register adapter, checker
|
||||
|
||||
expect(checker).to receive(:===).with(device).and_call_original
|
||||
expect(adapter).to_not receive(:new)
|
||||
expect { Rackstash::Adapters[device] }.to raise_error(ArgumentError)
|
||||
expect { described_class[device] }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a registered scheme' do
|
||||
before do
|
||||
Rackstash::Adapters.register adapter, 'dummy'
|
||||
described_class.register adapter, 'dummy'
|
||||
end
|
||||
|
||||
it 'creates an adapter from the scheme' do
|
||||
raw_uri = 'dummy://example.com'
|
||||
expect(adapter).to receive(:from_uri).with(URI(raw_uri)).and_call_original
|
||||
expect(Rackstash::Adapters[raw_uri]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[raw_uri]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
|
||||
it 'calls adapter.new if adapter.from_uri is not available' do
|
||||
plain_adapter = Class.new(Rackstash::Adapters::Adapter)
|
||||
described_class.register plain_adapter, 'dummy'
|
||||
|
||||
raw_uri = 'dummy://example.com'
|
||||
expect(plain_adapter).to receive(:new).with(URI(raw_uri)).and_call_original
|
||||
|
||||
expect(described_class[raw_uri]).to be_a plain_adapter
|
||||
end
|
||||
|
||||
it 'creates an adapter from a URI' do
|
||||
uri = URI('dummy://example.com')
|
||||
expect(adapter).to receive(:from_uri).with(uri).and_call_original
|
||||
expect(Rackstash::Adapters[uri]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[uri]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
|
||||
it 'raises if no scheme was found' do
|
||||
expect(adapter).to_not receive(:new)
|
||||
expect(adapter).to_not receive(:from_uri)
|
||||
expect { Rackstash::Adapters['unknown://example.com'] }
|
||||
expect { described_class['unknown://example.com'] }
|
||||
.to raise_error(ArgumentError)
|
||||
expect { Rackstash::Adapters[URI('unknown://example.com')] }
|
||||
expect { described_class[URI('unknown://example.com')] }
|
||||
.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
context 'and a registered class' do
|
||||
before do
|
||||
Rackstash::Adapters.register adapter, Object
|
||||
described_class.register adapter, Object
|
||||
end
|
||||
|
||||
it 'falls though on invalid URI' do
|
||||
@ -234,7 +244,7 @@ describe Rackstash::Adapters do
|
||||
expect(adapter).to_not receive(:from_uri)
|
||||
# from the fallback
|
||||
expect(adapter).to receive(:new).with(invalid_uri).and_call_original
|
||||
expect(Rackstash::Adapters[invalid_uri]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[invalid_uri]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
|
||||
it 'falls though if no scheme was found' do
|
||||
@ -242,7 +252,7 @@ describe Rackstash::Adapters do
|
||||
|
||||
expect(adapter).to_not receive(:from_uri)
|
||||
expect(adapter).to receive(:new).with(unknown_uri).and_call_original
|
||||
expect(Rackstash::Adapters[unknown_uri]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[unknown_uri]).to be_an Rackstash::Adapters::Adapter
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -250,10 +260,10 @@ describe Rackstash::Adapters do
|
||||
context 'with an existing adapter object' do
|
||||
it 'just returns the object' do
|
||||
adapter_instance = adapter.new
|
||||
Rackstash::Adapters.register adapter, Object
|
||||
described_class.register adapter, Object
|
||||
|
||||
expect(adapter).to_not receive(:new)
|
||||
expect(Rackstash::Adapters[adapter_instance]).to equal adapter_instance
|
||||
expect(described_class[adapter_instance]).to equal adapter_instance
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -12,7 +12,7 @@ require 'rackstash/buffer'
|
||||
describe Rackstash::Buffer do
|
||||
let(:buffer_options) { {} }
|
||||
let(:sink) { instance_double(Rackstash::Sink) }
|
||||
let(:buffer) { Rackstash::Buffer.new(sink, **buffer_options) }
|
||||
let(:buffer) { described_class.new(sink, **buffer_options) }
|
||||
|
||||
describe '#allow_empty?' do
|
||||
it 'defaults to false' do
|
||||
|
||||
@ -11,7 +11,7 @@ require 'rackstash/buffer_stack'
|
||||
|
||||
describe Rackstash::BufferStack do
|
||||
let(:sink) { instance_double(Rackstash::Sink) }
|
||||
let(:stack) { Rackstash::BufferStack.new(sink) }
|
||||
let(:stack) { described_class.new(sink) }
|
||||
|
||||
describe '#current' do
|
||||
it 'initializes a buffer' do
|
||||
|
||||
@ -10,7 +10,7 @@ require 'spec_helper'
|
||||
require 'rackstash/encoders/json'
|
||||
|
||||
describe Rackstash::Encoders::JSON do
|
||||
let(:encoder) { Rackstash::Encoders::JSON.new }
|
||||
let(:encoder) { described_class.new }
|
||||
|
||||
describe '#encode' do
|
||||
it 'formats the passed event hash as a JSON string' do
|
||||
|
||||
@ -10,7 +10,7 @@ require 'spec_helper'
|
||||
require 'rackstash/encoders/message'
|
||||
|
||||
describe Rackstash::Encoders::Message do
|
||||
let(:encoder) { Rackstash::Encoders::Message.new }
|
||||
let(:encoder) { described_class.new }
|
||||
|
||||
describe '#encode' do
|
||||
it 'gets the message from the event hash' do
|
||||
|
||||
@ -10,7 +10,7 @@ require 'spec_helper'
|
||||
require 'rackstash/encoders/raw'
|
||||
|
||||
describe Rackstash::Encoders::Raw do
|
||||
let(:encoder) { Rackstash::Encoders::Raw.new }
|
||||
let(:encoder) { described_class.new }
|
||||
|
||||
describe '#encode' do
|
||||
it 'passes the raw event through' do
|
||||
|
||||
@ -12,7 +12,7 @@ require 'rackstash/fields/array'
|
||||
require 'rackstash/fields/hash'
|
||||
|
||||
describe Rackstash::Fields::AbstractCollection do
|
||||
let(:collection) { Rackstash::Fields::AbstractCollection.new }
|
||||
let(:collection) { described_class.new }
|
||||
|
||||
def normalize(*args)
|
||||
collection.send(:normalize, *args)
|
||||
@ -42,7 +42,7 @@ describe Rackstash::Fields::AbstractCollection do
|
||||
expect(collection).to receive(:eql?).twice.and_call_original
|
||||
expect(collection).to receive(:==).twice.and_call_original
|
||||
|
||||
other = Rackstash::Fields::AbstractCollection.new
|
||||
other = described_class.new
|
||||
expect(collection).to eql other
|
||||
expect(collection).to eq other
|
||||
|
||||
@ -97,7 +97,7 @@ describe Rackstash::Fields::AbstractCollection do
|
||||
it 'returns the same hash for the same raw content' do
|
||||
collection.send(:raw=, [123, 'foo'])
|
||||
|
||||
collection2 = Rackstash::Fields::AbstractCollection.new
|
||||
collection2 = described_class.new
|
||||
collection2.send(:raw=, [123, 'foo'])
|
||||
|
||||
expect(collection.send(:raw)).not_to equal collection2.send(:raw)
|
||||
|
||||
@ -10,18 +10,18 @@ require 'spec_helper'
|
||||
require 'rackstash/fields/array'
|
||||
|
||||
describe Rackstash::Fields::Array do
|
||||
let(:array) { Rackstash::Fields::Array.new }
|
||||
let(:array) { described_class.new }
|
||||
|
||||
describe '#+' do
|
||||
it 'returns the addition of elements' do
|
||||
array[0] = 'existing'
|
||||
expect(array + ['existing', -> { 'new' }, [:nested]])
|
||||
.to contain_exactly('existing', 'existing', 'new', ['nested'])
|
||||
.and be_a(Rackstash::Fields::Array)
|
||||
.and be_a(described_class)
|
||||
end
|
||||
|
||||
it 'returns a new Array' do
|
||||
expect(array + [:foo]).to be_a(Rackstash::Fields::Array)
|
||||
expect(array + [:foo]).to be_a(described_class)
|
||||
expect(array + [:foo]).not_to equal array
|
||||
end
|
||||
end
|
||||
@ -34,7 +34,7 @@ describe Rackstash::Fields::Array do
|
||||
end
|
||||
|
||||
it 'returns a new Array' do
|
||||
expect(array - [:foo]).to be_a(Rackstash::Fields::Array).and be_empty
|
||||
expect(array - [:foo]).to be_a(described_class).and be_empty
|
||||
expect(array - [:foo]).not_to equal array
|
||||
end
|
||||
end
|
||||
@ -47,7 +47,7 @@ describe Rackstash::Fields::Array do
|
||||
end
|
||||
|
||||
it 'returns a new Array' do
|
||||
expect(array | [:foo]).to be_a(Rackstash::Fields::Array)
|
||||
expect(array | [:foo]).to be_a(described_class)
|
||||
expect(array | [:foo]).not_to equal array
|
||||
end
|
||||
end
|
||||
@ -60,7 +60,7 @@ describe Rackstash::Fields::Array do
|
||||
end
|
||||
|
||||
it 'returns a new Array' do
|
||||
expect(array & [:foo]).to be_a(Rackstash::Fields::Array).and be_empty
|
||||
expect(array & [:foo]).to be_a(described_class).and be_empty
|
||||
expect(array & [:foo]).not_to equal array
|
||||
end
|
||||
end
|
||||
@ -78,7 +78,7 @@ describe Rackstash::Fields::Array do
|
||||
end
|
||||
|
||||
it 'returns an array from start, end' do
|
||||
expect(array[1, 3]).to be_a Rackstash::Fields::Array
|
||||
expect(array[1, 3]).to be_a described_class
|
||||
expect(array[1, 3].to_ary).to eql %w[foo bar baz]
|
||||
|
||||
expect(array[2, 0].to_ary).to eql []
|
||||
@ -87,7 +87,7 @@ describe Rackstash::Fields::Array do
|
||||
end
|
||||
|
||||
it 'returns an array from a range' do
|
||||
expect(array[1..3]).to be_a Rackstash::Fields::Array
|
||||
expect(array[1..3]).to be_a described_class
|
||||
expect(array[1..3].to_ary).to eql %w[foo bar baz]
|
||||
|
||||
expect(array[2..4].to_ary).to eql %w[bar baz]
|
||||
@ -167,7 +167,7 @@ describe Rackstash::Fields::Array do
|
||||
end
|
||||
|
||||
it 'returns a nested array' do
|
||||
expect(array[2]).to be_a Rackstash::Fields::Array
|
||||
expect(array[2]).to be_a described_class
|
||||
|
||||
expect(array.as_json[2]).to be_instance_of ::Array
|
||||
expect(array.as_json[2]).to eql %w[v1 v2]
|
||||
@ -283,11 +283,11 @@ describe Rackstash::Fields::Array do
|
||||
array[0] = 'existing'
|
||||
expect(array.merge(['new', :existing, -> { 123 }]))
|
||||
.to contain_exactly('existing', 'new', 123)
|
||||
.and be_a(Rackstash::Fields::Array)
|
||||
.and be_a(described_class)
|
||||
end
|
||||
|
||||
it 'returns a new Array' do
|
||||
expect(array.merge([:foo])).to be_a(Rackstash::Fields::Array)
|
||||
expect(array.merge([:foo])).to be_a(described_class)
|
||||
expect(array.merge([:foo])).not_to equal array
|
||||
end
|
||||
|
||||
@ -348,7 +348,7 @@ describe Rackstash::Fields::Array do
|
||||
value = ['hello']
|
||||
array.push value
|
||||
|
||||
expect(array[0]).to be_a Rackstash::Fields::Array
|
||||
expect(array[0]).to be_a described_class
|
||||
expect(array[0].to_a).to eql value
|
||||
end
|
||||
|
||||
@ -400,7 +400,7 @@ describe Rackstash::Fields::Array do
|
||||
raw = [Time.now, 'foo']
|
||||
array = Rackstash::Fields::Array(raw)
|
||||
|
||||
expect(array).to be_a Rackstash::Fields::Array
|
||||
expect(array).to be_a described_class
|
||||
expect(array[0]).to be_a String
|
||||
expect(array[1]).to eql 'foo'
|
||||
end
|
||||
|
||||
@ -128,7 +128,7 @@ describe Rackstash::Fields::Hash do
|
||||
end
|
||||
|
||||
it 'returns a nested hash' do
|
||||
expect(hash['hash']).to be_instance_of Rackstash::Fields::Hash
|
||||
expect(hash['hash']).to be_instance_of described_class
|
||||
|
||||
expect(hash.as_json['hash']).to be_instance_of Hash
|
||||
expect(hash.as_json['hash']).to eql 'key' => 'nested value', 'number' => 42
|
||||
@ -200,7 +200,7 @@ describe Rackstash::Fields::Hash do
|
||||
hash['foo'] = ['bar']
|
||||
|
||||
new_hash = hash.deep_merge('beep' => :boop, 'foo' => [123])
|
||||
expect(new_hash).to be_a Rackstash::Fields::Hash
|
||||
expect(new_hash).to be_a described_class
|
||||
|
||||
expect(hash).not_to have_key 'beep'
|
||||
expect(hash['foo']).to contain_exactly 'bar'
|
||||
@ -283,7 +283,7 @@ describe Rackstash::Fields::Hash do
|
||||
it 'allows to merge forbidden fields in nested hashes' do
|
||||
hash.deep_merge!({ top: { 'forbidden' => 'value' } }, force: true)
|
||||
expect(hash['top'])
|
||||
.to be_a(Rackstash::Fields::Hash)
|
||||
.to be_a(described_class)
|
||||
.and have_key 'forbidden'
|
||||
end
|
||||
end
|
||||
@ -311,12 +311,12 @@ describe Rackstash::Fields::Hash do
|
||||
|
||||
hash.deep_merge!({ 'key' => [:foo, 'baz'] }, force: false)
|
||||
expect(hash['key'])
|
||||
.to be_a(Rackstash::Fields::Hash)
|
||||
.to be_a(described_class)
|
||||
.and have_key 'nested_key'
|
||||
|
||||
hash.deep_merge!({ 'key' => 123 }, force: false)
|
||||
expect(hash['key'])
|
||||
.to be_a(Rackstash::Fields::Hash)
|
||||
.to be_a(described_class)
|
||||
.and have_key 'nested_key'
|
||||
end
|
||||
|
||||
@ -325,7 +325,7 @@ describe Rackstash::Fields::Hash do
|
||||
expect(hash).to have_key 'key'
|
||||
|
||||
hash.deep_merge!({ 'key' => { nested: 'value' } }, force: false)
|
||||
expect(hash['key']).to be_a Rackstash::Fields::Hash
|
||||
expect(hash['key']).to be_a described_class
|
||||
end
|
||||
|
||||
it 'ignores forbidden fields' do
|
||||
@ -339,7 +339,7 @@ describe Rackstash::Fields::Hash do
|
||||
it 'allows to merge forbidden fields in nested hashes' do
|
||||
hash.deep_merge!({ top: { 'forbidden' => 'value' } }, force: false)
|
||||
expect(hash['top'])
|
||||
.to be_a(Rackstash::Fields::Hash)
|
||||
.to be_a(described_class)
|
||||
.and have_key 'forbidden'
|
||||
end
|
||||
end
|
||||
@ -473,10 +473,10 @@ describe Rackstash::Fields::Hash do
|
||||
end
|
||||
|
||||
it 'merges an empty hash with compatible arguments' do
|
||||
empty_hash = Rackstash::Fields::Hash.new
|
||||
empty_hash = described_class.new
|
||||
|
||||
expect(hash.merge!({})).to eql empty_hash
|
||||
expect(hash.merge!(Rackstash::Fields::Hash.new)).to eql empty_hash
|
||||
expect(hash.merge!(described_class.new)).to eql empty_hash
|
||||
end
|
||||
|
||||
it 'merges a normalized hash' do
|
||||
@ -572,7 +572,7 @@ describe Rackstash::Fields::Hash do
|
||||
it 'returns a new object' do
|
||||
new_hash = hash.merge(foo: :bar)
|
||||
|
||||
expect(new_hash).to be_instance_of Rackstash::Fields::Hash
|
||||
expect(new_hash).to be_instance_of described_class
|
||||
expect(new_hash).not_to equal hash
|
||||
|
||||
# The origiginal hash is not changed
|
||||
|
||||
@ -10,7 +10,7 @@ require 'spec_helper'
|
||||
require 'rackstash/fields/tags'
|
||||
|
||||
describe Rackstash::Fields::Tags do
|
||||
let(:tags) { Rackstash::Fields::Tags.new }
|
||||
let(:tags) { described_class.new }
|
||||
|
||||
describe '#<<' do
|
||||
it 'adds a single tag' do
|
||||
@ -74,7 +74,7 @@ describe Rackstash::Fields::Tags do
|
||||
it 'returns a new object' do
|
||||
new_tags = tags.merge ['hello']
|
||||
|
||||
expect(new_tags).to be_a Rackstash::Fields::Tags
|
||||
expect(new_tags).to be_a described_class
|
||||
expect(new_tags.tagged?('hello')).to be true
|
||||
expect(new_tags).not_to equal tags
|
||||
|
||||
@ -111,7 +111,7 @@ describe Rackstash::Fields::Tags do
|
||||
end
|
||||
|
||||
it 'accepts tags' do
|
||||
new_tags = Rackstash::Fields::Tags.new
|
||||
new_tags = described_class.new
|
||||
new_tags << 'foo'
|
||||
|
||||
tags.merge! [new_tags]
|
||||
@ -158,7 +158,7 @@ describe Rackstash::Fields::Tags do
|
||||
raw = [Time.now, 'foo']
|
||||
tags = Rackstash::Fields::Tags(raw)
|
||||
|
||||
expect(tags).to be_a Rackstash::Fields::Tags
|
||||
expect(tags).to be_a described_class
|
||||
expect(tags.to_a).to match [String, 'foo']
|
||||
end
|
||||
end
|
||||
|
||||
@ -11,7 +11,7 @@ require 'rackstash/flows'
|
||||
require 'rackstash/flow'
|
||||
|
||||
describe Rackstash::Flows do
|
||||
let(:flows) { Rackstash::Flows.new }
|
||||
let(:flows) { described_class.new }
|
||||
|
||||
def a_flow
|
||||
flow = instance_double('Rackstash::Flow')
|
||||
@ -21,17 +21,17 @@ describe Rackstash::Flows do
|
||||
|
||||
describe '#initialize' do
|
||||
it 'accepts a single flow' do
|
||||
list = Rackstash::Flows.new(a_flow)
|
||||
list = described_class.new(a_flow)
|
||||
expect(list.size).to eql 1
|
||||
end
|
||||
|
||||
it 'accepts a list of flows' do
|
||||
raw_flows = Array.new(3) { a_flow }
|
||||
|
||||
list_with_array = Rackstash::Flows.new(raw_flows)
|
||||
list_with_array = described_class.new(raw_flows)
|
||||
expect(list_with_array.size).to eql 3
|
||||
|
||||
list_with_splat = Rackstash::Flows.new(*raw_flows)
|
||||
list_with_splat = described_class.new(*raw_flows)
|
||||
expect(list_with_splat.size).to eql 3
|
||||
end
|
||||
|
||||
@ -39,7 +39,7 @@ describe Rackstash::Flows do
|
||||
flow_class = class_double('Rackstash::Flow').as_stubbed_const
|
||||
expect(flow_class).to receive(:new).with(:dummy).and_return(a_flow)
|
||||
|
||||
Rackstash::Flows.new(:dummy)
|
||||
described_class.new(:dummy)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ require 'time'
|
||||
require 'rackstash/formatter'
|
||||
|
||||
describe Rackstash::Formatter do
|
||||
let(:formatter) { Rackstash::Formatter.new }
|
||||
let(:formatter) { described_class.new }
|
||||
|
||||
it 'formats plain strings' do
|
||||
expect(formatter.call('ERROR', Time.now, 'progname', 'Hello')).to eql "Hello\n"
|
||||
@ -50,7 +50,7 @@ describe Rackstash::Formatter do
|
||||
end
|
||||
|
||||
describe Rackstash::RawFormatter do
|
||||
let(:formatter) { Rackstash::RawFormatter.new }
|
||||
let(:formatter) { described_class.new }
|
||||
|
||||
it 'returns the message' do
|
||||
msg = 'my message'
|
||||
|
||||
@ -10,8 +10,8 @@ require 'spec_helper'
|
||||
require 'rackstash/logger'
|
||||
|
||||
describe Rackstash::Logger do
|
||||
let(:targets) { double('targets') }
|
||||
let(:logger) { Rackstash::Logger.new(targets) }
|
||||
let(:target) { StringIO.new }
|
||||
let(:logger) { described_class.new(target) }
|
||||
|
||||
describe '#formatter' do
|
||||
it 'defaults to a Rackstash::Formatter' do
|
||||
|
||||
@ -23,7 +23,7 @@ describe Rackstash::Message do
|
||||
]
|
||||
|
||||
messages.each do |msg, clean|
|
||||
message = Rackstash::Message.new(msg)
|
||||
message = described_class.new(msg)
|
||||
expect(message.message).to eql clean
|
||||
expect(message.message).to be_frozen
|
||||
end
|
||||
@ -34,25 +34,25 @@ describe Rackstash::Message do
|
||||
latin_str = utf8_str.encode(Encoding::ISO8859_9)
|
||||
expect(latin_str.encoding).to eql Encoding::ISO8859_9
|
||||
|
||||
message = Rackstash::Message.new(latin_str)
|
||||
message = described_class.new(latin_str)
|
||||
expect(message.message).to eql utf8_str
|
||||
expect(message.message.encoding).to eql Encoding::UTF_8
|
||||
end
|
||||
|
||||
it 'does not raise an error on incompatible encodings' do
|
||||
binary = Digest::SHA256.digest('string')
|
||||
message = Rackstash::Message.new(binary)
|
||||
message = described_class.new(binary)
|
||||
|
||||
expect(message.message).to include '<27>'
|
||||
expect(message.message.encoding).to eql Encoding::UTF_8
|
||||
end
|
||||
|
||||
it 'accepts non-string objects' do
|
||||
message = Rackstash::Message.new(StandardError.new('An error'))
|
||||
message = described_class.new(StandardError.new('An error'))
|
||||
expect(message.message).to eql '#<StandardError: An error>'
|
||||
expect(message.message).to be_frozen
|
||||
|
||||
message = Rackstash::Message.new(:symbol)
|
||||
message = described_class.new(:symbol)
|
||||
expect(message.message).to eql ':symbol'
|
||||
expect(message.message).to be_frozen
|
||||
end
|
||||
@ -61,7 +61,7 @@ describe Rackstash::Message do
|
||||
str = 'hello'
|
||||
expect(str.encoding).to eql Encoding::UTF_8
|
||||
|
||||
message = Rackstash::Message.new(str)
|
||||
message = described_class.new(str)
|
||||
expect(message.message).to be_frozen
|
||||
expect(message.message).not_to equal str
|
||||
expect(message.message).to eql str
|
||||
@ -70,49 +70,49 @@ describe Rackstash::Message do
|
||||
|
||||
describe '#message' do
|
||||
it 'is aliased to to_str' do
|
||||
message = Rackstash::Message.new('hello world')
|
||||
message = described_class.new('hello world')
|
||||
expect(message.to_s).to eql 'hello world'
|
||||
end
|
||||
|
||||
it 'is aliased to to_str' do
|
||||
message = Rackstash::Message.new('hello world')
|
||||
message = described_class.new('hello world')
|
||||
expect(message.to_str).to eql 'hello world'
|
||||
end
|
||||
|
||||
it 'is aliased to as_json' do
|
||||
message = Rackstash::Message.new('hello world')
|
||||
message = described_class.new('hello world')
|
||||
expect(message.as_json).to eql 'hello world'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#severity' do
|
||||
it 'defaults to UNKNOWN' do
|
||||
expect(Rackstash::Message.new('').severity).to eql 5
|
||||
expect(described_class.new('').severity).to eql 5
|
||||
end
|
||||
|
||||
it 'accepts any non-negative integer' do
|
||||
expect(Rackstash::Message.new('', severity: 0).severity).to eql 0
|
||||
expect(Rackstash::Message.new('', severity: 1).severity).to eql 1
|
||||
expect(Rackstash::Message.new('', severity: 23).severity).to eql 23
|
||||
expect(Rackstash::Message.new('', severity: '3').severity).to eql 3
|
||||
expect(described_class.new('', severity: 0).severity).to eql 0
|
||||
expect(described_class.new('', severity: 1).severity).to eql 1
|
||||
expect(described_class.new('', severity: 23).severity).to eql 23
|
||||
expect(described_class.new('', severity: '3').severity).to eql 3
|
||||
end
|
||||
|
||||
it 'uses 0 for negative severities' do
|
||||
expect(Rackstash::Message.new('', severity: -1).severity).to eql 0
|
||||
expect(Rackstash::Message.new('', severity: -42).severity).to eql 0
|
||||
expect(described_class.new('', severity: -1).severity).to eql 0
|
||||
expect(described_class.new('', severity: -42).severity).to eql 0
|
||||
end
|
||||
|
||||
it 'does not accept non-integers' do
|
||||
expect { Rackstash::Message.new('', severity: nil) }.to raise_error TypeError
|
||||
expect { Rackstash::Message.new('', severity: [42]) }.to raise_error TypeError
|
||||
expect { Rackstash::Message.new('', severity: 'foo') }.to raise_error ArgumentError
|
||||
expect { described_class.new('', severity: nil) }.to raise_error TypeError
|
||||
expect { described_class.new('', severity: [42]) }.to raise_error TypeError
|
||||
expect { described_class.new('', severity: 'foo') }.to raise_error ArgumentError
|
||||
end
|
||||
end
|
||||
|
||||
describe '#progname' do
|
||||
it 'dup-freezes a mutable progname' do
|
||||
progname = String.new('a message')
|
||||
message = Rackstash::Message.new('', progname: progname)
|
||||
message = described_class.new('', progname: progname)
|
||||
|
||||
expect(message.progname).to eql progname
|
||||
expect(message.progname).not_to equal progname
|
||||
@ -120,18 +120,18 @@ describe Rackstash::Message do
|
||||
end
|
||||
|
||||
it 'defaults to PROGNAME' do
|
||||
expect(Rackstash::Message.new('').progname).to match %r{\Arackstash/v\d+(\..+)*\z}
|
||||
expect(described_class.new('').progname).to match %r{\Arackstash/v\d+(\..+)*\z}
|
||||
end
|
||||
end
|
||||
|
||||
describe '#length' do
|
||||
it 'returns the size if the message' do
|
||||
message = Rackstash::Message.new('hello world')
|
||||
message = described_class.new('hello world')
|
||||
expect(message.length).to eql 11
|
||||
end
|
||||
|
||||
it 'can use the #size alias' do
|
||||
message = Rackstash::Message.new('hello world')
|
||||
message = described_class.new('hello world')
|
||||
expect(message.size).to eql 11
|
||||
end
|
||||
end
|
||||
@ -139,16 +139,16 @@ describe Rackstash::Message do
|
||||
describe '#severity_label' do
|
||||
it 'returns the severity label' do
|
||||
expect(Rackstash).to receive(:severity_label).exactly(3).times.and_call_original
|
||||
expect(Rackstash::Message.new('', severity: 0).severity_label).to eql 'DEBUG'
|
||||
expect(Rackstash::Message.new('', severity: 2).severity_label).to eql 'WARN'
|
||||
expect(Rackstash::Message.new('', severity: 5).severity_label).to eql 'ANY'
|
||||
expect(described_class.new('', severity: 0).severity_label).to eql 'DEBUG'
|
||||
expect(described_class.new('', severity: 2).severity_label).to eql 'WARN'
|
||||
expect(described_class.new('', severity: 5).severity_label).to eql 'ANY'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#time' do
|
||||
it 'dups the time' do
|
||||
time = Time.now
|
||||
message = Rackstash::Message.new('', time: time)
|
||||
message = described_class.new('', time: time)
|
||||
|
||||
expect(message.time).to eql time
|
||||
expect(message.time).not_to equal time
|
||||
@ -158,15 +158,15 @@ describe Rackstash::Message do
|
||||
end
|
||||
|
||||
it 'defaults to Time.now.utc' do
|
||||
expect(Rackstash::Message.new('').time).to be_within(1).of(Time.now)
|
||||
expect(Rackstash::Message.new('').time).to be_frozen
|
||||
expect(Rackstash::Message.new('').time).to be_utc
|
||||
expect(described_class.new('').time).to be_within(1).of(Time.now)
|
||||
expect(described_class.new('').time).to be_frozen
|
||||
expect(described_class.new('').time).to be_utc
|
||||
end
|
||||
end
|
||||
|
||||
describe '#to_json' do
|
||||
it 'formats the message as JSON' do
|
||||
message = Rackstash::Message.new('hello world')
|
||||
message = described_class.new('hello world')
|
||||
expect(message.to_json).to eql '"hello world"'
|
||||
end
|
||||
end
|
||||
|
||||
@ -11,7 +11,7 @@ require 'rackstash/sink'
|
||||
|
||||
describe Rackstash::Sink do
|
||||
let(:targets) { [] }
|
||||
let(:sink) { Rackstash::Sink.new(targets) }
|
||||
let(:sink) { described_class.new(targets) }
|
||||
|
||||
describe '#initialize' do
|
||||
it 'accepts an array with targets' do
|
||||
@ -21,7 +21,7 @@ describe Rackstash::Sink do
|
||||
|
||||
it 'wraps a single target into an array' do
|
||||
target = Object.new
|
||||
expect(Rackstash::Sink.new(target).targets).to eql [target]
|
||||
expect(described_class.new(target).targets).to eql [target]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user