Sha256: 1aaf2cffd80782cd287d675d2848c03e867c073bb7bc66fc722296e2d219e868

Contents?: true

Size: 1.38 KB

Versions: 27

Compression:

Stored size: 1.38 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(yield) }
        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

27 entries across 27 versions & 1 rubygems

Version Path
omnibus-9.0.24 spec/support/file_helpers.rb
omnibus-9.0.23 spec/support/file_helpers.rb
omnibus-9.0.22 spec/support/file_helpers.rb
omnibus-9.0.17 spec/support/file_helpers.rb
omnibus-9.0.12 spec/support/file_helpers.rb
omnibus-9.0.11 spec/support/file_helpers.rb
omnibus-9.0.8 spec/support/file_helpers.rb
omnibus-8.3.2 spec/support/file_helpers.rb
omnibus-8.2.2 spec/support/file_helpers.rb
omnibus-8.1.15 spec/support/file_helpers.rb
omnibus-8.0.15 spec/support/file_helpers.rb
omnibus-8.0.9 spec/support/file_helpers.rb
omnibus-7.0.34 spec/support/file_helpers.rb
omnibus-7.0.13 spec/support/file_helpers.rb
omnibus-7.0.12 spec/support/file_helpers.rb
omnibus-6.1.9 spec/support/file_helpers.rb
omnibus-6.1.7 spec/support/file_helpers.rb
omnibus-6.1.4 spec/support/file_helpers.rb
omnibus-6.0.30 spec/support/file_helpers.rb
omnibus-6.0.25 spec/support/file_helpers.rb