Skip to content

Keep RSpec configuration between jobs in the same worker - #124

Open
trusche wants to merge 3 commits into
briandunn:masterfrom
serpapi:bugfix/rspec-configuration-shared-jobs
Open

trusche wants to merge 3 commits into
briandunn:masterfrom
serpapi:bugfix/rspec-configuration-shared-jobs

Conversation

@trusche

@trusche trusche commented Sep 20, 2026 •

Copy link
Copy Markdown

Workers pull jobs from a shared queue, so a worker that finishes early can run a second job in the same process. Flatware::RSpec.run ends each job with ::RSpec.reset, which sets RSpec.configuration to nil. On the next job --require spec_helper is a no-op (already required), so the new configuration has none of the config.includes or hooks from spec_helper. Specs then fail with errors like undefined method 'stub_request' (WebMock), missing FactoryBot methods, and so on.

Because it depends on worker timing, it shows up as intermittent failures, which is happening to us a lot recently.

Fix: use ::RSpec.clear_examples instead. It clears the example groups and reporter (so nothing runs twice) but keeps the configuration.

Added a test that reproduce the issue by running two jobs through Flatware::RSpec.run in one subprocess against a spec_helper that includes a helper module.

Disclosure: Built with Claude, but manually verified and submitted.

@briandunn

Copy link
Copy Markdown
Owner

@trusche this looks useful thanks! Please resolve the CI errors and I'll merge.

@trusche

trusche commented Sep 21, 2026 •

Copy link
Copy Markdown
Author

Please resolve the CI errors

I tried in #126 😄 I think they're all unrelated, it's just that CI is set to fail-fast. Same failures happen on master. It first failed on Rubocop, I threw a fix in for that, now it's the Cucumber incompatibility:

CleanShot 2026-09-21 at 09 03 54@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants