Class: Cucumber::Messages::Attachment

Inherits:
Message show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.deserializers.rb

Overview

Represents the Attachment message in Cucumber’s message protocol.

//// Attachments (parse errors, execution errors, screenshots, links…)

*

An attachment represents any kind of data associated with a line in a
[Source](#io.cucumber.messages.Source) file. It can be used for:

* Syntax errors during parse time
* Screenshots captured and attached during execution
* Logs captured and attached during execution

It is not to be used for runtime errors raised/thrown during execution. This
is captured in `TestResult`.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Message::Utils

included

Methods included from Message::Serialization

#to_h, #to_json

Methods included from Message::Deserialization

included

Constructor Details

#initialize(body: '', content_encoding: AttachmentContentEncoding::IDENTITY, file_name: nil, media_type: '', source: nil, test_case_started_id: nil, test_step_id: nil, url: nil) ⇒ Attachment

Returns a new instance of Attachment.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb', line 87

def initialize(
  body: '',
  content_encoding: AttachmentContentEncoding::IDENTITY,
  file_name: nil,
  media_type: '',
  source: nil,
  test_case_started_id: nil,
  test_step_id: nil,
  url: nil
)
  @body = body
  @content_encoding = content_encoding
  @file_name = file_name
  @media_type = media_type
  @source = source
  @test_case_started_id = test_case_started_id
  @test_step_id = test_step_id
  @url = url
end

Instance Attribute Details

#bodyObject (readonly)

*

The body of the attachment. If `contentEncoding` is `IDENTITY`, the attachment
is simply the string. If it's `BASE64`, the string should be Base64 decoded to
obtain the attachment.


35
36
37
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb', line 35

def body
  @body
end

#content_encodingObject (readonly)

*

Whether to interpret `body` "as-is" (IDENTITY) or if it needs to be Base64-decoded (BASE64).

Content encoding is *not* determined by the media type, but rather by the type
of the object being attached:

- string => IDENTITY
- byte array => BASE64
- stream => BASE64


48
49
50
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb', line 48

def content_encoding
  @content_encoding
end

#file_nameObject (readonly)

*

Suggested file name of the attachment. (Provided by the user as an argument to `attach`)


54
55
56
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb', line 54

def file_name
  @file_name
end

#media_typeObject (readonly)

*

The media type of the data. This can be any valid
[IANA Media Type](https://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`


63
64
65
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb', line 63

def media_type
  @media_type
end

#sourceObject (readonly)

Returns the value of attribute source.



65
66
67
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb', line 65

def source
  @source
end

#test_case_started_idObject (readonly)

Returns the value of attribute test_case_started_id.



67
68
69
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb', line 67

def test_case_started_id
  @test_case_started_id
end

#test_step_idObject (readonly)

Returns the value of attribute test_step_id.



69
70
71
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb', line 69

def test_step_id
  @test_step_id
end

#urlObject (readonly)

*

A URL where the attachment can be retrieved. This field should not be set by Cucumber.
It should be set by a program that reads a message stream and does the following for
each Attachment message:

- Writes the body (after base64 decoding if necessary) to a new file.
- Sets `body` and `contentEncoding` to `null`
- Writes out the new attachment message

This will result in a smaller message stream, which can improve performance and
reduce bandwidth of message consumers. It also makes it easier to process and download attachments
separately from reports.


85
86
87
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.dtos.rb', line 85

def url
  @url
end

Class Method Details

.from_h(hash) ⇒ Object

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

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


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages.deserializers.rb', line 20

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

  self.new(
    body: hash[:body],
    content_encoding: hash[:contentEncoding],
    file_name: hash[:fileName],
    media_type: hash[:mediaType],
    source: Source.from_h(hash[:source]),
    test_case_started_id: hash[:testCaseStartedId],
    test_step_id: hash[:testStepId],
    url: hash[:url],
  )
end