class
ActiveSupport::LogSubscriber::TestHelper::MockLogger
v7.1.3.2 -
Show latest stable
- Superclass: Object
No documentation available for this class.
Included modules
- ActiveSupport::Logger::Severity
Attributes
| [R] | flush_count |
| [RW] | level |
Files
- activesupport/lib/active_support/log_subscriber/test_helper.rb
1Note
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.