aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support/zip_support.rb
blob: 3d9b2f97c9f7f9353e7fd0222f21d41d49fc4c5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require_relative 'helpers/tree_walker'
module ZipSupport

  module Helper extend self
    def remove
      -> filetype, path do
        filetype == :file ? File.unlink(path) : Dir.unlink(path)
      end
    end
  end

  def zip_fixtures_path(file_name)
    fixtures_path(File.join('zip', file_name))
  end

  def clear_all_zip_fixtures! relpath = ''
    raise ArgumentError, 'up dir not allowed (..)' if %r{\.\.} === relpath
    TreeWalker.walk_tree zip_fixtures_path(relpath), yield_dirs: :after, &Helper.remove 
  end
end

RSpec.configure do |conf|
  conf.include ZipSupport, type: :zip
end