Module: Cucumber::Formatter::Io

Included in:
HTML, Json, Junit, Message, Pretty, Progress, Rerun, Summary
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/io.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.ensure_dir(path, name) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/io.rb', line 71

def ensure_dir(path, name)
  raise "You *must* specify --out DIR for the #{name} formatter" unless path.instance_of? String
  raise "I can't write #{name} reports to a file - it has to be a directory" if File.file?(path)

  FileUtils.mkdir_p(path) unless File.directory?(path)
  File.absolute_path path
end

.ensure_file(path, name) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/io.rb', line 63

def ensure_file(path, name)
  raise "You *must* specify --out FILE for the #{name} formatter" unless path.instance_of? String
  raise "I can't write #{name} to a directory - it has to be a file" if File.directory?(path)
  raise "I can't write #{name} to a file in the non-existing directory #{File.dirname(path)}" unless File.directory?(File.dirname(path))

  ensure_io(path, nil)
end

.ensure_io(path_or_url_or_io, error_stream) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/io.rb', line 12

def ensure_io(path_or_url_or_io, error_stream)
  return nil if path_or_url_or_io.nil?
  return path_or_url_or_io if io?(path_or_url_or_io)

  io = if url?(path_or_url_or_io)
         url = path_or_url_or_io
         reporter = url.start_with?(Cucumber::Cli::Options::CUCUMBER_PUBLISH_URL) ? URLReporter.new(error_stream) : NoReporter.new
         HTTPIO.open(url, nil, reporter)
       else
         File.open(path_or_url_or_io, Cucumber.file_mode('w'))
       end
  @io_objects_to_close ||= []
  @io_objects_to_close.push(io)
  io
end

.included(formatter_class) ⇒ Object



51
52
53
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/io.rb', line 51

def self.included(formatter_class)
  formatter_class.extend(ClassMethods)
end

.io?(path_or_url_or_io) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/io.rb', line 55

def io?(path_or_url_or_io)
  path_or_url_or_io.respond_to?(:write)
end

.url?(path_or_url_or_io) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/io.rb', line 59

def url?(path_or_url_or_io)
  path_or_url_or_io.match(/^https?:\/\//)
end