diff options
author | Adam Jacob <adam@hjksolutions.com> | 2009-03-11 13:25:45 -0700 |
---|---|---|
committer | Adam Jacob <adam@hjksolutions.com> | 2009-03-11 13:25:45 -0700 |
commit | a136f9823b8b0fa01da4e758e64c89bbab0036dc (patch) | |
tree | 9eece42b81546f39e6fe460e093f41d646a285c4 /features | |
download | mixlib-log-a136f9823b8b0fa01da4e758e64c89bbab0036dc.tar.gz |
Initial commit
Diffstat (limited to 'features')
-rw-r--r-- | features/log.feature | 37 | ||||
-rw-r--r-- | features/steps/log.rb | 48 | ||||
-rw-r--r-- | features/support/env.rb | 46 | ||||
-rw-r--r-- | features/support/logit.rb | 23 |
4 files changed, 154 insertions, 0 deletions
diff --git a/features/log.feature b/features/log.feature new file mode 100644 index 0000000..78a65f3 --- /dev/null +++ b/features/log.feature @@ -0,0 +1,37 @@ +Feature: Log output + In order to keep a record of application specific information + As a developer + I want to publish information through a configurable log interface + + Scenario: Log a message at the debug level + Given a base log level of 'debug' + When the message 'this goes out' is sent at the 'debug' level + Then the regex '\[.+\] DEBUG: this goes out' should be logged + + Scenario: Log a message at the info level + Given a base log level of 'info' + When the message 'this goes out' is sent at the 'info' level + Then the regex '\[.+\] INFO: this goes out' should be logged + + Scenario: Log a message at the warn level + Given a base log level of 'warn' + When the message 'this goes out' is sent at the 'warn' level + Then the regex '\[.+\] WARN: this goes out' should be logged + + Scenario: Log a message at the error level + Given a base log level of 'error' + When the message 'this goes out' is sent at the 'error' level + Then the regex '\[.+\] ERROR: this goes out' should be logged + + Scenario: Log a message at the fatal level + Given a base log level of 'fatal' + When the message 'this goes out' is sent at the 'fatal' level + Then the regex '\[.+\] FATAL: this goes out' should be logged + + Scenario: Log messages below the current threshold should not appear + Given a base log level of 'fatal' + When the message 'this goes out' is sent at the 'error' level + And the message 'this goes out' is sent at the 'warn' level + And the message 'this goes out' is sent at the 'info' level + And the message 'this goes out' is sent at the 'debug' level + Then nothing should be logged diff --git a/features/steps/log.rb b/features/steps/log.rb new file mode 100644 index 0000000..13a8fea --- /dev/null +++ b/features/steps/log.rb @@ -0,0 +1,48 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +Given /^a base log level of '(.+)'$/ do |level| + Logit.level(level.to_sym) +end + +When /^the message '(.+)' is sent at the '(.+)' level$/ do |message, level| + case level.to_sym + when :debug + Logit.debug(message) + when :info + Logit.info(message) + when :warn + Logit.warn(message) + when :error + Logit.error(message) + when :fatal + Logit.fatal(message) + else + raise ArgumentError, "Level is not one of debug, info, warn, error, or fatal" + end +end + +Then /^the regex '(.+)' should be logged$/ do |regex_string| + regex = Regexp.new(regex_string, Regexp::MULTILINE) + regex.match(@output).should_not == nil +end + +Then /^nothing should be logged$/ do + @output.should == "" +end + diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..56dee6c --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,46 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +$: << File.join(File.dirname(__FILE__), '..', '..', 'lib') + +require 'spec/expectations' +require 'mixlib/log' +require 'tmpdir' +require 'stringio' + +class MyWorld + def initialize + @tmpdir = File.join(Dir.tmpdir, "mixlib_log") + @output = '' + @output_io = StringIO.new(@output) + Logit.init(@output_io) + end +end + +World do + MyWorld.new +end + +Before do + system("mkdir -p #{@tmpdir}") +end + +After do + system("rm -rf #{@tmpdir}") +end + diff --git a/features/support/logit.rb b/features/support/logit.rb new file mode 100644 index 0000000..4bc0d50 --- /dev/null +++ b/features/support/logit.rb @@ -0,0 +1,23 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class Logit + class << self + include Mixlib::Log + end +end
\ No newline at end of file |