Require some RSpec support files only when needed
We can consider speeding up our RSpec suite by doing some TestEnv.init
stuff / require 'something'
only when needed by using
RSpec.configure do |config|
config.when_first_matching_example_defined(:db) do
require "support/db"
end
end
as per docs
In large projects that use RSpec, it's common to have some expensive setup logic that is only needed when certain kinds of specs have been loaded. If that kind of spec has not been loaded, you'd prefer to avoid the cost of doing the setup.
The when_first_matching_example_defined hook makes it easy to conditionally perform some logic when the first example is defined with matching metadata, allowing you to ensure the necessary setup is performed only when needed.
/cc @rymai @rspeicher