@@ -19,6 +19,15 @@ def shell
1919 shell . ask "Is this green?" , :green , :limited_to => %w( Yes No Maybe )
2020 end
2121
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+
2231 it "handles an Array of colors" do
2332 expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( "\e [32m\e [47m\e [1mIs this green on white? \e [0m" , anything ) . and_return ( "yes" )
2433 shell . ask "Is this green on white?" , [ :green , :on_white , :bold ]
@@ -48,6 +57,15 @@ def shell
4857 expect ( out . chomp ) . to eq ( "Wow! Now we have colors!" )
4958 end
5059
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+
5169 it "does not use a new line even with colors" do
5270 out = capture ( :stdout ) do
5371 shell . say "Wow! Now we have colors! " , :green
@@ -118,6 +136,13 @@ def shell
118136 colorless = shell . set_color "hi!" , :white
119137 expect ( colorless ) . to eq ( "hi!" )
120138 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
121146 end
122147
123148 describe "#file_collision" do
0 commit comments