I am writing an RSpec test to check if a given path is a directory. In once scenario this isn't the case and I expect a false, but I don't know how to raise this.
So my test looks like this:
context 'when a logfile is given' do
it 'does not contain a folder first' do
logfile = '/tmp/qwertyasd/random/path/rspec.log'
expect(Pathname(File.dirname(logfile))).to be_directory
# I want this expect to return false. I cannot use !be_directory
# I know I should not use be_directory, I was thinking about something like !be_directory but this raise an error.
end
it 'create a folder for it' do
logfile = '/tmp/qwertyasd/random/path/rspec.log'
Pathname.new(logfile).parent.descend { |path| FileUtils.mkdir path if path.parent.writable? && !path.exist? }
expect(Pathname(File.dirname(logfile))).to be_directory
`rm -rf /tmp/qwertyasd`
end
end
I have tried using !be_directory but this gives me an error. Any tips?