Skip to content

Adding 'safe' frameworks to the preloader #61

@jdelStrother

Description

@jdelStrother

So now that I've slowed down everyone's test cycles by removing rspec/rails from the preloader (#60), it would probably be a good idea to try to figure out exactly what can be preloaded safely.

Obviously the safest option is not to preload anything - that way you're guaranteed to have the same load ordering as just running via rspec. But on my SSD'd MacPro, I see roughly 1 second wasted every test run due to loading ActiveRecord::Base, ActionController::Base and all their dependencies.

At least for my app, requiring active_record/base & action_controller/base seems safe, and recovers a decent chunk of the time lost by not loading rspec/rails. But to be honest, the rails initialization process and dependency ordering makes my head hurt - I couldn't guarantee it's not going to break stuff, particularly in the face of plugins doing crazy shit. Also, maybe not all apps want to load ActiveRecord?

We could just hand the responsibility off to the user : if they'd like to try to speed things up, they can just add something like the following to .spin.rb :

Spin.hook(:after_preload) do
  require 'action_controller/base'
end

but that seems like a cop-out.

One final option : make rspec/rails safe to load at any time. It seems like maybe rspec could delay some of its loading until the corresponding Rails framework loads - eg in example.rb :

ActiveSupport.on_load(:action_controller) do
  require 'rspec/rails/example/controller_example_group'
end
ActiveSupport.on_load(:action_view) do
  require 'rspec/rails/example/view_example_group'
end

etc. I suspect that leads to a rabbit hole of pain, though.

Any thoughts? Anyone know a particular rails core member who might be able to offer advice?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions