Skip to content

Commit

Permalink
Remove deprecated color and tty configuration and CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Feb 18, 2021
1 parent f12da3a commit 0407831
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 235 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Breaking Changes:
execution result. (Phil Pirozhkov, #2862)
* Skip setting the default pattern from Rake task. (Phil Pirozhkov, #2868)
* Remove special `:if`/`:unless` filtering metadata. (Phil Pirozhkov, #2870)
* Remove deprecated `color` configuration option and `--color` command line
option. (Phil Pirozhkov, #2864)

Enhancements:

Expand Down
27 changes: 1 addition & 26 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,6 @@ def bisect_runner=(value)
@bisect_runner = value
end

# @private
# @deprecated Use {#color_mode} = :on, instead of {#color} with {#tty}
add_setting :tty
# @private
attr_writer :files_to_run
# @private
Expand Down Expand Up @@ -441,7 +438,6 @@ def initialize
@mock_framework = nil
@files_or_directories_to_run = []
@loaded_spec_files = Set.new
@color = false
@color_mode = :automatic
@pattern = '**{,/*/**}/*_spec.rb'
@exclude_pattern = ''
Expand Down Expand Up @@ -803,20 +799,6 @@ def full_backtrace=(true_or_false)
@backtrace_formatter.full_backtrace = true_or_false
end

# Enables color output if the output is a TTY. As of RSpec 3.6, this is
# the default behavior and this option is retained only for backwards
# compatibility.
#
# @deprecated No longer recommended because of complex behavior. Instead,
# rely on the fact that TTYs will display color by default, or set
# {#color_mode} to :on to display color on a non-TTY output.
# @see color_mode
# @see color_enabled?
# @return [Boolean]
def color
value_for(:color) { @color }
end

# The mode for determining whether to display output in color. One of:
#
# - :automatic - the output will be in color if the output is a TTY (the
Expand All @@ -839,20 +821,13 @@ def color_enabled?(output=output_stream)
when :on then true
when :off then false
else # automatic
output_to_tty?(output) || (color && tty?)
output_to_tty?(output)
end
end

# Set the color mode.
attr_writer :color_mode

# Toggle output color.
#
# @deprecated No longer recommended because of complex behavior. Instead,
# rely on the fact that TTYs will display color by default, or set
# {:color_mode} to :on to display color on a non-TTY output.
attr_writer :color

# @private
def libs=(libs)
libs.map do |lib|
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/configuration_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def organize_options

UNFORCED_OPTIONS = Set.new([
:requires, :profile, :drb, :libs, :files_or_directories_to_run,
:full_description, :full_backtrace, :tty
:full_description, :full_backtrace
])

UNPROCESSABLE_OPTIONS = Set.new([:formatters])
Expand Down
2 changes: 0 additions & 2 deletions lib/rspec/core/drb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ def initialize(submitted_options, filter_manager)

def options
argv = []
argv << "--color" if @submitted_options[:color]
argv << "--force-color" if @submitted_options[:color_mode] == :on
argv << "--no-color" if @submitted_options[:color_mode] == :off
argv << "--profile" if @submitted_options[:profile_examples]
argv << "--backtrace" if @submitted_options[:full_backtrace]
argv << "--tty" if @submitted_options[:tty]
argv << "--fail-fast" if @submitted_options[:fail_fast]
argv << "--options" << @submitted_options[:custom_options_file] if @submitted_options[:custom_options_file]
argv << "--order" << @submitted_options[:order] if @submitted_options[:order]
Expand Down
8 changes: 1 addition & 7 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def parse(source=nil)
return { :files_or_directories_to_run => [] } if original_args.empty?
args = original_args.dup

options = args.delete('--tty') ? { :tty => true } : {}
options = {}
begin
parser(options).parse!(args)
rescue OptionParser::InvalidOption => e
Expand Down Expand Up @@ -140,12 +140,6 @@ def parser(options)
options[:full_backtrace] = true
end

parser.on('-c', '--color', '--colour', '') do |_o|
# flag will be excluded from `--help` output because it is deprecated
options[:color] = true
options[:color_mode] = :automatic
end

parser.on('--force-color', '--force-colour', 'Force the output to be in color, even if the output is not a TTY') do |_o|
if options[:color_mode] == :off
abort "Please only use one of `--force-color` and `--no-color`"
Expand Down
31 changes: 2 additions & 29 deletions spec/rspec/core/configuration_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@
expect(config.exclusion_filter.rules).to have_key(:slow)
end

it "forces color" do
opts = config_options_object(*%w[--color])
expect(config).to receive(:force).with(:color => true)
expect(config).to receive(:force).with(:color_mode => :automatic)
opts.configure(config)
end

it "forces force_color" do
opts = config_options_object(*%w[--force-color])
expect(config).to receive(:force).with(:color_mode => :on)
Expand Down Expand Up @@ -204,36 +197,16 @@
end
end

describe "-c, --color, and --colour" do
it "sets :color_mode => :automatic" do
expect(parse_options('-c')).to include(:color_mode => :automatic)
expect(parse_options('--color')).to include(:color_mode => :automatic)
expect(parse_options('--colour')).to include(:color_mode => :automatic)
end

it "overrides previous color flag" do
expect(parse_options('--no-color', '--color')).to include(:color_mode => :automatic)
end
end

describe "--no-color" do
it "sets :color_mode => :off" do
expect(parse_options('--no-color')).to include(:color_mode => :off)
end

it "overrides previous color flag" do
expect(parse_options('--color', '--no-color')).to include(:color_mode => :off)
end
end

describe "--force-color" do
it "sets :color_mode => :on" do
expect(parse_options('--force-color')).to include(:color_mode => :on)
end

it "overrides previous color flag" do
expect(parse_options('--color', '--force-color')).to include(:color_mode => :on)
end
end

describe "-I" do
Expand Down Expand Up @@ -365,8 +338,8 @@
end

describe "files_or_directories_to_run" do
it "parses files from '-c file.rb dir/file.rb'" do
expect(parse_options("-c", "file.rb", "dir/file.rb")).to include(
it "parses files from '--no-color file.rb dir/file.rb'" do
expect(parse_options("--no-color", "file.rb", "dir/file.rb")).to include(
:files_or_directories_to_run => ["file.rb", "dir/file.rb"]
)
end
Expand Down
175 changes: 22 additions & 153 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1265,11 +1265,20 @@ def metadata_hash(*args)

end

describe "#color_mode" do
context ":automatic" do
before do
config.color_mode = :automatic
end
describe "#color_enabled?" do
it "allows overriding instance output stream with an argument" do
config.output_stream = StringIO.new
output_override = StringIO.new

allow(config.output_stream).to receive_messages(:tty? => false)
allow(output_override).to receive_messages(:tty? => true)

expect(config.color_enabled?).to be false
expect(config.color_enabled?(output_override)).to be true
end

context "with color_mode :automatic" do
before { config.color_mode = :automatic }

context "with output.tty?" do
it "sets color_enabled?" do
Expand All @@ -1288,10 +1297,8 @@ def metadata_hash(*args)
end
end

context ":on" do
before do
config.color_mode = :on
end
context "with color_mode :on" do
before { config.color_mode = :on }

context "with output.tty?" do
it "sets color_enabled?" do
Expand All @@ -1310,10 +1317,8 @@ def metadata_hash(*args)
end
end

context ":off" do
before do
config.color_mode = :off
end
context "with color_mode :off" do
before { config.color_mode = :off }

context "with output.tty?" do
it "sets !color_enabled?" do
Expand All @@ -1330,151 +1335,15 @@ def metadata_hash(*args)
expect(config.color_enabled?).to be false
end
end

it "prefers incoming cli_args" do
config.output_stream = StringIO.new
config.force :color_mode => :on
config.color_mode = :off
expect(config.color_mode).to be :on
end
end
end

describe "#color_enabled?" do
it "allows overriding instance output stream with an argument" do
config.output_stream = StringIO.new
output_override = StringIO.new

config.color_mode = :automatic
allow(config.output_stream).to receive_messages(:tty? => false)
allow(output_override).to receive_messages(:tty? => true)

expect(config.color_enabled?).to be false
expect(config.color_enabled?(output_override)).to be true
end
end

describe "#color=" do
before { config.color_mode = :automatic }

context "given false" do
before { config.color = false }

context "with config.tty? and output.tty?" do
it "sets color_enabled?" do
output = StringIO.new
config.output_stream = output

config.tty = true
allow(config.output_stream).to receive_messages(:tty? => true)

expect(config.color_enabled?).to be true
expect(config.color_enabled?(output)).to be true
end
end

context "with config.tty? and !output.tty?" do
it "does not set color_enabled?" do
output = StringIO.new
config.output_stream = output

config.tty = true
allow(config.output_stream).to receive_messages(:tty? => false)

expect(config.color_enabled?).to be false
expect(config.color_enabled?(output)).to be false
end
end

context "with !config.tty? and output.tty?" do
it "sets color_enabled?" do
output = StringIO.new
config.output_stream = output

config.tty = false
allow(config.output_stream).to receive_messages(:tty? => true)

expect(config.color_enabled?).to be true
expect(config.color_enabled?(output)).to be true
end
end

context "with !config.tty? and !output.tty?" do
it "does not set color_enabled?" do
output = StringIO.new
config.output_stream = output

config.tty = false
allow(config.output_stream).to receive_messages(:tty? => false)

expect(config.color_enabled?).to be false
expect(config.color_enabled?(output)).to be false
end
end
end

context "given true" do
before { config.color = true }

context "with config.tty? and output.tty?" do
it "sets color_enabled?" do
output = StringIO.new
config.output_stream = output

config.tty = true
allow(config.output_stream).to receive_messages(:tty? => true)

expect(config.color_enabled?).to be true
expect(config.color_enabled?(output)).to be true
end
end

context "with config.tty? and !output.tty?" do
it "sets color_enabled?" do
output = StringIO.new
config.output_stream = output

config.tty = true
allow(config.output_stream).to receive_messages(:tty? => false)

expect(config.color_enabled?).to be true
expect(config.color_enabled?(output)).to be true
end
end

context "with !config.tty? and output.tty?" do
it "sets color_enabled?" do
output = StringIO.new
config.output_stream = output

config.tty = false
allow(config.output_stream).to receive_messages(:tty? => true)

expect(config.color_enabled?).to be true
expect(config.color_enabled?(output)).to be true
end
end

context "with !config.tty? and !output.tty?" do
it "does not set color_enabled?" do
output = StringIO.new
config.output_stream = output

config.tty = false
allow(config.output_stream).to receive_messages(:tty? => false)

expect(config.color_enabled?).to be false
expect(config.color_enabled?(output)).to be false
end
end
end

describe '#color_mode' do
it "prefers incoming cli_args" do
config.output_stream = StringIO.new
allow(config.output_stream).to receive_messages(:tty? => true)
config.force :color => true
config.color = false
expect(config.color).to be true
config.force :color_mode => :on
config.color_mode = :off
expect(config.color_mode).to be :on
end
end

Expand Down
Loading

0 comments on commit 0407831

Please sign in to comment.