that is what triggers rake.rb and rake/rake_module.rb (which defines Rake.application) to get loaded.
ThenBundler.require loads exception_notification-rake gem, which checks that Rake.application is defined and patches Rake::Application#display_error_message
This is evident from the following backtraces taken at those 2 points:
spring's preload loads exception_notifier-rake gem beforebin/rake is loaded
exception_notification-rake checks if Rake.application is defined; since it is not, it doesn't patch Rake::Application#display_error_message and so this gem has no effect
Then the bin/rake binstub gets loaded,
which triggers rake.rb and rake/rake_module.rb (which defines Rake.application) to get loaded (too late).
Again, you can see this from the backtraces if you wish:
Steps to reproduce
Check out a Rails app that has spring inserted in the binstubs — for example, this example app: https://github.com/TylerRick/exception_notification-rake_example_with_spring/tree/workaround_using_load_in_bin_rake
Run
bin/rake check:exception
Observe that no email is sent
How it's supposed to work
Normally (without spring), what happens is:
bin/rake
binstub gets loaded first, andrake.rb
andrake/rake_module.rb
(which definesRake.application
) to get loaded.Bundler.require
loadsexception_notification-rake
gem, which checks thatRake.application
is defined and patchesRake::Application#display_error_message
This is evident from the following backtraces taken at those 2 points:
(or if using global
rake
instead ofbin/rake
binstub:)
How it works instead when using spring
But when using spring:
preload
loadsexception_notifier-rake
gem beforebin/rake
is loadedexception_notification-rake
checks ifRake.application
is defined; since it is not, it doesn't patchRake::Application#display_error_message
and so this gem has no effectbin/rake
binstub gets loaded,rake.rb
andrake/rake_module.rb
(which definesRake.application
) to get loaded (too late).Again, you can see this from the backtraces if you wish:
Workaround
One workaround is to add this line to
bin/rake
:But a better solution is needed that doesn't require modifying the binstubs that spring automatically generated...