Permalink
Browse files

forward port support for color on Windows from rspec-1

  • Loading branch information...
1 parent 22553eb commit 2b6ba51b3e3de2795d70dac2e405da319c475b8c @dchelimsky dchelimsky committed Jun 11, 2010
Showing with 68 additions and 5 deletions.
  1. +16 −0 lib/rspec/core/configuration.rb
  2. +3 −5 rspec-core.gemspec
  3. +49 −0 spec/rspec/core/configuration_spec.rb
@@ -120,6 +120,22 @@ def full_backtrace=(bool)
backtrace_clean_patterns.clear
end
+ def color_enabled=(bool)
+ return unless bool
+ settings[:color_enabled] = true
+ if bool && Config::CONFIG['host_os'] =~ /mswin|mingw/
+ orig_output_stream = settings[:output_stream]
+ begin
+ require 'Win32/Console/ANSI'
+ rescue LoadError
+ warn "You must 'gem install win32console' to use colour on Windows"
+ settings[:color_enabled] = false
+ ensure
+ settings[:output_stream] = orig_output_stream
+ end
+ end
+ end
+
def libs=(libs)
libs.map {|lib| $LOAD_PATH.unshift lib}
end
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Chad Humphries", "David Chelimsky"]
- s.date = %q{2010-06-06}
+ s.date = %q{2010-06-10}
s.description = %q{RSpec runner and example group classes}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
s.executables = ["rspec", "spec"]
@@ -110,6 +110,7 @@ Gem::Specification.new do |s|
"spec/rspec/core/kernel_extensions_spec.rb",
"spec/rspec/core/let_spec.rb",
"spec/rspec/core/metadata_spec.rb",
+ "spec/rspec/core/option_parser_spec.rb",
"spec/rspec/core/pending_example_spec.rb",
"spec/rspec/core/resources/a_bar.rb",
"spec/rspec/core/resources/a_foo.rb",
@@ -131,10 +132,6 @@ Gem::Specification.new do |s|
s.post_install_message = %q{**************************************************
Thank you for installing rspec-core-2.0.0.beta.11
-
- This is beta software. If you are looking
- for a supported production release, please
- "gem install rspec" (without --pre).
**************************************************
}
@@ -160,6 +157,7 @@ Gem::Specification.new do |s|
"spec/rspec/core/kernel_extensions_spec.rb",
"spec/rspec/core/let_spec.rb",
"spec/rspec/core/metadata_spec.rb",
+ "spec/rspec/core/option_parser_spec.rb",
"spec/rspec/core/pending_example_spec.rb",
"spec/rspec/core/resources/a_bar.rb",
"spec/rspec/core/resources/a_foo.rb",
@@ -181,6 +181,55 @@ def that_thing
config.run_all_when_everything_filtered?.should == true
end
end
+
+ describe 'color_enabled=' do
+ context "given true" do
+ context "on windows" do
+ before do
+ @original_host = Config::CONFIG['host_os']
+ Config::CONFIG['host_os'] = 'mswin'
+ config.stub(:require)
+ config.stub(:warn)
+ end
+
+ after do
+ Config::CONFIG['host_os'] = @original_host
+ end
+
+ context "with win32console available" do
+ it "requires win32console" do
+ config.should_receive(:require).
+ with("Win32/Console/ANSI")
+ config.color_enabled = true
+ end
+
+ it "leaves output stream intact" do
+ config.output_stream = $stdout
+ config.stub(:require) do |what|
+ config.output_stream = 'foo' if what =~ /Win32/
+ end
+ config.color_enabled = true
+ config.output_stream.should eq($stdout)
+ end
+ end
+
+ context "with win32console NOT available" do
+ it "warns to install win32console" do
+ config.stub(:require) { raise LoadError }
+ config.should_receive(:warn).
+ with /You must 'gem install win32console'/
+ config.color_enabled = true
+ end
+
+ it "sets color_enabled to false" do
+ config.stub(:require) { raise LoadError }
+ config.color_enabled = true
+ config.color_enabled.should be_false
+ end
+ end
+ end
+ end
+ end
describe 'formatter=' do

0 comments on commit 2b6ba51

Please sign in to comment.