Skip to content

Commit

Permalink
improve tempfile handling in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcupitt committed Dec 21, 2020
1 parent 2a277c5 commit d7f0305
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.swp
doc
pkg/*.gem
spec/tmp

# skip Gemfile.lock since this is a gem
Gemfile.lock
36 changes: 4 additions & 32 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,18 @@
Vips.set_debug ENV["DEBUG"]
# Vips.leak_set true

module Spec
module Path
def set_root(path)
@root = Pathname.new(path).expand_path
end

def sample(*path)
root.join "samples", *path
end

def tmp(*path)
root.join "tmp", "working", *path
end

extend self

private

def root
@root ||= set_root(File.expand_path("..", __FILE__))
end
end
end

def simg(name)
Spec::Path.sample(name).to_s
File.join(File.expand_path("..", __FILE__), "samples", name)

This comment has been minimized.

Copy link
@Nakilon

Nakilon Dec 22, 2020

Contributor

This may work too.

File.join __dir__, "samples", name

https://apidock.com/ruby/v2_1_10/Kernel/__dir__
https://stackoverflow.com/q/15190700/322020

This comment has been minimized.

Copy link
@jcupitt

jcupitt Dec 22, 2020

Author Member

Oh yes, a ruby2.0 feature. Thanks!

end

def timg(name)
Spec::Path.tmp(name).to_s
File.join(@temp_dir, name)
end

RSpec.configure do |config|
config.include Spec::Path

config.around do |example|
Dir.mktmpdir do |dir|
set_root(dir)
FileUtils.mkdir_p(Spec::Path.sample)
FileUtils.mkdir_p(Spec::Path.tmp)
Dir.mktmpdir("ruby-vips-spec-") do |dir|
@temp_dir = dir
example.run
end
end
Expand Down

0 comments on commit d7f0305

Please sign in to comment.