I am using Test-Kitchen and Serverspec for my integration tests. I want to use a Serverspec file resource to verify whether a hidden file exists, in this case .gemrc
. Here is my spec configuration:
require 'spec_helper'
describe "Checking the .gemrc" do
describe file('~/.gemrc') do
it { should be_file }
end
end
And here is the error output:
Check .gemrc
File "~/.gemrc"
should be file (FAILED - 1)
Failures:
1) Check .gemrc File "~/.gemrc" should be file
Failure/Error: it { should be_file }
test -f \~/.gemrc
expected file? to return true, got false
# /tmp/busser/suites/serverspec/default/ruby_spec.rb:14:in `block (3 levels) in <top (required)>'
Finished in 0.06349 seconds
1 example, 1 failure
Why doesn't the file
resource see the .gemrc file as a normal file?
The ~
shorthand is a path expansion supported by many popular shells, but it is not a true filesystem path. In effect, you are asking the file resource to look for a file .gemrc
in an actual subdirectory named ~
(from an unspecified working directory, whatever it may be at the time the specs run).
I think you will need to specify an absolute path to the file (for example, file('/home/username/.gemrc')
).