class ExpectContext

Handle expect blocks inside of test blocks

Attributes

name[R]

Public Class Methods

new(test_context, name, block) click to toggle source
# File lib/logstash/filters/ruby/script/expect_context.rb, line 7
def initialize(test_context, name, block)
  @test_context = test_context
  @name = name
  @block = block
end

Public Instance Methods

execute(events) click to toggle source
# File lib/logstash/filters/ruby/script/expect_context.rb, line 17
def execute(events)
  begin
    if @block.call(events)
      return :passed
    else
      result = :failed
      message = "***TEST FAILURE FOR: '#{@test_context.name} #{@name}'***"
      log_hash = {}
    end
  rescue => e
    result = :errored
    message = "***TEST RAISED ERROR: '#{@test_context.name} #{@name}'***"
    log_hash = { "exception" => e.inspect, "backtrace" => e.backtrace }
  end
  script_path = @test_context.script_context.script.script_path
  log_hash.merge!({
    :parameters => @test_context.parameters,
    :in_events => @test_context.in_events.map(&:to_hash_with_metadata),
    :results => events.map(&:to_hash_with_metadata)
  })
  logger.error(message, log_hash)
  result
end
to_s() click to toggle source
# File lib/logstash/filters/ruby/script/expect_context.rb, line 13
def to_s
  "<Expect #{@test_context.name}/#{self.name}>"
end