@@ -7,6 +7,8 @@ def shell
77
88 before do
99 allow ( $stdout) . to receive ( :tty? ) . and_return ( true )
10+ allow ( ENV ) . to receive ( :[] ) . and_return ( nil )
11+ allow ( ENV ) . to receive ( :[] ) . with ( "TERM" ) . and_return ( "ansi" )
1012 allow_any_instance_of ( StringIO ) . to receive ( :tty? ) . and_return ( true )
1113 end
1214
@@ -131,13 +133,25 @@ def shell
131133 expect ( colorless ) . to eq ( "hi!" )
132134 end
133135
134- it "does nothing when the terminal does not support color " do
136+ it "does nothing when stdout is not a tty " do
135137 allow ( $stdout) . to receive ( :tty? ) . and_return ( false )
136138 colorless = shell . set_color "hi!" , :white
137139 expect ( colorless ) . to eq ( "hi!" )
138140 end
139141
140- it "does nothing when the terminal has the NO_COLOR environment variable set" do
142+ it "does nothing when the TERM environment variable is set to 'dumb'" do
143+ allow ( ENV ) . to receive ( :[] ) . with ( "TERM" ) . and_return ( "dumb" )
144+ colorless = shell . set_color "hi!" , :white
145+ expect ( colorless ) . to eq ( "hi!" )
146+ end
147+
148+ it "does nothing when the TERM environment variable is not set" do
149+ allow ( ENV ) . to receive ( :[] ) . with ( "TERM" ) . and_return ( nil )
150+ colorless = shell . set_color "hi!" , :white
151+ expect ( colorless ) . to eq ( "hi!" )
152+ end
153+
154+ it "does nothing when the NO_COLOR environment variable is set" do
141155 allow ( ENV ) . to receive ( :[] ) . with ( "NO_COLOR" ) . and_return ( "" )
142156 allow ( $stdout) . to receive ( :tty? ) . and_return ( true )
143157 colorless = shell . set_color "hi!" , :white
0 commit comments