Sha256: 0e3175f4cd81e00201e73b16509ee9fd8f88e438d85d30b9b79cd7d8b3d24994

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

module Omnibus
  module RSpec
    module FileHelpers
      def create_directory(*paths)
        path = File.join(*paths)
        FileUtils.mkdir_p(path)
        path
      end

      def remove_directory(*paths)
        path = File.join(*paths)
        FileUtils.rm_rf(path)
        path
      end

      def copy_file(source, destination)
        FileUtils.cp(source, destination)
        destination
      end

      def remove_file(*paths)
        path = File.join(*paths)
        FileUtils.rm_f(path)
        path
      end

      def create_file(*paths, &block)
        path = File.join(*paths)

        FileUtils.mkdir_p(File.dirname(path))
        FileUtils.rm(path) if File.exist?(path)

        if block
          File.open(path, 'wb') { |f| f.write(block.call) }
        else
          FileUtils.touch(path)
        end

        path
      end

      def create_link(src, dest)
        # Windows has no symlinks. Documentation seems to suggest that
        # ln will create hard-links - so attempt to elicit the behavior
        # we want using hard-links.  If your test happens to fail even
        # with this, consider what semantics you actually wish to have
        # on windows and refactor your test or code.
        if windows?
          FileUtils.ln(src, dest) unless File.exist?(dest)
        else
          FileUtils.ln_s(src, dest) unless File.exist?(dest)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
omnibus-5.4.0 spec/support/file_helpers.rb
omnibus-5.3.0 spec/support/file_helpers.rb
omnibus-5.2.0 spec/support/file_helpers.rb
omnibus-5.1.0 spec/support/file_helpers.rb
omnibus-5.0.0 spec/support/file_helpers.rb
omnibus-4.1.0 spec/support/file_helpers.rb