Sha256: 9c67eadf8ea18d0b423d3b200491eda7f27cfd0847d2b8888223f27955d62356

Contents?: true

Size: 818 Bytes

Versions: 2

Compression:

Stored size: 818 Bytes

Contents

require 'logger'

LOG_FILE_NAME = 'cucumber_log_file.log'

Given(/^I am logging to a log file(?: at the (#{STRING_OR_SYM}) level)?$/) do |level|
  step "an empty file named \"#{LOG_FILE_NAME}\""
  cd('.') do
    @logger = Logger.new(LOG_FILE_NAME)
  end
  step "I set the log level to #{level || 'info'}"
  @orig_logger, MessageDriver.logger = MessageDriver.logger, @logger
end

Given(/^I set the log level to (#{STRING_OR_SYM})$/) do |level|
  level = level ? level.to_s.upcase : 'INFO'
  @logger.level = Logger::SEV_LABEL.find_index(level)
end

Then 'the log file should contain:' do |string|
  step "the file \"#{LOG_FILE_NAME}\" should contain:", string
end

After do
  if @logger
    @logger.close
    @logger = nil
  end
  if @orig_logger
    MessageDriver.logger = @orig_logger
    @orig_logger = nil
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
message-driver-0.6.1 features/step_definitions/logging_steps.rb
message-driver-0.6.0 features/step_definitions/logging_steps.rb