Permalink
Browse files

--color on command line or in .rspec (etc) overrides setting in RSpec…

….configure
  • Loading branch information...
1 parent 60379b8 commit b563e7d295d9f58f2dac5219e4733cfab1213539 @dchelimsky dchelimsky committed Nov 3, 2011
@@ -85,6 +85,11 @@ def initialize
@default_path = 'spec'
@exclusion_filter = DEFAULT_EXCLUSION_FILTERS.dup
@seed = srand % 0xFFFF
+ @dominant_options = {}
+ end
+
+ def force(hash)
+ @dominant_options.merge!(hash)
end
def reset
@@ -255,7 +260,8 @@ def full_backtrace=(true_or_false)
end
def color
- @color && output_to_tty?
+ return false unless output_to_tty?
+ value_for(:color, @color)
end
def color=(bool)
@@ -571,6 +577,14 @@ def order=(type)
private
+ def value_for(key, default=nil)
+ # TODO - not sure about this name, but that's partially due to the need
+ # for a default value. Once we align the CLI options with the
+ # RSpec.configure options we can glean the default from the key, then
+ # this name makes more sense.
+ @dominant_options.has_key?(key) ? @dominant_options[key] : default
+ end
+
def add_location(file_path, line_numbers)
# filter_locations is a hash of expanded paths to arrays of line
# numbers to match against.
@@ -15,7 +15,13 @@ def configure(config)
exclusion_filter = options.delete(:exclusion_filter)
order(options.keys, :libs, :requires, :default_path, :pattern).each do |key|
- config.send("#{key}=", options[key]) if config.respond_to?("#{key}=")
+ # temp to get through refactoring - eventually all options will be
+ # set using force
+ if key == :color
+ config.force :color => options[key]
+ else
+ config.send("#{key}=", options[key]) if config.respond_to?("#{key}=")
+ end
end
formatters.each {|pair| config.add_formatter(*pair) } if formatters
@@ -95,7 +95,7 @@ def config_options(argv=[])
# this is necessary to ensure that color works correctly on windows
config.should_receive(:error_stream=).ordered
config.should_receive(:output_stream=).ordered
- config.should_receive(:color=).ordered
+ config.should_receive(:force).with(:color => true).ordered
command_line.run(err, out) rescue nil
end
@@ -54,6 +54,13 @@
opts.configure(config)
config.exclusion_filter.should have_key(:slow)
end
+
+ it "forces color_enabled" do
+ opts = config_options_object(*%w[--color])
+ config = RSpec::Core::Configuration.new
+ config.should_receive(:force).with(:color => true)
+ opts.configure(config)
+ end
end
describe "-c, --color, and --colour" do
@@ -512,6 +512,14 @@ def metadata_hash(*args)
end
end
end
+
+ it "prefers incoming cli_args" do
+ config.output_stream = StringIO.new
+ config.output_stream.stub :tty? => true
+ config.force :color => true
+ config.color = false
+ config.color.should be_true
+ end
end
describe '#formatter=' do

0 comments on commit b563e7d

Please sign in to comment.