packs-rails: RSpec integration not working as expected
I’ve currently setup packwerk and stimpack in my application and my expectation around RSpec was that when running rspec or bundle exec rspec then all tests contained in the standard spec/ folder and all tests in packs/**/spec/ folders would be executed.
However it seems like at the moment only tests in the global folder are being picked up and executed, the packs tests are being ignored. I’m using the new Stimpack.config.root setting but I don’t think that has anything to do with this.
While debugging, I’ve managed to print out the value of RSpec.configuration.pattern after the Stimpack integration was loaded, and I got the following:
"**{,/*/**}/*_spec.rb,components/comp1/spec/**/*_spec.rb,components/comp2/spec/**/*_spec.rb,components/comp3/spec/**/*_spec.rb"
so I can see my components there, but the tests are still not included in the run. Is my expectation incorrect, or is this a bug with Stimpack?
For what is worth, I was previously able to make this work in my app before adding Stimpack, and the trick had to do with setting the --default-path option for RSpec.
This is because, as far as I understand, RSpec assumes your path starts from spec/ and so all patterns are relative to that path, hence components/... will translate into spec/components... which is not what we want.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 19 (8 by maintainers)
Commits related to this issue
- Fix RSpec integration no seeing files from packs Fixes #15 — committed to astyagun/stimpack by astyagun 2 years ago
I’ll test this out once I’m back from my holiday, but the feedback is really positive so far! Thank you @AlexEvanczuk and @ngan for fixing this 🙏 !
I spent some extra time investigating this and opened a new issue with my findings.
Works for me now, thanks 🙏
Seems to work in my limited testing so far. 👍
Actually, it wasn’t because of Spring. Turns out we had
--require spec_helperin our.rspecfile. This causedspec/spec_helper.rbto boot before files are resolved by RSpec. This allowed us to load Stimpack with a simplerequire 'stimpack'. As a workaround, you can do the same.That said, I’ve just put up a PR to refactor lots of Stimpack and improve RSpec support: https://github.com/rubyatscale/stimpack/pull/28
After that lands, you’ll simply add
--require stimpack/rspecto your.rspecor on your CLI run (bundle exec rspec --require stimpack/rspec)This didn’t work for us: there are a bunch of
requirecalls which are actually relative to/spec. We also have--require spec_helperwhich breaks with default path set to..Thank you!! I’ll take a look later today!
Hey @iMacTia – do you have something in your
.rspec,.rspec-localor somewhere else that overrides thepattern?