|
26 | 26 | "[\e[32m#{uuid}\e[0m] Running \e[33;1mecho hello\e[0m\n", |
27 | 27 | "[\e[32m#{uuid}\e[0m] \thello\n", |
28 | 28 | "[\e[32m#{uuid}\e[0m] Finished in x seconds with exit status 0 " \ |
29 | | - "(\e[32;1msuccessful\e[0m)\n" |
| 29 | + "(\e[32;1msuccessful\e[0m)\n" |
30 | 30 | ]) |
31 | 31 | end |
32 | 32 |
|
|
48 | 48 | ]) |
49 | 49 | end |
50 | 50 |
|
51 | | - # TODO: |
52 | | - # Move "with xxx option" context to the end of |
53 | | - # the describe block to follow RSpec style guide. |
54 | | - |
55 | | - context "with uuid option" do |
56 | | - it "runs command successfully with logging without uuid set globally" do |
57 | | - output = StringIO.new |
58 | | - command = TTY::Command.new(output: output, uuid: false) |
59 | | - |
60 | | - command.run(:echo, "hello") |
61 | | - output.rewind |
62 | | - |
63 | | - lines = output.readlines |
64 | | - lines.last.gsub!(/\d+\.\d+/, "x") |
65 | | - expect(lines).to eq( |
66 | | - generic_colored_log_lines(prefix: nil) |
67 | | - ) |
68 | | - end |
69 | | - |
70 | | - it "runs command successfully with logging without uuid set locally" do |
71 | | - output = StringIO.new |
72 | | - command = TTY::Command.new(output: output) |
73 | | - |
74 | | - command.run(:echo, "hello", uuid: false) |
75 | | - output.rewind |
76 | | - |
77 | | - lines = output.readlines |
78 | | - lines.last.gsub!(/\d+\.\d+/, "x") |
79 | | - expect(lines).to eq( |
80 | | - generic_colored_log_lines(prefix: nil) |
81 | | - ) |
82 | | - end |
83 | | - end |
84 | | - |
85 | | - context "with tag option" do |
86 | | - it "prints the tag set globally" do |
87 | | - output = StringIO.new |
88 | | - tag = "task" |
89 | | - command = TTY::Command.new(output: output, tag: tag) |
90 | | - |
91 | | - command.run(:echo, "hello") |
92 | | - |
93 | | - output.rewind |
94 | | - lines = output.readlines |
95 | | - lines.last.gsub!(/\d+\.\d+/, "x") |
96 | | - expect(lines).to eq( |
97 | | - generic_colored_log_lines(prefix: tag) |
98 | | - ) |
99 | | - end |
100 | | - |
101 | | - it "prints the tag set locally" do |
102 | | - output = StringIO.new |
103 | | - tag = "task" |
104 | | - command = TTY::Command.new(output: output) |
105 | | - |
106 | | - command.run(:echo, "hello", tag: tag) |
107 | | - |
108 | | - output.rewind |
109 | | - lines = output.readlines |
110 | | - lines.last.gsub!(/\d+\.\d+/, "x") |
111 | | - expect(lines).to eq( |
112 | | - generic_colored_log_lines(prefix: tag) |
113 | | - ) |
114 | | - end |
115 | | - |
116 | | - it "prints the tag even if uuid is set to false" do |
117 | | - output = StringIO.new |
118 | | - tag = "task" |
119 | | - command = TTY::Command.new(output: output, tag: tag, uuid: false) |
120 | | - |
121 | | - command.run(:echo, "hello") |
122 | | - |
123 | | - output.rewind |
124 | | - lines = output.readlines |
125 | | - lines.last.gsub!(/\d+\.\d+/, "x") |
126 | | - expect(lines).to eq( |
127 | | - generic_colored_log_lines(prefix: tag) |
128 | | - ) |
129 | | - end |
130 | | - end |
131 | | - |
132 | 51 | it "runs command and fails with logging" do |
133 | 52 | non_zero_exit = fixtures_path("non_zero_exit") |
134 | 53 | output = StringIO.new |
|
145 | 64 | "[\e[32m#{uuid}\e[0m] Running \e[33;1mruby #{non_zero_exit}\e[0m\n", |
146 | 65 | "[\e[32m#{uuid}\e[0m] \tnooo\n", |
147 | 66 | "[\e[32m#{uuid}\e[0m] Finished in x seconds with exit status 1 " \ |
148 | | - "(\e[31;1mfailed\e[0m)\n" |
| 67 | + "(\e[31;1mfailed\e[0m)\n" |
149 | 68 | ]) |
150 | 69 | end |
151 | 70 |
|
|
209 | 128 | "[\e[32m#{uuid}\e[0m] Running \e[33;1mruby #{phased_output}\e[0m\n", |
210 | 129 | "[\e[32m#{uuid}\e[0m] \t..........\n", |
211 | 130 | "[\e[32m#{uuid}\e[0m] Finished in x seconds with exit status 0 " \ |
212 | | - "(\e[32;1msuccessful\e[0m)\n" |
| 131 | + "(\e[32;1msuccessful\e[0m)\n" |
213 | 132 | ]) |
214 | 133 | end |
215 | 134 |
|
216 | 135 | it "does not persist environment variables", |
217 | | - unless: RSpec::Support::OS.windows? do |
| 136 | + unless: RSpec::Support::OS.windows? do |
218 | 137 | output = StringIO.new |
219 | 138 | command = TTY::Command.new(output: output) |
220 | 139 |
|
|
234 | 153 | expect(lines[0]).to include("Running \e[33;1mecho hello\e[0m\n") |
235 | 154 | end |
236 | 155 |
|
| 156 | + context "with uuid option" do |
| 157 | + it "runs command successfully with logging without uuid set globally" do |
| 158 | + output = StringIO.new |
| 159 | + command = TTY::Command.new(output: output, uuid: false) |
| 160 | + |
| 161 | + command.run(:echo, "hello") |
| 162 | + output.rewind |
| 163 | + |
| 164 | + lines = output.readlines |
| 165 | + lines.last.gsub!(/\d+\.\d+/, "x") |
| 166 | + expect(lines).to eq( |
| 167 | + generic_colored_log_lines(prefix: nil) |
| 168 | + ) |
| 169 | + end |
| 170 | + |
| 171 | + it "runs command successfully with logging without uuid set locally" do |
| 172 | + output = StringIO.new |
| 173 | + command = TTY::Command.new(output: output) |
| 174 | + |
| 175 | + command.run(:echo, "hello", uuid: false) |
| 176 | + output.rewind |
| 177 | + |
| 178 | + lines = output.readlines |
| 179 | + lines.last.gsub!(/\d+\.\d+/, "x") |
| 180 | + expect(lines).to eq( |
| 181 | + generic_colored_log_lines(prefix: nil) |
| 182 | + ) |
| 183 | + end |
| 184 | + end |
| 185 | + |
| 186 | + context "with tag option" do |
| 187 | + it "prints the tag set globally" do |
| 188 | + output = StringIO.new |
| 189 | + tag = "task" |
| 190 | + command = TTY::Command.new(output: output, tag: tag) |
| 191 | + |
| 192 | + command.run(:echo, "hello") |
| 193 | + |
| 194 | + output.rewind |
| 195 | + lines = output.readlines |
| 196 | + lines.last.gsub!(/\d+\.\d+/, "x") |
| 197 | + expect(lines).to eq( |
| 198 | + generic_colored_log_lines(prefix: tag) |
| 199 | + ) |
| 200 | + end |
| 201 | + |
| 202 | + it "prints the tag set locally" do |
| 203 | + output = StringIO.new |
| 204 | + tag = "task" |
| 205 | + command = TTY::Command.new(output: output) |
| 206 | + |
| 207 | + command.run(:echo, "hello", tag: tag) |
| 208 | + |
| 209 | + output.rewind |
| 210 | + lines = output.readlines |
| 211 | + lines.last.gsub!(/\d+\.\d+/, "x") |
| 212 | + expect(lines).to eq( |
| 213 | + generic_colored_log_lines(prefix: tag) |
| 214 | + ) |
| 215 | + end |
| 216 | + |
| 217 | + it "prints the tag even if uuid is set to false" do |
| 218 | + output = StringIO.new |
| 219 | + tag = "task" |
| 220 | + command = TTY::Command.new(output: output, tag: tag, uuid: false) |
| 221 | + |
| 222 | + command.run(:echo, "hello") |
| 223 | + |
| 224 | + output.rewind |
| 225 | + lines = output.readlines |
| 226 | + lines.last.gsub!(/\d+\.\d+/, "x") |
| 227 | + expect(lines).to eq( |
| 228 | + generic_colored_log_lines(prefix: tag) |
| 229 | + ) |
| 230 | + end |
| 231 | + end |
| 232 | + |
237 | 233 | # Generates the expected log lines in colored mode, with/without `[prefix]` |
238 | 234 | def generic_colored_log_lines(prefix: nil) |
239 | 235 | if prefix |
240 | 236 | [ |
241 | 237 | "[\e[32m#{prefix}\e[0m] Running \e[33;1mecho hello\e[0m\n", |
242 | 238 | "[\e[32m#{prefix}\e[0m] \thello\n", |
243 | 239 | "[\e[32m#{prefix}\e[0m] Finished in x seconds with exit status 0 " \ |
244 | | - "(\e[32;1msuccessful\e[0m)\n" |
| 240 | + "(\e[32;1msuccessful\e[0m)\n" |
245 | 241 | ] |
246 | 242 | else |
247 | 243 | [ |
|
0 commit comments