Notes posted by lukaszsliwa

RSS feed
April 19, 2012 - (<= v3.2.1)
0 thanks

Locale

To change default locale by the parameter you can set :locale option, like below:

select_date 'user', 'birth', :locale => 'de'
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.