Sha256: 254105fed80bd01c2ab181e9527c181dc549f75ee35b235f198f08eac9e0b5bf

Contents?: true

Size: 989 Bytes

Versions: 2

Compression:

Stored size: 989 Bytes

Contents

require 'tmpdir'


module CukeCataloger
  module FileHelper

    class << self

      def create_feature_file(options = {})
        options[:text] ||= 'Feature:'
        options[:name] ||= 'test_file'

        create_file(:text => options[:text], :name => options[:name], :extension => '.feature', :directory => options[:directory])
      end

      def create_file(options = {})
        options[:text] ||= ''
        options[:name] ||= 'test_file'
        options[:extension] ||= '.txt'
        options[:directory] ||= create_directory

        file_path = "#{options[:directory]}/#{options[:name]}#{options[:extension]}"
        File.open(file_path, 'w') { |file| file.write(options[:text]) }

        file_path
      end

      def created_directories
        @created_directories ||= []
      end

      def create_directory
        new_dir = Dir::mktmpdir
        created_directories << new_dir

        new_dir
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cuke_cataloger-1.6.0 testing/file_helper.rb
cuke_cataloger-1.5.0 testing/file_helper.rb