Skip to content

Commit 9cb84af

Browse files
committed
Convert FileUtils to block style
1 parent ffc4282 commit 9cb84af

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

spec/fake_lib_dir.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
require "arduino_ci"
22

3+
# This class is meant for the :around behavior of RSpec test cases so that
4+
# we can make temporary directories in test cases. Note that since test cases
5+
# are evaluated on load, any temp directories that were created will not exist
6+
# by the time the test runs. So this class handles all of the particulars
7+
# around creating a fake library directory on time and configuring the backend
8+
# to properly use it.
39
class FakeLibDir
410

511
attr_reader :config_dir
@@ -18,16 +24,18 @@ def initialize
1824

1925
# designed to be called by rspec's "around" function
2026
def in_pristine_fake_libraries_dir(example)
21-
d = Dir.mktmpdir
22-
begin
27+
# we will make a dummy directory to contain the libraries directory,
28+
# and use that directory in a dummy config which we will pass to the backend.
29+
# then we can run the test case
30+
Dir.mktmpdir do |d|
2331
# write a yaml file containing the current directory
2432
dummy_config = { "directories" => { "user" => d.to_s } }
2533
@arduino_dir = Pathname.new(d)
2634
@libraries_dir = @arduino_dir + "libraries"
2735
Dir.mkdir(@libraries_dir)
2836

29-
f = File.open(@config_file, "w")
30-
begin
37+
# with the config file, enforce a structure similar to a temp file -- delete after use
38+
File.open(@config_file, "w") do |f|
3139
f.write dummy_config.to_yaml
3240
f.close
3341
example.run
@@ -39,15 +47,14 @@ def in_pristine_fake_libraries_dir(example)
3947
end
4048
end
4149
ensure
50+
# the tmp dir will be cleaned up automatically, but if we did our own symlink hack then here is the place to clean it up
4251
if ArduinoCI::Host.needs_symlink_hack?
4352
stdout, stderr, exitstatus = Open3.capture3('cmd.exe', "/c rmdir /s /q #{ArduinoCI::Host.pathname_to_windows(d)}")
4453
unless exitstatus.success?
4554
puts "====== rmdir of #{d} failed"
4655
puts stdout
4756
puts stderr
4857
end
49-
else
50-
FileUtils.remove_entry(d)
5158
end
5259
end
5360
end

0 commit comments

Comments
 (0)