The last chapter in The Saga of The Mem Leak

One last thing about the infamous mem leak. This time with regard to Rails and testing.

As with any other gem used in a Rails app, it’s sensible to declare the gem in the Gemfile. That way you’ll get the benefits of having Bundler to manage the gem.

But just adding gem 'psych' to the Gemfile makes running tests blow up the same way as running the app with Phusion Passenger does.

When running tests however it shouldn’t matter much whether there’s a mem leak or not. Tests probably don’t execute in long running processes, so the memory should be freed regularly, when the processes terminate.

The easiest solution is to only include the Psych gem in the development and production groups in the Gemfile:

    gem 'psych', groups: [:development, :production]

That way running tests will use Psych v1.0.0 that is bundled in MRI 1.9.2.