Permalink
Browse files

Using the new logging capture mechanism to grab log messages.

  • Loading branch information...
TwP committed Apr 11, 2009
1 parent bcae2c4 commit 290defb36366b5b93f2030d5417d9daa2fbe0244
Showing with 36 additions and 40 deletions.
  1. +24 −0 spec/helpers/webby_helper.rb
  2. +11 −28 spec/spec_helper.rb
  3. +1 −12 spec/webby/apps/generator_spec.rb
@@ -0,0 +1,24 @@
+
+# Add a datapath method to webby
+module Webby
+ DATAPATH = ::Webby.path(%w[spec data])
+ def self.datapath( *args )
+ args.empty? ? DATAPATH : ::File.join(DATAPATH, args.flatten)
+ end
+end
+
+module WebbyHelper
+ def webby_site_setup
+ before(:all) do
+ @pwd = Dir.pwd
+ Dir.chdir Webby.datapath('site')
+ FileUtils.mkdir_p Webby.datapath('site', ::Webby.site.output_dir)
+ end
+
+ after(:all) do
+ FileUtils.rm_rf(Webby.datapath('site', ::Webby.cairn))
+ FileUtils.rm_rf(Dir.glob(Webby.datapath(%w[site output *])))
+ Dir.chdir @pwd
+ end
+ end
+end
View
@@ -3,9 +3,6 @@
unless defined? WEBBY_SPEC_HELPER
WEBBY_SPEC_HELPER = true
-require 'fileutils'
-require 'stringio'
-
begin
require 'fake_web'
$test_externals = true
@@ -14,21 +11,17 @@
$test_externals = false
end
-require File.expand_path(
- File.join(File.dirname(__FILE__), %w[.. lib webby]))
+require 'fileutils'
+require 'spec'
+require 'spec/logging_helper'
+
+dir = File.expand_path(File.dirname(__FILE__))
+require File.join(dir, %w[.. lib webby])
+Dir.glob(File.join(dir, %w[helpers *_helper.rb])).each {|fn| require fn}
Spec::Runner.configure do |config|
- config.before :all do
- @pwd = Dir.pwd
- Dir.chdir Webby.datapath('site')
- FileUtils.mkdir_p Webby.datapath('site', ::Webby.site.output_dir)
- end
-
- config.after :all do
- FileUtils.rm_rf(Webby.datapath('site', ::Webby.cairn))
- FileUtils.rm_rf(Dir.glob(Webby.datapath(%w[site output *])))
- Dir.chdir @pwd
- end
+ include Spec::LoggingHelper
+ include WebbyHelper
# == Mock Framework
#
@@ -38,21 +31,11 @@
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
-end
-module Webby
- DATAPATH = ::Webby.path(%w[spec data])
- def self.datapath( *args )
- args.empty? ? DATAPATH : ::File.join(DATAPATH, args.flatten)
- end
+ config.capture_log_messages :from => 'Webby'
+ config.webby_site_setup
end
-$webby_log_output = StringIO.new
-
-logger = Logging::Logger['Webby']
-logger.clear_appenders
-logger.add_appenders(Logging::Appenders::IO.new('stringio', $webby_log_output))
-
end # unless defined?
# EOF
@@ -87,19 +87,8 @@
describe "when parsing command line arguments" do
before :each do
- @strio = StringIO.new
- ::Logging::Logger['Webby::Journal'].appenders =
- ::Logging::Appenders::IO.new('test', @strio)
+ @strio = @log_output.sio
@generator = Webby::Apps::Generator.new(@strio)
-
- class << @strio
- def to_s
- seek 0
- str = read
- truncate 0
- return str
- end
- end
end
it "should force the overwriting of files on collision" do

0 comments on commit 290defb

Please sign in to comment.