forked from Arduino-CI/arduino_ci
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhost_spec.rb
53 lines (41 loc) · 1.27 KB
/
host_spec.rb
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require "spec_helper"
require 'tmpdir'
def idempotent_delete(path)
path.delete
rescue Errno::ENOENT
end
# creates a dir at <path> then deletes it after block executes
# this will DESTROY any existing entry at that location in the filesystem
def with_tmpdir(path)
begin
idempotent_delete(path)
path.mkpath
yield
ensure
idempotent_delete(path)
end
end
RSpec.describe ArduinoCI::Host do
next if skip_ruby_tests
context "symlinks" do
it "creates symlinks that we agree are symlinks" do
our_dir = Pathname.new(__dir__)
foo_dir = our_dir + "foo_dir"
bar_dir = our_dir + "bar_dir"
with_tmpdir(foo_dir) do
foo_dir.unlink # we just want to place something at this location
expect(foo_dir.exist?).to be_falsey
with_tmpdir(bar_dir) do
expect(bar_dir.exist?).to be_truthy
expect(bar_dir.symlink?).to be_falsey
ArduinoCI::Host.symlink(bar_dir, foo_dir)
expect(ArduinoCI::Host.symlink?(bar_dir)).to be_falsey
expect(ArduinoCI::Host.symlink?(foo_dir)).to be_truthy
expect(ArduinoCI::Host.readlink(foo_dir).realpath).to eq(bar_dir.realpath)
end
end
expect(foo_dir.exist?).to be_falsey
expect(bar_dir.exist?).to be_falsey
end
end
end