2
votes

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
Instead of domain/spec and infrastructure/spec, can you do spec/domain and spec/infrastructure and keep spec_helper.rb directly under /spec, and run all the rspecs with rspec spec/? - Jagdeep Singh

1 Answers

3
votes

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:

  1. Edit the source code of rspec-core to let that configuration support multiple directories. Hopefully your PR will be approved and merged.
  2. Or, write a simple wrapper script that runs rspec against both directories. For example, you could alias rspecs='rspec domain/ infrastructure/'.
  3. Or (what I would recommend!), you could just restructure your tests slightly to use spec/domain/ and spec/infrastructure/ folders -- and then everything will just work, by convention, out of the box.