According to Ruby's documentation for Pathname#realdirpath and Pathname#realpath they are supposed to return the real, absolute path to the actual entity in the File System. I'm currently using them precisely with this purpose:
def validate_path(path)
path = Pathname.new(path).realpath
workspace = Pathname.new(WORKSPACE).realpath
# The following statement goes up one level at a time starting from the
# given path until it finds a path that matches the Workspace. If it
# never does then the result is set to false.
path.ascend { |parent| break true if parent == workspace } || false
end
But when I use FakeFS these no longer work. They seem to be trying to return the the actual real path (on the real File System) and since the directories do not exist there they fail:
For example:
pry> path
=> #<FakeFS::Pathname:/Workspace/other/project/spec/routing>
pry> path.exist?
=> true
pry> path.realdirpath
Errno::ENOENT: No such file or directory @ realpath_rec - /Workspace
pry> path.realpath
Errno::ENOENT: No such file or directory @ rb_check_realpath_internal - /Workspace/other/project/spec/routing
This is what I'm doing:
require 'fakefs/safe'
RSpec.describe PathValidator do
subject(:path_validator) { described_class.new }
let(:workspace) { '/Workspace/project' }
let(:path) { '/Workspace/other/project/spec/routing' }
before do
FakeFS.activate!
FileUtils.mkdir_p(workspace)
FileUtils.mkdir_p(path)
end
after { FakeFS.deactivate! }
it 'returns false' do
expect(path_validator.validate_path(path)).to eq(false)
end
end
I was expecting false to be returned but instead:
1) PathValidator returns false
Failure/Error: expect(path_validator.validate_path(path)).to eq(false)
Errno::ENOENT:
No such file or directory @ rb_check_realpath_internal - /Workspace/other/project/spec/routing
According to Ruby's documentation for
Pathname#realdirpath
andPathname#realpath
they are supposed to return the real, absolute path to the actual entity in the File System. I'm currently using them precisely with this purpose:But when I use
FakeFS
these no longer work. They seem to be trying to return the the actual real path (on the real File System) and since the directories do not exist there they fail:For example:
This is what I'm doing:
I was expecting
false
to be returned but instead:I'm running with: