changes to stdout and -err - tests and behaviour

By using $stdin adn $stderr instead of STDIN and 
STDERR it is possible to capture or redirect them 
using in process ruby code without the need
to manage pipes and external processes
This commit is contained in:
Gregor Schmidt 2009-11-24 21:40:56 +01:00
parent 2f2e45bedf
commit 597c7a7904
2 changed files with 8 additions and 8 deletions

View File

@ -67,10 +67,10 @@ module Jekyll
begin
config = YAML.load_file(config_file)
raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
STDOUT.puts "Configuration from #{config_file}"
$stdout.puts "Configuration from #{config_file}"
rescue => err
STDERR.puts "WARNING: Could not read configuration. Using defaults (and options)."
STDERR.puts "\t" + err.to_s
$stderr.puts "WARNING: Could not read configuration. Using defaults (and options)."
$stderr.puts "\t" + err.to_s
config = {}
end

View File

@ -8,21 +8,21 @@ class TestConfiguration < Test::Unit::TestCase
should "fire warning with no _config.yml" do
mock(YAML).load_file(@path) { raise "No such file or directory - #{@path}" }
mock(STDERR).puts("WARNING: Could not read configuration. Using defaults (and options).")
mock(STDERR).puts("\tNo such file or directory - #{@path}")
mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
mock($stderr).puts("\tNo such file or directory - #{@path}")
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
end
should "load configuration as hash" do
mock(YAML).load_file(@path) { Hash.new }
mock(STDOUT).puts("Configuration from #{@path}")
mock($stdout).puts("Configuration from #{@path}")
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
end
should "fire warning with bad config" do
mock(YAML).load_file(@path) { Array.new }
mock(STDERR).puts("WARNING: Could not read configuration. Using defaults (and options).")
mock(STDERR).puts("\tInvalid configuration - #{@path}")
mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
mock($stderr).puts("\tInvalid configuration - #{@path}")
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
end
end