Class: Cucumber::Messages::ExternalAttachment

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

Overview

Represents the ExternalAttachment message in Cucumber’s message protocol.

Represents an attachment that is stored externally rather than embedded in the message stream.

This message type is used for large attachments (e.g., video files) that are already on the filesystem and should not be loaded into memory. Instead of embedding the content, only a URL reference is stored.

A formatter or other consumer of messages may replace an Attachment with an ExternalAttachment if it makes sense to do so.

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(url: '', media_type: '', test_case_started_id: nil, test_step_id: nil, test_run_hook_started_id: nil, timestamp: nil) ⇒ ExternalAttachment

Returns a new instance of ExternalAttachment.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cucumber/messages/external_attachment.rb', line 53

def initialize(
  url: '',
  media_type: '',
  test_case_started_id: nil,
  test_step_id: nil,
  test_run_hook_started_id: nil,
  timestamp: nil
)
  @url = url
  @media_type = media_type
  @test_case_started_id = test_case_started_id
  @test_step_id = test_step_id
  @test_run_hook_started_id = test_run_hook_started_id
  @timestamp = timestamp
  super()
end

Instance Attribute Details

#media_typeObject (readonly)

The media type of the data. This can be any valid [IANA Media Type](www.iana.org/assignments/media-types/media-types.xhtml) as well as Cucumber-specific media types such as ‘text/x.cucumber.gherkin+plain` and `text/x.cucumber.stacktrace+plain`



31
32
33
# File 'lib/cucumber/messages/external_attachment.rb', line 31

def media_type
  @media_type
end

#test_case_started_idObject (readonly)

The identifier of the test case attempt if the attachment was created during the execution of a test step



36
37
38
# File 'lib/cucumber/messages/external_attachment.rb', line 36

def test_case_started_id
  @test_case_started_id
end

#test_run_hook_started_idObject (readonly)

The identifier of the test run hook execution if the attachment was created during the execution of a test run hook



46
47
48
# File 'lib/cucumber/messages/external_attachment.rb', line 46

def test_run_hook_started_id
  @test_run_hook_started_id
end

#test_step_idObject (readonly)

The identifier of the test step if the attachment was created during the execution of a test step



41
42
43
# File 'lib/cucumber/messages/external_attachment.rb', line 41

def test_step_id
  @test_step_id
end

#timestampObject (readonly)

When the attachment was created



51
52
53
# File 'lib/cucumber/messages/external_attachment.rb', line 51

def timestamp
  @timestamp
end

#urlObject (readonly)

A URL where the attachment can be retrieved. This could be a file:// URL for local filesystem paths, or an http(s):// URL for remote resources.



23
24
25
# File 'lib/cucumber/messages/external_attachment.rb', line 23

def url
  @url
end

Class Method Details

.from_h(hash) ⇒ Object

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

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


77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cucumber/messages/external_attachment.rb', line 77

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

  new(
    url: hash[:url],
    media_type: hash[:mediaType],
    test_case_started_id: hash[:testCaseStartedId],
    test_step_id: hash[:testStepId],
    test_run_hook_started_id: hash[:testRunHookStartedId],
    timestamp: Timestamp.from_h(hash[:timestamp])
  )
end