Module: Cucumber::Formatter::Io

Included in:
HTML, Json, Junit, Message, Pretty, Progress, Rerun, Summary
Defined in:
lib/cucumber/formatter/io.rb

Class Method Summary collapse

Class Method Details

.ensure_dir(path, name) ⇒ Object


34
35
36
37
38
39
# File 'lib/cucumber/formatter/io.rb', line 34

def ensure_dir(path, name)
  raise "You *must* specify --out DIR for the #{name} formatter" unless String == path.class
  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


27
28
29
30
31
32
# File 'lib/cucumber/formatter/io.rb', line 27

def ensure_file(path, name)
  raise "You *must* specify --out FILE for the #{name} formatter" unless String == path.class
  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)
end

.ensure_io(path_or_url_or_io) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cucumber/formatter/io.rb', line 10

def ensure_io(path_or_url_or_io)
  return nil if path_or_url_or_io.nil?
  return path_or_url_or_io if path_or_url_or_io.respond_to?(:write)
  io = if path_or_url_or_io.match(%r{^https?://})
         HTTPIO.open(path_or_url_or_io)
       else
         File.open(path_or_url_or_io, Cucumber.file_mode('w'))
       end
  at_exit do
    unless io.closed?
      io.flush
      io.close
    end
  end
  io
end