Module: Cucumber::Formatter::Io

Included in:
Gpretty, Html, Json, Junit, Pretty, Progress, Rerun
Defined in:
lib/cucumber/formatter/io.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) ensure_dir(path, name)



23
24
25
26
27
28
# File 'lib/cucumber/formatter/io.rb', line 23

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

- (Object) ensure_file(path, name)



17
18
19
20
21
# File 'lib/cucumber/formatter/io.rb', line 17

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

- (Object) ensure_io(path_or_io, name)



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cucumber/formatter/io.rb', line 4

def ensure_io(path_or_io, name)
  return nil if path_or_io.nil?
  return path_or_io if path_or_io.respond_to?(:write)
  file = File.open(path_or_io, Cucumber.file_mode('w'))
  at_exit do
    unless file.closed?
      file.flush
      file.close
    end
  end
  file
end