@@ -7,6 +7,8 @@ def shell
7
7
8
8
before do
9
9
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" )
10
12
allow_any_instance_of ( StringIO ) . to receive ( :tty? ) . and_return ( true )
11
13
end
12
14
@@ -131,13 +133,25 @@ def shell
131
133
expect ( colorless ) . to eq ( "hi!" )
132
134
end
133
135
134
- it "does nothing when the terminal does not support color " do
136
+ it "does nothing when stdout is not a tty " do
135
137
allow ( $stdout) . to receive ( :tty? ) . and_return ( false )
136
138
colorless = shell . set_color "hi!" , :white
137
139
expect ( colorless ) . to eq ( "hi!" )
138
140
end
139
141
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
141
155
allow ( ENV ) . to receive ( :[] ) . with ( "NO_COLOR" ) . and_return ( "" )
142
156
allow ( $stdout) . to receive ( :tty? ) . and_return ( true )
143
157
colorless = shell . set_color "hi!" , :white
0 commit comments