Class: Cucumber::Messages::Exception

Inherits:
Message
  • Object
show all
Defined in:
lib/cucumber/messages/exception.rb

Overview

Represents the Exception message in Cucumber’s message protocol.

A simplified representation of an exception

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

camelize, from_json, #to_h, #to_json

Constructor Details

#initialize(type: '', message: nil, stack_trace: nil) ⇒ Exception

Returns a new instance of Exception.



28
29
30
31
32
33
34
35
36
37
# File 'lib/cucumber/messages/exception.rb', line 28

def initialize(
  type: '',
  message: nil,
  stack_trace: nil
)
  @type = type
  @message = message
  @stack_trace = stack_trace
  super()
end

Instance Attribute Details

#messageObject (readonly)

The message of exception that caused this result. E.g. expected: “a” but was: “b”



21
22
23
# File 'lib/cucumber/messages/exception.rb', line 21

def message
  @message
end

#stack_traceObject (readonly)

The stringified stack trace of the exception that caused this result



26
27
28
# File 'lib/cucumber/messages/exception.rb', line 26

def stack_trace
  @stack_trace
end

#typeObject (readonly)

The type of the exception that caused this result. E.g. “Error” or “org.opentest4j.AssertionFailedError”



16
17
18
# File 'lib/cucumber/messages/exception.rb', line 16

def type
  @type
end

Class Method Details

.from_h(hash) ⇒ Object

Returns a new Exception from the given hash. If the hash keys are camelCased, they are properly assigned to the corresponding snake_cased attributes.

Cucumber::Messages::Exception.from_h(some_hash) # => #<Cucumber::Messages::Exception:0x... ...>


46
47
48
49
50
51
52
53
54
# File 'lib/cucumber/messages/exception.rb', line 46

def self.from_h(hash)
  return nil if hash.nil?

  new(
    type: hash[:type],
    message: hash[:message],
    stack_trace: hash[:stackTrace]
  )
end