Permalink
Browse files

Merge pull request #49 from petemounce/rspec_example

Fix #48; lack of rspec examples
  • Loading branch information...
2 parents c0ff4bb + eb2262b commit aa5c4f924fe2f42f18866115bbb3b3ebcfb59fc4 @TwP committed Oct 8, 2012
Showing with 47 additions and 0 deletions.
  1. +20 −0 examples/rspec_everywhere.rb
  2. +27 −0 examples/rspec_only_some_specs.rb
@@ -0,0 +1,20 @@
+require 'rspec'
+require 'logging'
+#spec_helper - adjust path, because this is applicable to within the logging source-code. Yours would be
+#require 'logging/rspec/logging_helper'
+require 'rspec/logging_helper'
+
+RSpec.configure do |config|
+ include RSpec::LoggingHelper
+ config.capture_log_messages
+end
+
+# a spec file
+describe 'Foo' do
+ it 'should be able to read a log message' do
+ Logging.logger['root'].debug 'foo'
+ @log_output.readline.strip.should =~ /foo/
+ end
+end
+
+RSpec::Core::Runner.run([File.dirname(__FILE__)], $stderr, $stdout)
@@ -0,0 +1,27 @@
+require 'rspec'
+require 'logging'
+#spec_helper - adjust path, because this is applicable to within the logging source-code. Yours would be
+#require 'logging/rspec/logging_helper'
+require 'rspec/logging_helper'
+
+RSpec.configure do |config|
+ config.extend RSpec::LoggingHelper
+end
+
+# a spec file
+describe 'Foo' do
+ capture_log_messages
+ it 'should be able to read a log message' do
+ Logging.logger['root'].debug 'foo'
+ @log_output.readline.strip.should =~ /foo/
+ end
+end
+
+describe 'Bar' do
+ it 'should not be able to read a log message because we did not call capture_log_messages' do
+ Logging.logger['root'].debug 'foo'
+ @log_output.should be_nil
+ end
+end
+
+RSpec::Core::Runner.run([File.dirname(__FILE__)], $stderr, $stdout)

0 comments on commit aa5c4f9

Please sign in to comment.