More natural language matchers
Related to #87
I'd like to write
The path /x/y/z should exist
The path /x/y/z should be a file
The path /x/y/z should have setguid
Currently I have to write
The path /x/y/z should be exist
The path /x/y/z should be file
The path /x/y/z should has setguid
Which is feels awkward considering the otherwise neat English definition.
Thanks!
This was just merged - "should exist" will soon be available. https://github.com/shellspec/shellspec/pull/233
Also, there is this discussion https://github.com/shellspec/shellspec/discussions/221 - pointing out that "should be a file" also works. :)
... and there are other issues like https://github.com/shellspec/shellspec/issues/178
should have setguid
This could actually be quite easy to add - have a look at shellspec/lib/core/matchers/has.sh.
I think I can give it a try. EDIT: https://github.com/shellspec/shellspec/pull/235
Did this feature regress somehow? I'm very confused when trying to write my spec:
This test:
The file '/tmp/repo/dummy.ts' should exist
Fails:
The file /tmp/repo/dummy.ts should exist
Unknown word 'exist' after should verb. The correct word is one of the following.
be, end, equal, eq, has, include, match, start,
satisfy
In the reference document, should exist is recommended.
I'm also using latest:
shellspec --version
0.28.1
Did this feature regress somehow? I'm very confused when trying to write my spec:
This test:
The file '/tmp/repo/dummy.ts' should existFails:
The file /tmp/repo/dummy.ts should exist Unknown word 'exist' after should verb. The correct word is one of the following. be, end, equal, eq, has, include, match, start, satisfyIn the reference document,
should existis recommended.I'm also using latest:
shellspec --version 0.28.1
I have the same problem (0.28.1).
Currently ONLY should be a file works!
$ shellspec --version
0.28.1
My test
Describe "Test"
Describe "'Old' syntax"
Example "should be exist"
The path "${LIBRARY_PATH}" should be exist
End
Example "should be file"
The path "${LIBRARY_PATH}" should be file
End
Example "should not has setgid"
The path "${LIBRARY_PATH}" should not has setgid
End
End
Describe "Natural language"
Example "should exist"
The path "${LIBRARY_PATH}" should exist
End
Example "should be a file"
The path "${LIBRARY_PATH}" should be a file
End
Example "should not have setuid"
The path "${LIBRARY_PATH}" should not have setuid
End
End
End
Output
As you can see should exist and should not have setuid fail the tests here:

I finally figured it out... This feature did not regress. It just never came out as a release. 😀
The PR #233 introducing the should exist syntax was merged in 3 August 2021 on the master branch, while the latest release (0.28.1) dates back to 1 January 2021.
As said by @ko1nksm in #240, the feature is not yet available:
It is not a typo, a change in the next version. See https://github.com/shellspec/shellspec/pull/233. Note that the master contains the latest updates.
⚠ Workaround
To use this feature you would have to switch to the master branch.
This however could lead to potential problems, since the master branch could have bugs (it's the development branch). So do it at your own risk (and if you absolutely MUST).
The command to get the latest features is the following:
curl -fsSL https://git.io/shellspec | sh -s -- master --switch