I am following the hspec documentation on passing options to Hspec. Specifying my option works as expected when passed from the command line, but not when passed from the .hspec
file or any of the other listed methods.
One of the tests in my test suite matches the filter "post_returns_200". I can run this test alone without running the rest of the suite via the command
stack test --test-arguments=--match="post_returns_200"
The linked hspec documentation shows that I should be able to specify this filter not only from the command line, but also: from an .hspec
file, from within ghci
, or from an environment variable. When I follow the documentation to specify my filter by one of those other methods, however, I get an "unrecognized option" error. For instance, when I specify the option in the .hspec
file via
$ echo --match="post_returns_200">>.hspec
then running stack test
returns the following
$ stack test
azara-api-0.1.0.0: test (suite: azara-test)
azara-test: unrecognized option `--match="post_returns_200"' in config file /home/matthew/backup/azara_work/platform/api/.hspec
Test suite failure for package azara-api-0.1.0.0
azara-test: exited with: ExitFailure 1
Logs printed to console
When I attempt to specify the option via an environment variable or from within ghci, I get a similar error. I have tried many variations on how to specify the command, e.g. with or without quotes, with and without "--test-arguments=
", but I am totally stumped at this point. Any suggestions on why the option works properly when specified via command line but is unrecognized by the other methods?
For some reason I ignore, hspec recognizes a different set of options in the command line and in config files.
As of now, explicit command line arguments (via
--test-arguments
when using stack) is the only way to pass--match
to hspec.From the source code of 2.4.4 (which has changed a lot on the current active branch, but it still doesn't allow what you want either):
Command line options are parsed with
recognizedOptions
, containing bothcommandLineOptions
(which includes--match
) andconfigFileOptions
.Config file options, via
parseOtherOptions
, use onlyconfigFileOptions
, which don't include--match
.