From 6cb04f85ed9709123fdc4075da2a2bea10f07a4f Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 2 May 2024 09:56:39 +1200 Subject: [PATCH] More WIP. --- lib/console.rb | 4 ++++ lib/console/split.rb | 10 --------- lib/console/terminal.rb | 2 +- test/console/output.rb | 2 +- test/console/terminal/formatter/failure.rb | 23 +++++++++++++++++++++ test/console/terminal/formatter/progress.rb | 21 +++++++++++++++++++ 6 files changed, 50 insertions(+), 12 deletions(-) delete mode 100644 lib/console/split.rb create mode 100644 test/console/terminal/formatter/failure.rb create mode 100644 test/console/terminal/formatter/progress.rb diff --git a/lib/console.rb b/lib/console.rb index 35825a8..da3fc4c 100644 --- a/lib/console.rb +++ b/lib/console.rb @@ -42,5 +42,9 @@ def fatal(...) def failure(...) Logger.instance.failure(...) end + + def call(...) + Logger.instance.call(...) + end end end diff --git a/lib/console/split.rb b/lib/console/split.rb deleted file mode 100644 index 61e5224..0000000 --- a/lib/console/split.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2019-2022, by Samuel Williams. - -require_relative 'output/split' - -module Console - Split = Output::Split -end diff --git a/lib/console/terminal.rb b/lib/console/terminal.rb index 8c41fc8..f86515d 100644 --- a/lib/console/terminal.rb +++ b/lib/console/terminal.rb @@ -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) diff --git a/test/console/output.rb b/test/console/output.rb index 9d3efb9..356a97a 100644 --- a/test/console/output.rb +++ b/test/console/output.rb @@ -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 diff --git a/test/console/terminal/formatter/failure.rb b/test/console/terminal/formatter/failure.rb new file mode 100644 index 0000000..d69448f --- /dev/null +++ b/test/console/terminal/formatter/failure.rb @@ -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 \ No newline at end of file diff --git a/test/console/terminal/formatter/progress.rb b/test/console/terminal/formatter/progress.rb new file mode 100644 index 0000000..43b3b97 --- /dev/null +++ b/test/console/terminal/formatter/progress.rb @@ -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 \ No newline at end of file