@@ -1265,11 +1265,20 @@ def metadata_hash(*args)
1265
1265
1266
1266
end
1267
1267
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 }
1273
1282
1274
1283
context "with output.tty?" do
1275
1284
it "sets color_enabled?" do
@@ -1288,10 +1297,8 @@ def metadata_hash(*args)
1288
1297
end
1289
1298
end
1290
1299
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 }
1295
1302
1296
1303
context "with output.tty?" do
1297
1304
it "sets color_enabled?" do
@@ -1310,10 +1317,8 @@ def metadata_hash(*args)
1310
1317
end
1311
1318
end
1312
1319
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 }
1317
1322
1318
1323
context "with output.tty?" do
1319
1324
it "sets !color_enabled?" do
@@ -1330,151 +1335,15 @@ def metadata_hash(*args)
1330
1335
expect ( config . color_enabled? ) . to be false
1331
1336
end
1332
1337
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
1354
1338
end
1355
1339
end
1356
1340
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
1472
1342
it "prefers incoming cli_args" do
1473
1343
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
1478
1347
end
1479
1348
end
1480
1349
0 commit comments