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

Commit f501c66

Browse files
committed
Remove deprecated color configuration option
1 parent b92e94d commit f501c66

File tree

5 files changed

+24
-180
lines changed

5 files changed

+24
-180
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Breaking Changes:
1717
(Phil Pirozhkov, #2851)
1818
* Remove deprecated Hash-like behavior from example
1919
execution result. (Phil Pirozhkov, #2862)
20+
* Remove deprecated `color` configuration option. (Phil Pirozhkov, #2864)
2021

2122
Enhancements:
2223

lib/rspec/core/configuration.rb

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ def initialize
441441
@mock_framework = nil
442442
@files_or_directories_to_run = []
443443
@loaded_spec_files = Set.new
444-
@color = false
445444
@color_mode = :automatic
446445
@pattern = '**{,/*/**}/*_spec.rb'
447446
@exclude_pattern = ''
@@ -803,20 +802,6 @@ def full_backtrace=(true_or_false)
803802
@backtrace_formatter.full_backtrace = true_or_false
804803
end
805804

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-
820805
# The mode for determining whether to display output in color. One of:
821806
#
822807
# - :automatic - the output will be in color if the output is a TTY (the
@@ -839,20 +824,13 @@ def color_enabled?(output=output_stream)
839824
when :on then true
840825
when :off then false
841826
else # automatic
842-
output_to_tty?(output) || (color && tty?)
827+
output_to_tty?(output) || tty?
843828
end
844829
end
845830

846831
# Set the color mode.
847832
attr_writer :color_mode
848833

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-
856834
# @private
857835
def libs=(libs)
858836
libs.map do |lib|

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

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def handle_current_dir_change
7676

7777
# runtime options
7878
c.raise_errors_for_deprecations!
79-
c.color = true
8079
c.include CommonHelpers
8180

8281
c.expect_with :rspec do |expectations|

spec/support/aruba_support.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ module ArubaLoader
3535
attr_reader :last_cmd_stdout, :last_cmd_stderr, :last_cmd_exit_status
3636

3737
def run_command(cmd)
38-
RSpec.configuration.color = true
39-
4038
temp_stdout = StringIO.new
4139
temp_stderr = StringIO.new
4240

@@ -51,7 +49,6 @@ def run_command(cmd)
5149
end
5250
ensure
5351
RSpec.reset
54-
RSpec.configuration.color = true
5552

5653
# Ensure it gets cached with a proper value -- if we leave it set to nil,
5754
# and the next spec operates in a different dir, it could get set to an

0 commit comments

Comments
 (0)