A More Kosher Approach to Spork

December 1, 2011 Onsi Fakhouri

Ask for Help

“Reloading of models under spork?”

From hybrid-cutlery expert Sobo:

Spork requires you to divide your spec helper into two phases, before fork and after fork.
Before fork, you want to do time consuming things like loading the Rails environment, so you don’t have to pay that cost on each test run.
If you end up requiring model classes or other volatile files before forking, then they won’t be reloaded for each test run.
This can happen, for example, when you use Devise route helpers, which touch the User constant during route evaluation.
This causes user.rb to be auto-required before fork.
Since the User constant is defined after forking, Rails won’t autoload changes to User, forcing you to restart the Spork server every time you change it.

There are two solutions:

  • The first is simply to avoid loading models or other code you want to auto-reload before fork.
  • If you must refer to models before fork, as is the case with the Devise route helpers, then put an explicit load (not require because it won’t load the file if it’s already been loaded) in your after fork block for the files that were loaded before fork.
    This will force them to be reloaded.

Interesting Things

  • It’s open season on open enrollment. SF will have an info session today at 12:30. Pizza will be served. Y’all have between now and December 9th to make changes.
  • Those with mohawks and staches in SF are encouraged to take a picture at the Vermehr e-mail station (closest e-mail station to the bathrooms).

About the Author

Onsi Fakhouri

Onsi Fakhouri is the Senior Vice President, Cloud R&D of Pivotal.

New Tech Talk: Parse
New Tech Talk: Parse

Many mobile developers find themselves rewriting the same server code for every app. Co-founder Kevin Lacke...

[SF] 11/30/2011: 30 Days has Movember
[SF] 11/30/2011: 30 Days has Movember

Ask for Help "Is there a good JS/HTML code editor that will expand to fix the contents?" A team is ...

SpringOne 2021

Register Now