Class: ExpectContext
- Inherits:
-
Object
- Object
- ExpectContext
- Includes:
- LogStash::Util::Loggable
- Defined in:
- lib/logstash/filters/ruby/script/expect_context.rb
Overview
Handle expect blocks inside of test blocks
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #execute(events) ⇒ Object
-
#initialize(test_context, name, block) ⇒ ExpectContext
constructor
A new instance of ExpectContext.
- #to_s ⇒ Object
Constructor Details
#initialize(test_context, name, block) ⇒ ExpectContext
Returns a new instance of ExpectContext.
7 8 9 10 11 |
# 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/logstash/filters/ruby/script/expect_context.rb', line 5 def name @name end |
Instance Method Details
#execute(events) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/logstash/filters/ruby/script/expect_context.rb', line 17 def execute(events) begin if @block.call(events) return :passed else result = :failed = "***TEST FAILURE FOR: '#{@test_context.name} #{@name}'***" log_hash = {} end rescue => e result = :errored = "***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(, log_hash) result end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/logstash/filters/ruby/script/expect_context.rb', line 13 def to_s "<Expect #{@test_context.name}/#{self.name}>" end |