Browse files

Support for rspec 2

  • Loading branch information...
1 parent 04dcab4 commit 69d8221980251e64c93def344c2428891026c623 @TwP committed Aug 18, 2011
Showing with 46 additions and 31 deletions.
  1. +39 −0 lib/rspec/logging_helper.rb
  2. +7 −31 lib/spec/logging_helper.rb
View
39 lib/rspec/logging_helper.rb
@@ -0,0 +1,39 @@
+
+module RSpec
+ module LoggingHelper
+
+ # Capture log messages from the Logging framework and make them
+ # available via a @log_output instance variable. The @log_output
+ # supports a readline method to access the log messags.
+ #
+ def capture_log_messages( opts = {} )
+ from = opts.getopt(:from, 'root')
+ to = opts.getopt(:to, '__rspec__')
+ exclusive = opts.getopt(:exclusive, true)
+
+ appender = Logging::Appenders[to] || Logging::Appenders::StringIo.new(to)
+ logger = Logging::Logger[from]
+ if exclusive
+ logger.appenders = appender
+ else
+ logger.add_appenders(appender)
+ end
+
+ before(:all) do
+ @log_output = Logging::Appenders[to]
+ end
+
+ before(:each) do
+ @log_output.reset
+ end
+ end
+
+ end # module LoggingHelper
+end # module RSpec
+
+if defined? RSpec::Core::Configuration
+ class RSpec::Core::Configuration
+ include RSpec::LoggingHelper
+ end
+end
+
View
38 lib/spec/logging_helper.rb
@@ -1,34 +1,10 @@
-module Spec
- module LoggingHelper
+require File.expand_path('../../rspec/logging_helper', __FILE__)
+Spec::LoggingHelper = RSpec::LoggingHelper
- # Capture log messages from the Logging framework and make them
- # available via a @log_output instance variable. The @log_output
- # supports a readline method to access the log messags.
- #
- def capture_log_messages( opts = {} )
- from = opts.getopt(:from, 'root')
- to = opts.getopt(:to, '__rspec__')
- exclusive = opts.getopt(:exclusive, true)
+if defined? Spec::Runner::Configuration
+ class Spec::Runner::Configuration
+ include Spec::LoggingHelper
+ end
+end
- appender = Logging::Appenders[to] || Logging::Appenders::StringIo.new(to)
- logger = Logging::Logger[from]
- if exclusive
- logger.appenders = appender
- else
- logger.add_appenders(appender)
- end
-
- before(:all) do
- @log_output = Logging::Appenders[to]
- end
-
- before(:each) do
- @log_output.reset
- end
- end
-
- end # module LoggingHelper
-end # module Spec
-
-# EOF

0 comments on commit 69d8221

Please sign in to comment.