spec/supports/helpers.rb in logstash-codec-multiline-2.0.5 vs spec/supports/helpers.rb in logstash-codec-multiline-2.0.6

- old
+ new

@@ -11,96 +11,98 @@ # Grab the in-memory-event multiline.flush { |event| events << event } events end -class LineListener - attr_reader :data, :path, :queue, :codec - # use attr_reader to define noop methods of Listener API - attr_reader :deleted, :created, :error, :eof #, :line +module Mlc + class LineListener + attr_reader :data, :path, :queue, :codec + # use attr_reader to define noop methods of Listener API + attr_reader :deleted, :created, :error, :eof #, :line - def initialize(queue, codec, path = '') - # store state from upstream - @queue = queue - @codec = codec - @path = path - end + def initialize(queue, codec, path = '') + # store state from upstream + @queue = queue + @codec = codec + @path = path + end - # receives a line from some upstream source - # and sends it downstream - def accept(data) - @codec.accept dup_adding_state(data) - end + # receives a line from some upstream source + # and sends it downstream + def accept(data) + @codec.accept dup_adding_state(data) + end - def process_event(event) - event["path"] = path - @queue << event - end + def process_event(event) + event["path"] = path + @queue << event + end - def add_state(data) - @data = data - self - end + def add_state(data) + @data = data + self + end - private + private - # dup and add state for downstream - def dup_adding_state(line) - self.class.new(queue, codec, path).add_state(line) + # dup and add state for downstream + def dup_adding_state(line) + self.class.new(queue, codec, path).add_state(line) + end end -end -class LineErrorListener < LineListener - def process_event(event) - raise StandardError.new("OMG, Daleks!") + class LineErrorListener < LineListener + def process_event(event) + raise StandardError.new("OMG, Daleks!") + end end -end -class MultilineRspec < LogStash::Codecs::Multiline - def internal_buffer - @buffer + class MultilineRspec < LogStash::Codecs::Multiline + def internal_buffer + @buffer + end + def buffer_size + @buffer.size + end end - def buffer_size - @buffer.size - end -end -class TracerBase - def initialize() @tracer = []; end + class TracerBase + def initialize() @tracer = []; end - def trace_for(symbol) - params = @tracer.assoc(symbol) - params.nil? ? false : params.last - end + def trace_for(symbol) + params = @tracer.assoc(symbol) + params.nil? ? false : params.last + end - def clear() - @tracer.clear() + def clear() + @tracer.clear() + end end -end -class MultilineLogTracer < TracerBase - def warn(*args) @tracer.push [:warn, args]; end - def error(*args) @tracer.push [:error, args]; end - def debug(*args) @tracer.push [:debug, args]; end - def info(*args) @tracer.push [:info, args]; end + class MultilineLogTracer < TracerBase + def warn(*args) @tracer.push [:warn, args]; end + def error(*args) @tracer.push [:error, args]; end + def debug(*args) @tracer.push [:debug, args]; end + def info(*args) @tracer.push [:info, args]; end - def info?() true; end - def debug?() true; end - def warn?() true; end - def error?() true; end -end + def info?() true; end + def debug?() true; end + def warn?() true; end + def error?() true; end + end -class AutoFlushTracer < TracerBase - def auto_flush() @tracer.push [:auto_flush, true]; end -end + class AutoFlushTracer < TracerBase + def auto_flush() @tracer.push [:auto_flush, true]; end + end -class IdentityMapCodecTracer < TracerBase - def clone() self.class.new; end - def decode(data) @tracer.push [:decode, data]; end - def encode(event) @tracer.push [:encode, event]; end - def flush(&block) @tracer.push [:flush, block.call]; end - def close() @tracer.push [:close, true]; end - def logger() @logger ||= MultilineLogTracer.new; end + class IdentityMapCodecTracer < TracerBase + def clone() self.class.new; end + def decode(data) @tracer.push [:decode, data]; end + def encode(event) @tracer.push [:encode, event]; end + def flush(&block) @tracer.push [:flush, block.call]; end + def close() @tracer.push [:close, true]; end + def logger() @logger ||= MultilineLogTracer.new; end + end end RSpec::Matchers.define(:have_an_empty_buffer) do match do |actual| actual.buffer_size.zero?