Skip to content

Commit

Permalink
More WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 1, 2024
1 parent ee4a0f5 commit 6cb04f8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
4 changes: 4 additions & 0 deletions lib/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ def fatal(...)
def failure(...)
Logger.instance.failure(...)
end

def call(...)
Logger.instance.call(...)
end
end
end
10 changes: 0 additions & 10 deletions lib/console/split.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/console/terminal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
module Console
module Terminal
def self.for(io)
if io.isatty
if io.tty?
XTerm.new(io)
else
Text.new(io)
Expand Down
2 changes: 1 addition & 1 deletion test/console/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
let(:capture) {$stderr}

it 'should use a terminal format' do
expect($stderr).to receive(:tty?).and_return(true)
expect($stderr).to receive(:tty?).twice.and_return(true)

expect(output).to be_a Console::Output::Terminal
end
Expand Down
23 changes: 23 additions & 0 deletions test/console/terminal/formatter/failure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'console/terminal/formatter/failure'
require 'console/event/failure'
require 'console/terminal'

describe Console::Terminal::Formatter::Failure do
let(:buffer) {StringIO.new}
let(:terminal) {Console::Terminal.for(buffer)}
let(:formatter) {subject.new(terminal)}

let(:event) do
begin
raise StandardError, "It failed!"
rescue => error
Console::Event::Failure.for(error)
end
end

it "can format failure events" do
formatter.format(event.to_hash, buffer)

expect(buffer.string).to be =~ /StandardError: It failed!/
end
end
21 changes: 21 additions & 0 deletions test/console/terminal/formatter/progress.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'console/terminal/formatter/progress'
require 'console/event/progress'
require 'console/output/null'
require 'console/terminal'

describe Console::Terminal::Formatter::Progress do
let(:buffer) {StringIO.new}
let(:terminal) {Console::Terminal.for(buffer)}
let(:formatter) {subject.new(terminal)}
let(:output) {Console::Output::Null.new}

let(:event) do
Console::Event::Progress.new(output, self, 10)
end

it "can format failure events" do
formatter.format(event.to_hash, buffer)

expect(buffer.string).to be =~ /0.00%/
end
end

0 comments on commit 6cb04f8

Please sign in to comment.