问题
Im currently building a project using Rspec in which I sepparated in two different folders with domain code and infrastructure code. Both folders have their own specs in a spec folder. The domain/spec folder is the one containing the spec_helper.rb file, thats required from the tests inside the other folder infrastructure/spec
I'd like to know how to have a spec folder in the root of the project, including the spec_helper file and also tests, and being able to run all the tests with just one command (right now I do it running rspec domain/ infrastructure/)
回答1:
RSpec
is designed to work with all tests in one folder. By default, this folder is called spec/
, but you can use a different name with the --default-path
option.
So, your options as I see it are:
- Edit the source code of
rspec-core
to let that configuration support multiple directories. Hopefully your PR will be approved and merged. - Or, write a simple wrapper script that runs
rspec
against both directories. For example, you couldalias rspecs='rspec domain/ infrastructure/'
. - Or (what I would recommend!), you could just restructure your tests slightly to use
spec/domain/
andspec/infrastructure/
folders -- and then everything will just work, by convention, out of the box.
来源:https://stackoverflow.com/questions/51648304/rspec-multiple-spec-folders