Disabling Spring when debugging

Posted . Visible to the public.

Spring Show archive.org snapshot is a Rails application preloader. When debugging e.g. the rails gem, you'll be wondering why your raise, puts or debugger debugging statements have no effect. That's because Spring preloads and caches your application once and all consecutive calls to it will not see any changes in your debugged gem.

Howto

Disable spring with export DISABLE_SPRING=1 in your terminal. That will keep Spring at bay in that terminal session.

In Ruby, you can only write environment variables that subprocesses will see Show archive.org snapshot . For tests with a Rails application (i.e., that call rails or rake or other binstubbed commands), this method may help you:

# Use this method to wrap any system calls to the test application
def prepare_environment(&block)
  Bundler.with_clean_env do
    # Spring leads to all kinds of unexpected behavior in tests.
    ENV['DISABLE_SPRING'] = '1'

    block.call
  end
end

Dominik Schöler
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2014-05-03 13:05)