Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #49 from petemounce/rspec_example

Fix #48; lack of rspec examples
  • Loading branch information...
commit aa5c4f924fe2f42f18866115bbb3b3ebcfb59fc4 2 parents c0ff4bb + eb2262b
@TwP authored
Showing with 47 additions and 0 deletions.
  1. +20 −0 examples/rspec_everywhere.rb
  2. +27 −0 examples/rspec_only_some_specs.rb
View
20 examples/rspec_everywhere.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)
View
27 examples/rspec_only_some_specs.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.