Method: Cucumber::Glue::ProtoWorld#attach

Defined in:
lib/cucumber/glue/proto_world.rb

#attach(file, media_type = nil, filename = nil) ⇒ Object

Attach a file to the output

Parameters:

  • file (string|io)

    the file to attach. It can be a string containing the file content itself, the file path, or an IO ready to be read.

  • media_type (string) (defaults to: nil)

    the media type. If file is a valid path, media_type can be omitted, it will then be inferred from the file name.

  • filename (string) (defaults to: nil)

    the name of the file you wish to specify. This is only needed in situations where you want to rename a PDF download e.t.c. - In most situations you should not need to pass a filename



92
93
94
95
96
97
98
99
100
# File 'lib/cucumber/glue/proto_world.rb', line 92

def attach(file, media_type = nil, filename = nil)
  if File.file?(file)
    media_type = MiniMime.lookup_by_filename(file)&.content_type if media_type.nil?
    file = File.read(file, mode: 'rb')
  end
  super
rescue StandardError
  super
end