Recommended way to check file existence?

10 views
Skip to first unread message

Arve Knudsen

unread,
Sep 3, 2010, 9:26:38 AM9/3/10
to cu...@googlegroups.com
Hello

Can someone please recommend me a way to check file existence the Cucumber way (i.e. in a Then step)? I tried this form: "File.should exist(fpath)", but the error message doesn't mention the file's path ("expected File to exist (RSpec::Expectations::ExpectationNotMetError)").

Thanks in advance,
Arve

David Chelimsky

unread,
Sep 3, 2010, 9:30:26 AM9/3/10
to cu...@googlegroups.com
On Sep 3, 2010, at 8:26 AM, Arve Knudsen wrote:

> Hello
>
> Can someone please recommend me a way to check file existence the Cucumber way (i.e. in a Then step)? I tried this form: "File.should exist(fpath)", but the error message doesn't mention the file's path ("expected File to exist (RSpec::Expectations::ExpectationNotMetError)").

File.should exist(path) comes from rspec. You can add a custom message like this:

File.should exist(path), "expected #{path} to exist on the file system"

HTH,
David

Arve Knudsen

unread,
Sep 3, 2010, 10:27:11 AM9/3/10
to cu...@googlegroups.com
Thanks for the clarification! I found a more direct way as well, "Pathname.new(fpath).should exist". This prints out the pathname in the case of error.

Arve
Reply all
Reply to author
Forward
0 new messages