Skip to content

Commit

Permalink
Refactor Runner#run_all_tests to raise unless for TestRunner (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexB52 authored Oct 20, 2024
1 parent d36c18c commit 9b86f2b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lib/retest/runners.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

module Retest
module Runners
class NotSupportedError < StandardError; end

module_function

def runner_for(command)
Expand Down
3 changes: 1 addition & 2 deletions lib/retest/runners/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def run(changed_file = nil, repository: nil)
end

def run_all_tests(tests_string)
log("Test File Selected: #{tests_string}")
system_run command.gsub('<test>', tests_string)
raise NotSupportedError, 'cannot run multiple test files against this command'
end

def sync(added:, removed:)
Expand Down
5 changes: 5 additions & 0 deletions lib/retest/runners/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def run(changed_file, repository:)
system_run command.gsub('<test>', cached_test_file)
end

def run_all_tests(tests_string)
log("Test File Selected: #{tests_string}")
system_run command.gsub('<test>', tests_string)
end

def sync(added:, removed:)
purge_test_file(removed)
end
Expand Down
4 changes: 4 additions & 0 deletions test/retest/runners/change_runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def test_run_with_a_file_found

assert_match "touch file_path.rb", out
end

def test_run_all_tests
assert_raises(NotSupportedError) { @subject.run_all_tests('file_path.rb file_path_two.rb') }
end
end
end
end
12 changes: 1 addition & 11 deletions test/retest/runners/runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,7 @@ def test_run
end

def test_run_all_tests
runner = Runner.new("echo '<test>'", stdout: StringIO.new)

out, _ = capture_subprocess_io { runner.run_all_tests('file_path.rb file_path_two.rb') }

assert_equal(<<~EXPECATIONS, runner.stdout.string)
Test File Selected: file_path.rb file_path_two.rb
EXPECATIONS

assert_equal(<<~EXPECATIONS, out)
file_path.rb file_path_two.rb
EXPECATIONS
assert_raises(NotSupportedError) { @subject.run_all_tests('file_path.rb file_path_two.rb') }
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/retest/runners/test_runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ def test_sync_files
@subject.sync(added: 'a.rb', removed:'file_path_test.rb')
assert_nil @subject.cached_test_file
end

def test_run_all_tests
out, _ = capture_subprocess_io { @subject.run_all_tests('file_path.rb file_path_two.rb') }

assert_equal(<<~EXPECATIONS, @subject.stdout.string)
Test File Selected: file_path.rb file_path_two.rb
EXPECATIONS

assert_equal(<<~EXPECATIONS, out)
touch file_path.rb file_path_two.rb
EXPECATIONS
end
end
end
end
4 changes: 4 additions & 0 deletions test/retest/runners/variable_runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def test_sync_files
@subject.sync(added: 'a.rb', removed:'file_path_test.rb')
assert_nil @subject.cached_test_file
end

def test_run_all_tests
assert_raises(NotSupportedError) { @subject.run_all_tests('file_path.rb file_path_two.rb') }
end
end
end
end

0 comments on commit 9b86f2b

Please sign in to comment.