Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 0407831

Browse files
committed
Remove deprecated color and tty configuration and CLI options
1 parent f12da3a commit 0407831

File tree

11 files changed

+42
-235
lines changed

11 files changed

+42
-235
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Breaking Changes:
1919
execution result. (Phil Pirozhkov, #2862)
2020
* Skip setting the default pattern from Rake task. (Phil Pirozhkov, #2868)
2121
* Remove special `:if`/`:unless` filtering metadata. (Phil Pirozhkov, #2870)
22+
* Remove deprecated `color` configuration option and `--color` command line
23+
option. (Phil Pirozhkov, #2864)
2224

2325
Enhancements:
2426

lib/rspec/core/configuration.rb

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,6 @@ def bisect_runner=(value)
408408
@bisect_runner = value
409409
end
410410

411-
# @private
412-
# @deprecated Use {#color_mode} = :on, instead of {#color} with {#tty}
413-
add_setting :tty
414411
# @private
415412
attr_writer :files_to_run
416413
# @private
@@ -441,7 +438,6 @@ def initialize
441438
@mock_framework = nil
442439
@files_or_directories_to_run = []
443440
@loaded_spec_files = Set.new
444-
@color = false
445441
@color_mode = :automatic
446442
@pattern = '**{,/*/**}/*_spec.rb'
447443
@exclude_pattern = ''
@@ -803,20 +799,6 @@ def full_backtrace=(true_or_false)
803799
@backtrace_formatter.full_backtrace = true_or_false
804800
end
805801

806-
# Enables color output if the output is a TTY. As of RSpec 3.6, this is
807-
# the default behavior and this option is retained only for backwards
808-
# compatibility.
809-
#
810-
# @deprecated No longer recommended because of complex behavior. Instead,
811-
# rely on the fact that TTYs will display color by default, or set
812-
# {#color_mode} to :on to display color on a non-TTY output.
813-
# @see color_mode
814-
# @see color_enabled?
815-
# @return [Boolean]
816-
def color
817-
value_for(:color) { @color }
818-
end
819-
820802
# The mode for determining whether to display output in color. One of:
821803
#
822804
# - :automatic - the output will be in color if the output is a TTY (the
@@ -839,20 +821,13 @@ def color_enabled?(output=output_stream)
839821
when :on then true
840822
when :off then false
841823
else # automatic
842-
output_to_tty?(output) || (color && tty?)
824+
output_to_tty?(output)
843825
end
844826
end
845827

846828
# Set the color mode.
847829
attr_writer :color_mode
848830

849-
# Toggle output color.
850-
#
851-
# @deprecated No longer recommended because of complex behavior. Instead,
852-
# rely on the fact that TTYs will display color by default, or set
853-
# {:color_mode} to :on to display color on a non-TTY output.
854-
attr_writer :color
855-
856831
# @private
857832
def libs=(libs)
858833
libs.map do |lib|

lib/rspec/core/configuration_options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def organize_options
5858

5959
UNFORCED_OPTIONS = Set.new([
6060
:requires, :profile, :drb, :libs, :files_or_directories_to_run,
61-
:full_description, :full_backtrace, :tty
61+
:full_description, :full_backtrace
6262
])
6363

6464
UNPROCESSABLE_OPTIONS = Set.new([:formatters])

lib/rspec/core/drb.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ def initialize(submitted_options, filter_manager)
4040

4141
def options
4242
argv = []
43-
argv << "--color" if @submitted_options[:color]
4443
argv << "--force-color" if @submitted_options[:color_mode] == :on
4544
argv << "--no-color" if @submitted_options[:color_mode] == :off
4645
argv << "--profile" if @submitted_options[:profile_examples]
4746
argv << "--backtrace" if @submitted_options[:full_backtrace]
48-
argv << "--tty" if @submitted_options[:tty]
4947
argv << "--fail-fast" if @submitted_options[:fail_fast]
5048
argv << "--options" << @submitted_options[:custom_options_file] if @submitted_options[:custom_options_file]
5149
argv << "--order" << @submitted_options[:order] if @submitted_options[:order]

lib/rspec/core/option_parser.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def parse(source=nil)
1818
return { :files_or_directories_to_run => [] } if original_args.empty?
1919
args = original_args.dup
2020

21-
options = args.delete('--tty') ? { :tty => true } : {}
21+
options = {}
2222
begin
2323
parser(options).parse!(args)
2424
rescue OptionParser::InvalidOption => e
@@ -140,12 +140,6 @@ def parser(options)
140140
options[:full_backtrace] = true
141141
end
142142

143-
parser.on('-c', '--color', '--colour', '') do |_o|
144-
# flag will be excluded from `--help` output because it is deprecated
145-
options[:color] = true
146-
options[:color_mode] = :automatic
147-
end
148-
149143
parser.on('--force-color', '--force-colour', 'Force the output to be in color, even if the output is not a TTY') do |_o|
150144
if options[:color_mode] == :off
151145
abort "Please only use one of `--force-color` and `--no-color`"

spec/rspec/core/configuration_options_spec.rb

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,6 @@
136136
expect(config.exclusion_filter.rules).to have_key(:slow)
137137
end
138138

139-
it "forces color" do
140-
opts = config_options_object(*%w[--color])
141-
expect(config).to receive(:force).with(:color => true)
142-
expect(config).to receive(:force).with(:color_mode => :automatic)
143-
opts.configure(config)
144-
end
145-
146139
it "forces force_color" do
147140
opts = config_options_object(*%w[--force-color])
148141
expect(config).to receive(:force).with(:color_mode => :on)
@@ -204,36 +197,16 @@
204197
end
205198
end
206199

207-
describe "-c, --color, and --colour" do
208-
it "sets :color_mode => :automatic" do
209-
expect(parse_options('-c')).to include(:color_mode => :automatic)
210-
expect(parse_options('--color')).to include(:color_mode => :automatic)
211-
expect(parse_options('--colour')).to include(:color_mode => :automatic)
212-
end
213-
214-
it "overrides previous color flag" do
215-
expect(parse_options('--no-color', '--color')).to include(:color_mode => :automatic)
216-
end
217-
end
218-
219200
describe "--no-color" do
220201
it "sets :color_mode => :off" do
221202
expect(parse_options('--no-color')).to include(:color_mode => :off)
222203
end
223-
224-
it "overrides previous color flag" do
225-
expect(parse_options('--color', '--no-color')).to include(:color_mode => :off)
226-
end
227204
end
228205

229206
describe "--force-color" do
230207
it "sets :color_mode => :on" do
231208
expect(parse_options('--force-color')).to include(:color_mode => :on)
232209
end
233-
234-
it "overrides previous color flag" do
235-
expect(parse_options('--color', '--force-color')).to include(:color_mode => :on)
236-
end
237210
end
238211

239212
describe "-I" do
@@ -365,8 +338,8 @@
365338
end
366339

367340
describe "files_or_directories_to_run" do
368-
it "parses files from '-c file.rb dir/file.rb'" do
369-
expect(parse_options("-c", "file.rb", "dir/file.rb")).to include(
341+
it "parses files from '--no-color file.rb dir/file.rb'" do
342+
expect(parse_options("--no-color", "file.rb", "dir/file.rb")).to include(
370343
:files_or_directories_to_run => ["file.rb", "dir/file.rb"]
371344
)
372345
end

spec/rspec/core/configuration_spec.rb

Lines changed: 22 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,11 +1265,20 @@ def metadata_hash(*args)
12651265

12661266
end
12671267

1268-
describe "#color_mode" do
1269-
context ":automatic" do
1270-
before do
1271-
config.color_mode = :automatic
1272-
end
1268+
describe "#color_enabled?" do
1269+
it "allows overriding instance output stream with an argument" do
1270+
config.output_stream = StringIO.new
1271+
output_override = StringIO.new
1272+
1273+
allow(config.output_stream).to receive_messages(:tty? => false)
1274+
allow(output_override).to receive_messages(:tty? => true)
1275+
1276+
expect(config.color_enabled?).to be false
1277+
expect(config.color_enabled?(output_override)).to be true
1278+
end
1279+
1280+
context "with color_mode :automatic" do
1281+
before { config.color_mode = :automatic }
12731282

12741283
context "with output.tty?" do
12751284
it "sets color_enabled?" do
@@ -1288,10 +1297,8 @@ def metadata_hash(*args)
12881297
end
12891298
end
12901299

1291-
context ":on" do
1292-
before do
1293-
config.color_mode = :on
1294-
end
1300+
context "with color_mode :on" do
1301+
before { config.color_mode = :on }
12951302

12961303
context "with output.tty?" do
12971304
it "sets color_enabled?" do
@@ -1310,10 +1317,8 @@ def metadata_hash(*args)
13101317
end
13111318
end
13121319

1313-
context ":off" do
1314-
before do
1315-
config.color_mode = :off
1316-
end
1320+
context "with color_mode :off" do
1321+
before { config.color_mode = :off }
13171322

13181323
context "with output.tty?" do
13191324
it "sets !color_enabled?" do
@@ -1330,151 +1335,15 @@ def metadata_hash(*args)
13301335
expect(config.color_enabled?).to be false
13311336
end
13321337
end
1333-
1334-
it "prefers incoming cli_args" do
1335-
config.output_stream = StringIO.new
1336-
config.force :color_mode => :on
1337-
config.color_mode = :off
1338-
expect(config.color_mode).to be :on
1339-
end
1340-
end
1341-
end
1342-
1343-
describe "#color_enabled?" do
1344-
it "allows overriding instance output stream with an argument" do
1345-
config.output_stream = StringIO.new
1346-
output_override = StringIO.new
1347-
1348-
config.color_mode = :automatic
1349-
allow(config.output_stream).to receive_messages(:tty? => false)
1350-
allow(output_override).to receive_messages(:tty? => true)
1351-
1352-
expect(config.color_enabled?).to be false
1353-
expect(config.color_enabled?(output_override)).to be true
13541338
end
13551339
end
13561340

1357-
describe "#color=" do
1358-
before { config.color_mode = :automatic }
1359-
1360-
context "given false" do
1361-
before { config.color = false }
1362-
1363-
context "with config.tty? and output.tty?" do
1364-
it "sets color_enabled?" do
1365-
output = StringIO.new
1366-
config.output_stream = output
1367-
1368-
config.tty = true
1369-
allow(config.output_stream).to receive_messages(:tty? => true)
1370-
1371-
expect(config.color_enabled?).to be true
1372-
expect(config.color_enabled?(output)).to be true
1373-
end
1374-
end
1375-
1376-
context "with config.tty? and !output.tty?" do
1377-
it "does not set color_enabled?" do
1378-
output = StringIO.new
1379-
config.output_stream = output
1380-
1381-
config.tty = true
1382-
allow(config.output_stream).to receive_messages(:tty? => false)
1383-
1384-
expect(config.color_enabled?).to be false
1385-
expect(config.color_enabled?(output)).to be false
1386-
end
1387-
end
1388-
1389-
context "with !config.tty? and output.tty?" do
1390-
it "sets color_enabled?" do
1391-
output = StringIO.new
1392-
config.output_stream = output
1393-
1394-
config.tty = false
1395-
allow(config.output_stream).to receive_messages(:tty? => true)
1396-
1397-
expect(config.color_enabled?).to be true
1398-
expect(config.color_enabled?(output)).to be true
1399-
end
1400-
end
1401-
1402-
context "with !config.tty? and !output.tty?" do
1403-
it "does not set color_enabled?" do
1404-
output = StringIO.new
1405-
config.output_stream = output
1406-
1407-
config.tty = false
1408-
allow(config.output_stream).to receive_messages(:tty? => false)
1409-
1410-
expect(config.color_enabled?).to be false
1411-
expect(config.color_enabled?(output)).to be false
1412-
end
1413-
end
1414-
end
1415-
1416-
context "given true" do
1417-
before { config.color = true }
1418-
1419-
context "with config.tty? and output.tty?" do
1420-
it "sets color_enabled?" do
1421-
output = StringIO.new
1422-
config.output_stream = output
1423-
1424-
config.tty = true
1425-
allow(config.output_stream).to receive_messages(:tty? => true)
1426-
1427-
expect(config.color_enabled?).to be true
1428-
expect(config.color_enabled?(output)).to be true
1429-
end
1430-
end
1431-
1432-
context "with config.tty? and !output.tty?" do
1433-
it "sets color_enabled?" do
1434-
output = StringIO.new
1435-
config.output_stream = output
1436-
1437-
config.tty = true
1438-
allow(config.output_stream).to receive_messages(:tty? => false)
1439-
1440-
expect(config.color_enabled?).to be true
1441-
expect(config.color_enabled?(output)).to be true
1442-
end
1443-
end
1444-
1445-
context "with !config.tty? and output.tty?" do
1446-
it "sets color_enabled?" do
1447-
output = StringIO.new
1448-
config.output_stream = output
1449-
1450-
config.tty = false
1451-
allow(config.output_stream).to receive_messages(:tty? => true)
1452-
1453-
expect(config.color_enabled?).to be true
1454-
expect(config.color_enabled?(output)).to be true
1455-
end
1456-
end
1457-
1458-
context "with !config.tty? and !output.tty?" do
1459-
it "does not set color_enabled?" do
1460-
output = StringIO.new
1461-
config.output_stream = output
1462-
1463-
config.tty = false
1464-
allow(config.output_stream).to receive_messages(:tty? => false)
1465-
1466-
expect(config.color_enabled?).to be false
1467-
expect(config.color_enabled?(output)).to be false
1468-
end
1469-
end
1470-
end
1471-
1341+
describe '#color_mode' do
14721342
it "prefers incoming cli_args" do
14731343
config.output_stream = StringIO.new
1474-
allow(config.output_stream).to receive_messages(:tty? => true)
1475-
config.force :color => true
1476-
config.color = false
1477-
expect(config.color).to be true
1344+
config.force :color_mode => :on
1345+
config.color_mode = :off
1346+
expect(config.color_mode).to be :on
14781347
end
14791348
end
14801349

0 commit comments

Comments
 (0)