Sha256: 30cbc886763de6840528faad3de7333892110b90609ce84a751e49f95764dfc3

Contents?: true

Size: 730 Bytes

Versions: 20

Compression:

Stored size: 730 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 = pwd
  paths = 1.upto(number_of_directories).map do
    File.expand_path(File.join(pwd, "spec/.fixtures/#{Time.now.to_f.to_s.sub('.', '') + rand(9999).to_s}"))
  end

  # Create the dirs
  paths.each { |p| mkdir_p(p) }

  cd(paths.first) if number_of_directories == 1
  yield(*paths)
ensure
  cd current_pwd
  paths.map { |p| rm_rf(p) if File.exists?(p) }
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
listen-2.7.4 spec/support/fixtures_helper.rb
listen-2.7.3 spec/support/fixtures_helper.rb
listen-2.7.2 spec/support/fixtures_helper.rb
listen-2.7.1 spec/support/fixtures_helper.rb
listen-2.7.0 spec/support/fixtures_helper.rb
listen-2.6.2 spec/support/fixtures_helper.rb
listen-2.6.1 spec/support/fixtures_helper.rb
listen-2.6.0 spec/support/fixtures_helper.rb
listen-2.5.0 spec/support/fixtures_helper.rb
listen-2.4.1 spec/support/fixtures_helper.rb
listen-2.4.0 spec/support/fixtures_helper.rb
listen-2.3.1 spec/support/fixtures_helper.rb
listen-2.2.0 spec/support/fixtures_helper.rb
listen-2.1.2 spec/support/fixtures_helper.rb
listen-2.1.1 spec/support/fixtures_helper.rb
listen-2.1.0 spec/support/fixtures_helper.rb
listen-2.0.4 spec/support/fixtures_helper.rb
listen-2.0.3 spec/support/fixtures_helper.rb
listen-2.0.2 spec/support/fixtures_helper.rb
listen-2.0.1 spec/support/fixtures_helper.rb