shellspec icon indicating copy to clipboard operation
shellspec copied to clipboard

More natural language matchers

Open jocutajar opened this issue 5 years ago • 6 comments

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.

jocutajar avatar Jan 20 '21 14:01 jocutajar

Thanks!

ko1nksm avatar Jan 20 '21 15:01 ko1nksm

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

robert-gurol-signavio avatar Aug 03 '21 05:08 robert-gurol-signavio

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

robert-gurol-signavio avatar Aug 03 '21 05:08 robert-gurol-signavio

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

kamok avatar Nov 23 '21 18:11 kamok

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

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:

image

LukeSavefrogs avatar Nov 11 '22 08:11 LukeSavefrogs

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

LukeSavefrogs avatar Nov 14 '22 00:11 LukeSavefrogs