Sha256: bc64f23c9bd8d39c2d71bce2096be884dbb6f97364e6278a546e835cb0db1ff5

Contents?: true

Size: 803 Bytes

Versions: 15

Compression:

Stored size: 803 Bytes

Contents

require 'tmpdir'

include FileUtils

# Prepares temporary fixture-directories and
# cleans them afterwards.
#
# @param [Fixnum] number_of_directories the number of fixture-directories to
# make
#
# @yield [path1, path2, ...] the empty fixture-directories
# @yieldparam [String] path the path to a fixture directory
#
def fixtures(number_of_directories = 1)
  current_pwd = Dir.pwd
  paths = 1.upto(number_of_directories).map { mk_fixture_tmp_dir }

  FileUtils.cd(paths.first) if number_of_directories == 1

  yield(*paths)
ensure
  FileUtils.cd current_pwd
  paths.map { |p| FileUtils.rm_rf(p) if File.exist?(p) }
end

def mk_fixture_tmp_dir
  timestamp = Time.now.to_f.to_s.sub('.', '') + rand(9999).to_s
  path = Pathname.pwd.join('spec', '.fixtures', timestamp).expand_path
  path.tap(&:mkpath)
end

Version data entries

15 entries across 13 versions & 3 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/listen-2.7.9/spec/support/fixtures_helper.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/listen-2.7.9/spec/support/fixtures_helper.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/listen-2.7.9/spec/support/fixtures_helper.rb
listen-2.8.4 spec/support/fixtures_helper.rb
listen-2.8.3 spec/support/fixtures_helper.rb
listen-2.8.2 spec/support/fixtures_helper.rb
listen-2.8.1 spec/support/fixtures_helper.rb
listen-2.8.0 spec/support/fixtures_helper.rb
listen-2.7.12 spec/support/fixtures_helper.rb
listen-2.7.11 spec/support/fixtures_helper.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/listen-2.7.9/spec/support/fixtures_helper.rb
listen-2.7.9 spec/support/fixtures_helper.rb
listen-2.7.8 spec/support/fixtures_helper.rb
listen-2.7.7 spec/support/fixtures_helper.rb
listen-2.7.6 spec/support/fixtures_helper.rb