|
62 | 62 |
|
63 | 63 | lines = output.readlines |
64 | 64 | lines.last.gsub!(/\d+\.\d+/, "x") |
65 | | - expect(lines).to eq([ |
66 | | - "Running \e[33;1mecho hello\e[0m\n", |
67 | | - "\thello\n", |
68 | | - "Finished in x seconds with exit status 0 (\e[32;1msuccessful\e[0m)\n" |
69 | | - ]) |
| 65 | + expect(lines).to eq( |
| 66 | + generic_colored_log_lines(prefix: nil) |
| 67 | + ) |
70 | 68 | end |
71 | 69 |
|
72 | 70 | it "runs command successfully with logging without uuid set locally" do |
|
78 | 76 |
|
79 | 77 | lines = output.readlines |
80 | 78 | lines.last.gsub!(/\d+\.\d+/, "x") |
81 | | - expect(lines).to eq([ |
82 | | - "Running \e[33;1mecho hello\e[0m\n", |
83 | | - "\thello\n", |
84 | | - "Finished in x seconds with exit status 0 (\e[32;1msuccessful\e[0m)\n" |
85 | | - ]) |
| 79 | + expect(lines).to eq( |
| 80 | + generic_colored_log_lines(prefix: nil) |
| 81 | + ) |
86 | 82 | end |
87 | 83 | end |
88 | 84 |
|
|
97 | 93 | output.rewind |
98 | 94 | lines = output.readlines |
99 | 95 | lines.last.gsub!(/\d+\.\d+/, "x") |
100 | | - expect(lines).to eq([ |
101 | | - "[\e[32m#{tag}\e[0m] Running \e[33;1mecho hello\e[0m\n", |
102 | | - "[\e[32m#{tag}\e[0m] \thello\n", |
103 | | - "[\e[32m#{tag}\e[0m] Finished in x seconds with exit status 0 " \ |
104 | | - "(\e[32;1msuccessful\e[0m)\n" |
105 | | - ]) |
| 96 | + expect(lines).to eq( |
| 97 | + generic_colored_log_lines(prefix: tag) |
| 98 | + ) |
106 | 99 | end |
107 | 100 |
|
108 | 101 | it "prints the tag set locally" do |
|
115 | 108 | output.rewind |
116 | 109 | lines = output.readlines |
117 | 110 | lines.last.gsub!(/\d+\.\d+/, "x") |
118 | | - expect(lines).to eq([ |
119 | | - "[\e[32m#{tag}\e[0m] Running \e[33;1mecho hello\e[0m\n", |
120 | | - "[\e[32m#{tag}\e[0m] \thello\n", |
121 | | - "[\e[32m#{tag}\e[0m] Finished in x seconds with exit status 0 " \ |
122 | | - "(\e[32;1msuccessful\e[0m)\n" |
123 | | - ]) |
| 111 | + expect(lines).to eq( |
| 112 | + generic_colored_log_lines(prefix: tag) |
| 113 | + ) |
124 | 114 | end |
125 | 115 |
|
126 | 116 | it "prints the tag even if uuid is set to false" do |
|
133 | 123 | output.rewind |
134 | 124 | lines = output.readlines |
135 | 125 | lines.last.gsub!(/\d+\.\d+/, "x") |
136 | | - expect(lines).to eq([ |
137 | | - "[\e[32m#{tag}\e[0m] Running \e[33;1mecho hello\e[0m\n", |
138 | | - "[\e[32m#{tag}\e[0m] \thello\n", |
139 | | - "[\e[32m#{tag}\e[0m] Finished in x seconds with exit status 0 " \ |
140 | | - "(\e[32;1msuccessful\e[0m)\n" |
141 | | - ]) |
| 126 | + expect(lines).to eq( |
| 127 | + generic_colored_log_lines(prefix: tag) |
| 128 | + ) |
142 | 129 | end |
143 | 130 | end |
144 | 131 |
|
|
246 | 233 | lines = output.readlines |
247 | 234 | expect(lines[0]).to include("Running \e[33;1mecho hello\e[0m\n") |
248 | 235 | end |
| 236 | + |
| 237 | + # Generates the expected log lines in colored mode, with/without `[prefix]` |
| 238 | + def generic_colored_log_lines(prefix: nil) |
| 239 | + if prefix |
| 240 | + [ |
| 241 | + "[\e[32m#{prefix}\e[0m] Running \e[33;1mecho hello\e[0m\n", |
| 242 | + "[\e[32m#{prefix}\e[0m] \thello\n", |
| 243 | + "[\e[32m#{prefix}\e[0m] Finished in x seconds with exit status 0 " \ |
| 244 | + "(\e[32;1msuccessful\e[0m)\n" |
| 245 | + ] |
| 246 | + else |
| 247 | + [ |
| 248 | + "Running \e[33;1mecho hello\e[0m\n", |
| 249 | + "\thello\n", |
| 250 | + "Finished in x seconds with exit status 0 (\e[32;1msuccessful\e[0m)\n" |
| 251 | + ] |
| 252 | + end |
| 253 | + end |
249 | 254 | end |
0 commit comments