|
48 | 48 | ]) |
49 | 49 | end |
50 | 50 |
|
51 | | - it "runs command successfully with logging without uuid set globally" do |
52 | | - output = StringIO.new |
53 | | - command = TTY::Command.new(output: output, uuid: false) |
| 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 | + "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 | + ]) |
| 70 | + end |
54 | 71 |
|
55 | | - command.run(:echo, "hello") |
56 | | - output.rewind |
| 72 | + it "runs command successfully with logging without uuid set locally" do |
| 73 | + output = StringIO.new |
| 74 | + command = TTY::Command.new(output: output) |
57 | 75 |
|
58 | | - lines = output.readlines |
59 | | - lines.last.gsub!(/\d+\.\d+/, "x") |
60 | | - expect(lines).to eq([ |
61 | | - "Running \e[33;1mecho hello\e[0m\n", |
62 | | - "\thello\n", |
63 | | - "Finished in x seconds with exit status 0 (\e[32;1msuccessful\e[0m)\n" |
64 | | - ]) |
| 76 | + command.run(:echo, "hello", uuid: false) |
| 77 | + output.rewind |
| 78 | + |
| 79 | + lines = output.readlines |
| 80 | + 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 | + ]) |
| 86 | + end |
65 | 87 | end |
66 | 88 |
|
67 | | - it "runs command successfully with logging without uuid set locally" do |
68 | | - output = StringIO.new |
69 | | - command = TTY::Command.new(output: output) |
| 89 | + context "with tag option" do |
| 90 | + it "prints the tag set globally" do |
| 91 | + output = StringIO.new |
| 92 | + tag = "task" |
| 93 | + command = TTY::Command.new(output: output, tag: tag) |
| 94 | + |
| 95 | + command.run(:echo, "hello") |
| 96 | + |
| 97 | + output.rewind |
| 98 | + lines = output.readlines |
| 99 | + 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 | + ]) |
| 106 | + end |
70 | 107 |
|
71 | | - command.run(:echo, "hello", uuid: false) |
72 | | - output.rewind |
| 108 | + it "prints the tag set locally" do |
| 109 | + output = StringIO.new |
| 110 | + tag = "task" |
| 111 | + command = TTY::Command.new(output: output) |
| 112 | + |
| 113 | + command.run(:echo, "hello", tag: tag) |
| 114 | + |
| 115 | + output.rewind |
| 116 | + lines = output.readlines |
| 117 | + 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 | + ]) |
| 124 | + end |
73 | 125 |
|
74 | | - lines = output.readlines |
75 | | - lines.last.gsub!(/\d+\.\d+/, "x") |
76 | | - expect(lines).to eq([ |
77 | | - "Running \e[33;1mecho hello\e[0m\n", |
78 | | - "\thello\n", |
79 | | - "Finished in x seconds with exit status 0 (\e[32;1msuccessful\e[0m)\n" |
80 | | - ]) |
| 126 | + it "prints the tag even if uuid is set to false" do |
| 127 | + output = StringIO.new |
| 128 | + tag = "task" |
| 129 | + command = TTY::Command.new(output: output, tag: tag, uuid: false) |
| 130 | + |
| 131 | + command.run(:echo, "hello") |
| 132 | + |
| 133 | + output.rewind |
| 134 | + lines = output.readlines |
| 135 | + 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 | + ]) |
| 142 | + end |
81 | 143 | end |
82 | 144 |
|
83 | 145 | it "runs command and fails with logging" do |
|
0 commit comments