Revert "Revert "- use more let() statements instead of local scoping things""

This reverts commit 87c46c3345.
This commit is contained in:
Jordan Sissel 2013-08-13 18:30:09 -07:00
parent 1087b92b9c
commit 40217a8e7f

View file

@ -25,33 +25,33 @@ end
module LogStash
module RSpec
def config(configstr)
@config_str = configstr
let(:config) { configstr }
end # def config
def type(default_type)
@default_type = default_type
let(:default_type) { default_type }
end
def tags(*tags)
@default_tags = tags
let(:default_tags) { tags }
puts "Setting default tags: #{@default_tags}"
end
def sample(event, &block)
pipeline = LogStash::Pipeline.new(@config_str)
name = event.is_a?(String) ? event : event.to_json
def sample(sample_event, &block)
name = sample_event.is_a?(String) ? sample_event : sample_event.to_json
name = name[0..50] + "..." if name.length > 50
describe "\"#{name}\"" do
before :each do
# Coerce to an array of LogStash::Event
event = [event] unless event.is_a?(Array)
event = event.collect do |e|
let(:pipeline) { LogStash::Pipeline.new(config) }
let(:event) do
sample_event = [sample_event] unless sample_event.is_a?(Array)
next sample_event.collect do |e|
e = { "message" => e } if e.is_a?(String)
next LogStash::Event.new(e)
end
end
let(:results) do
results = []
count = 0
pipeline.instance_eval { @filters.each(&:register) }
@ -66,19 +66,19 @@ module LogStash
# TODO(sissel): pipeline flush needs to be implemented.
#results += pipeline.flush
@results = results
end # before :all
next results
end
subject { results.length > 1 ? results: results.first }
subject { @results.length > 1 ? @results: @results.first }
it("when processed", &block)
end
end # def sample
def input(&block)
config_str = @config_str
it "inputs" do
queue = Queue.new
pipeline = LogStash::Pipeline.new(config_str)
pipeline = LogStash::Pipeline.new(config)
#(class << pipeline; self; end).send(:define_method, :output) do |event|
#p :event => event
#queue << event
@ -94,11 +94,10 @@ module LogStash
require "logstash/pipeline"
# scoping is hard, let's go shopping!
config_str = @config_str
describe "agent(#{@agent_count}) #{caller[1]}" do
before :each do
start = ::Time.now
pipeline = LogStash::Pipeline.new(config_str)
pipeline = LogStash::Pipeline.new(config)
pipeline.run
@duration = ::Time.now - start
end