Permalink
Browse files

Use ANSICON instead of win32console

- Closes #234.
  • Loading branch information...
1 parent 76e0d64 commit d5a39c92f90bc21ae6fe2ed54429033a680572bd @bosko bosko committed with dchelimsky Nov 27, 2010
Showing with 25 additions and 59 deletions.
  1. +2 −8 lib/rspec/core/configuration.rb
  2. +23 −51 spec/rspec/core/configuration_spec.rb
@@ -160,14 +160,8 @@ def color_enabled=(bool)
return unless bool
@color_enabled = true
if bool && ::RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
- using_stdout = settings[:output_stream] == $stdout
- using_stderr = settings[:error_stream] == $stderr
- begin
- require 'Win32/Console/ANSI'
- settings[:output_stream] = $stdout if using_stdout
- settings[:error_stream] = $stderr if using_stderr
- rescue LoadError
- warn "You must 'gem install win32console' to use colour on Windows"
+ unless ENV['ANSICON']
+ warn "You must use ANSICON 1.31 or later (http://adoxa.110mb.com/ansicon/) to use colour on Windows"
@color_enabled = false
end
end
@@ -285,75 +285,47 @@ def that_thing
context "on windows" do
before do
@original_host = RbConfig::CONFIG['host_os']
- @original_stdout = $stdout
- @original_stderr = $stderr
- RbConfig::CONFIG['host_os'] = 'mswin'
+ RbConfig::CONFIG['host_os'] = 'mingw'
config.stub(:require)
config.stub(:warn)
end
after do
RbConfig::CONFIG['host_os'] = @original_host
- $stdout = @original_stdout
- $stderr = @original_stderr
end
- context "with win32console available" do
- it "requires win32console" do
- config.should_receive(:require).
- with("Win32/Console/ANSI")
- config.color_enabled = true
+ context "with ANSICON available" do
+ before(:all) do
+ @original_ansicon = ENV['ANSICON']
+ ENV['ANSICON'] = 'ANSICON'
end
- context "with $stdout/err assigned to config.output/error_stream" do
- it "reassigns new $stdout to output_stream" do
- config.output_stream = $stdout
- substitute_stdout = StringIO.new
- config.stub(:require) do |what|
- $stdout = substitute_stdout if what =~ /Win32/
- end
- config.color_enabled = true
- config.output_stream.should eq(substitute_stdout)
- end
-
- it "reassigns new $stderr to error_stream" do
- config.error_stream = $stderr
- substitute_stderr = StringIO.new
- config.stub(:require) do |what|
- $stderr = substitute_stderr if what =~ /Win32/
- end
- config.color_enabled = true
- config.error_stream.should eq(substitute_stderr)
- end
+ after(:all) do
+ ENV['ANSICON'] = @original_ansicon
+ end
+
+ it "enables colors" do
+ config.output_stream = StringIO.new
+ config.output_stream.stub(:tty?) { true }
+ config.color_enabled = true
+ config.color_enabled.should be_true
end
- context "without $stdout/err assigned to config.output/error_stream" do
- it "leaves output stream intact" do
- config.output_stream = output_stream = StringIO.new
- config.stub(:require) do |what|
- $stdout = StringIO.new if what =~ /Win32/
- end
- config.color_enabled = true
- config.output_stream.should eq(output_stream)
- end
-
- it "leaves error stream intact" do
- config.error_stream = error_stream = StringIO.new
- config.stub(:require) do |what|
- $stderr = StringIO.new if what =~ /Win32/
- end
- config.color_enabled = true
- config.error_stream.should eq(error_stream)
+ 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
+ context "with ANSICON NOT available" do
+ it "warns to install ANSICON" do
config.stub(:require) { raise LoadError }
config.should_receive(:warn).
- with(/You must 'gem install win32console'/)
+ with(/You must use ANSICON/)
config.color_enabled = true
end

0 comments on commit d5a39c9

Please sign in to comment.