Sha256: 414412616e4073eed5866d1c885f4979928d867d4c8692a5338dcbdfa51c034b

Contents?: true

Size: 1.27 KB

Versions: 59

Compression:

Stored size: 1.27 KB

Contents

# :stopdoc:
#
# One useful feature of log messages in your code is that they provide a
# convenient instrumentation point for testing. Through log messages you can
# confirm that internal methods were called or that certain code paths were
# executed. This example demonstrates how to capture log output during testing
# for later analysis.
#
# The Logging framework provides an RSpec helper that will direct log output
# to a StringIO appender. Log lines can be read from this IO destination
# during tests.
#

  require 'rspec'
  require 'logging'
  require 'rspec/logging_helper'

  # Configure RSpec to capture log messages for each test. The output from the
  # logs will be stored in the @log_output variable. It is a StringIO instance.
  RSpec.configure do |config|
    include RSpec::LoggingHelper
    config.capture_log_messages
  end

  # Now within your specs you can check that various log events were generated.
  describe 'SuperLogger' do
    it 'should be able to read a log message' do
      logger = Logging.logger['SuperLogger']

      logger.debug 'foo bar'
      logger.warn  'just a little warning'

      @log_output.readline.should be == 'DEBUG SuperLogger: foo bar'
      @log_output.readline.should be == 'WARN  SuperLogger: just a little warning'
    end
  end

# :startdoc:

Version data entries

59 entries across 51 versions & 6 rubygems

Version Path
logging-2.4.0 examples/rspec_integration.rb
logging-2.3.1 examples/rspec_integration.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/logging-2.3.0/examples/rspec_integration.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/logging-2.3.0/examples/rspec_integration.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/logging-2.3.0/examples/rspec_integration.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/logging-2.3.0/examples/rspec_integration.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/logging-2.3.0/examples/rspec_integration.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/logging-2.3.0/examples/rspec_integration.rb
logging-2.3.0 examples/rspec_integration.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/logging-2.2.2/examples/rspec_integration.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/logging-2.2.2/examples/rspec_integration.rb