Flowdock
v3.2.13 - Show latest stable - 1 note - Superclass: Object

No documentation

This class has no description. You can help the Ruby on Rails community by adding new notes.

Show files where this class is defined (1 file)
Register or log in to add new notes.
January 20, 2012 - (>= v3.0.0)
0 thanks

Stubs Logger in rspec

Let we have a module like below:

module MyModule
  class << self
    def logger
      @logger ||= Logger.new(File.join(Rails.root, "log", "my_gem_#{Rails.env}.log"))
    end
  end
end

To use this logger just type:

MyModule.logger.info "This is a log line"

To stub in tests use (for rspec):

require 'active_support/log_subscriber/test_helper'

RSpec.configure do |config|
   config.include ActiveSupport::LogSubscriber::TestHelper

   config.before do
      MyModule.stub!(:logger).and_return(MockLogger.new)
   end
end

Usefull in testing when you don’t like to log anything.