@@ -19,6 +19,15 @@ def shell
19
19
shell . ask "Is this green?" , :green , :limited_to => %w( Yes No Maybe )
20
20
end
21
21
22
+ it "does not set the color if specified and NO_COLOR is set" do
23
+ allow ( ENV ) . to receive ( :[] ) . with ( "NO_COLOR" ) . and_return ( "" )
24
+ expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( "Is this green? " , anything ) . and_return ( "yes" )
25
+ shell . ask "Is this green?" , :green
26
+
27
+ expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( "Is this green? [Yes, No, Maybe] " , anything ) . and_return ( "Yes" )
28
+ shell . ask "Is this green?" , :green , :limited_to => %w( Yes No Maybe )
29
+ end
30
+
22
31
it "handles an Array of colors" do
23
32
expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( "\e [32m\e [47m\e [1mIs this green on white? \e [0m" , anything ) . and_return ( "yes" )
24
33
shell . ask "Is this green on white?" , [ :green , :on_white , :bold ]
@@ -48,6 +57,15 @@ def shell
48
57
expect ( out . chomp ) . to eq ( "Wow! Now we have colors!" )
49
58
end
50
59
60
+ it "does not set the color if NO_COLOR is set" do
61
+ allow ( ENV ) . to receive ( :[] ) . with ( "NO_COLOR" ) . and_return ( "" )
62
+ out = capture ( :stdout ) do
63
+ shell . say "Wow! Now we have colors!" , :green
64
+ end
65
+
66
+ expect ( out . chomp ) . to eq ( "Wow! Now we have colors!" )
67
+ end
68
+
51
69
it "does not use a new line even with colors" do
52
70
out = capture ( :stdout ) do
53
71
shell . say "Wow! Now we have colors! " , :green
@@ -118,6 +136,13 @@ def shell
118
136
colorless = shell . set_color "hi!" , :white
119
137
expect ( colorless ) . to eq ( "hi!" )
120
138
end
139
+
140
+ it "does nothing when the terminal has the NO_COLOR environment variable set" do
141
+ allow ( ENV ) . to receive ( :[] ) . with ( "NO_COLOR" ) . and_return ( "" )
142
+ allow ( $stdout) . to receive ( :tty? ) . and_return ( true )
143
+ colorless = shell . set_color "hi!" , :white
144
+ expect ( colorless ) . to eq ( "hi!" )
145
+ end
121
146
end
122
147
123
148
describe "#file_collision" do
0 commit comments