Dragan R.
Dragan R.

Reputation: 670

How to use multiple rspec_helpers

We are experimenting with adding integration tests with rspec into our workflow, and are experimenting the following folder structure:

.
├── spec #unit tests
├── spec-integration #e2e tests

When I run the e2e tests with bundle exec rspec SPECS=spec-integration, the --require spec_helper from .rspec automatically goes to spec/spec_helper. This makes sense and expected, but we don't want to use the spec_helper from the unit tests, we want to use another one for integration tests.

How do I tell rspec to go to spec-integration/spec_handler instead of spec/spec_handler as a default?

(Edit/PS: Comments from a folder architecture or suggestions on a better way to design this are also welcome, as we are pretty new to the Ruby ecosystem)

Thanks!

Upvotes: 3

Views: 317

Answers (1)

Nitish Parkar
Nitish Parkar

Reputation: 2868

You can override that by specifying --options command line flag. (ref)

bundle exec rspec --default-path spec-integration --options spec_handler

Also, when you use --default-path, you can have a spec-integration/spec_helper.rb and it will use that(because of --require spec_helper in .rspec).

(This is not working for me on rspec 3.9 though - bundle exec rspec SPECS=spec-integration.)

Coming to the folder structure part, I would keep integration specs in a sub-folder inside spec. Both unit and integration specs can have their own helper files and spec/spec_helper can have common configuration.

Upvotes: 1

Related Questions