From 13c20f80fad4a6920451d82b6de56c1a7151013b Mon Sep 17 00:00:00 2001 From: Alexandre Barret Date: Mon, 25 Nov 2024 09:33:09 +1300 Subject: [PATCH] Create Commnad::MultipleTestsNotSupported error --- lib/retest/command/base.rb | 6 ++++-- lib/retest/command/hardcoded.rb | 10 +--------- test/retest/command/hardcoded_test.rb | 4 ++-- test/retest/runner_test.rb | 2 +- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/retest/command/base.rb b/lib/retest/command/base.rb index 2b08092..e82295b 100644 --- a/lib/retest/command/base.rb +++ b/lib/retest/command/base.rb @@ -1,5 +1,7 @@ module Retest class Command + class MultipleTestsNotSupported < StandardError; end + class Base def initialize(all: false, file_system: FileSystem, command: nil) @file_system = file_system @@ -36,11 +38,11 @@ def hardcoded_type? end def to_s - raise NotImplementedError + @command end def format_batch(*files) - raise NotImplementedError + raise MultipleTestsNotSupported, "Multiple test files run not supported for '#{to_s}'" end private diff --git a/lib/retest/command/hardcoded.rb b/lib/retest/command/hardcoded.rb index 76e68d7..f4a44df 100644 --- a/lib/retest/command/hardcoded.rb +++ b/lib/retest/command/hardcoded.rb @@ -1,13 +1,5 @@ module Retest class Command - class Hardcoded < Base - def to_s - @command - end - - def format_batch(*files) - raise ArgumentError, "Multiple test files run not supported for '#{to_s}'" - end - end + class Hardcoded < Base; end end end diff --git a/test/retest/command/hardcoded_test.rb b/test/retest/command/hardcoded_test.rb index 7ee6edc..ccd69e6 100644 --- a/test/retest/command/hardcoded_test.rb +++ b/test/retest/command/hardcoded_test.rb @@ -55,13 +55,13 @@ def test_to_s end def test_format_with_one_file - assert_raises(ArgumentError) do + assert_raises(Command::MultipleTestsNotSupported) do @subject.format_batch('a/file/path.rb') end end def test_format_with_multiple_files - assert_raises(ArgumentError) do + assert_raises(Command::MultipleTestsNotSupported) do @subject.format_batch('a/file/path.rb', 'another/file/path.rb') end end diff --git a/test/retest/runner_test.rb b/test/retest/runner_test.rb index 7af1ecc..e67757c 100644 --- a/test/retest/runner_test.rb +++ b/test/retest/runner_test.rb @@ -160,7 +160,7 @@ def test_returns_last_command end def test_run_multiple_tests - assert_raises(ArgumentError) do + assert_raises(Command::MultipleTestsNotSupported) do @subject.command = @command @subject.format_instruction(test_files: ['file_path.rb', 'file_path_two.rb']) end