From 22258f0967ea5e8d3b756d347d0e511671c20a62 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sun, 28 Dec 2025 12:53:01 +0100 Subject: [PATCH 1/7] Basic test suite --- Gemfile.lock | 6 ++- bin/test | 15 ++++++ test/custom_on_change.rb | 11 +++-- test/test_helper.rb | 8 +++ test/testerobly_test.rb | 104 ++++++++++++++++++++++++++++++++++++++- testerobly.gemspec | 3 ++ 6 files changed, 141 insertions(+), 6 deletions(-) create mode 100755 bin/test create mode 100644 test/test_helper.rb diff --git a/Gemfile.lock b/Gemfile.lock index ca8b440..8699c80 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,24 +3,26 @@ PATH specs: testerobly (1.1.1) listen (~> 3.9.0) + logger GEM remote: https://rubygems.org/ specs: ffi (1.17.2) - ffi (1.17.2-arm64-darwin) listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) + logger (1.7.0) + minitest (5.27.0) rb-fsevent (0.11.2) rb-inotify (0.11.1) ffi (~> 1.0) PLATFORMS - arm64-darwin-24 ruby DEPENDENCIES + minitest (~> 5.0) testerobly! BUNDLED WITH diff --git a/bin/test b/bin/test new file mode 100755 index 0000000..5496809 --- /dev/null +++ b/bin/test @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +test_files = if ARGV.empty? + Dir["test/**/*_test.rb"] +else + ARGV +end + +if test_files.empty? + warn "No test files found." + exit 1 +end + +exec "ruby", "-Itest", *test_files diff --git a/test/custom_on_change.rb b/test/custom_on_change.rb index 8274e43..65a0ebf 100644 --- a/test/custom_on_change.rb +++ b/test/custom_on_change.rb @@ -1,4 +1,9 @@ -puts "custom_on_change.rb here" -# require "debug" -# debugger +# frozen_string_literal: true +require_relative "test_helper" + +class CustomOnChangeTest < Minitest::Test + def test_custom_on_change_is_runnable + assert_equal 2, 1 + 1 + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..8861356 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require "bundler/setup" +require "minitest/autorun" +require "fileutils" +require "tmpdir" + +require "testerobly" diff --git a/test/testerobly_test.rb b/test/testerobly_test.rb index 095809b..df78b2c 100644 --- a/test/testerobly_test.rb +++ b/test/testerobly_test.rb @@ -1 +1,103 @@ -puts "testerobly_test.rb here" +# frozen_string_literal: true + +require_relative "test_helper" + +class TesteroblyTest < Minitest::Test + def setup + @original_configuration = Testerobly.configuration + Testerobly.configuration = Testerobly::Configuration.new + end + + def teardown + Testerobly.configuration = @original_configuration + end + + def test_configuration_defaults_and_bind + config = Testerobly.configuration + + assert_equal "bin/test %s", config.test_command + assert_equal({}, config.keys) + assert_nil config.on_change + + config.bind("s", "echo hi") + config.test_all_command = "bin/test" + + assert_equal "echo hi", config.keys["s"] + assert_equal "bin/test", config.keys[""] + end + + def test_configure_yields_configuration + Testerobly.configure do |config| + config.test_command = "ruby %s" + end + + assert_equal "ruby %s", Testerobly.configuration.test_command + end + + def test_process_changes_enqueues_matching_tests + with_tmp_project do |dir| + write_file(dir, "lib/foo.rb", "# frozen_string_literal: true\n") + write_file(dir, "test/foo_test.rb", "# frozen_string_literal: true\n") + + main = build_main + + Dir.chdir(dir) do + main.process_changes(["lib/foo.rb"], []) + end + + queue = main.instance_variable_get(:@queue) + + assert_equal 1, queue.size + item = queue.pop + assert_equal "bin/test test/foo_test.rb", item[:command] + assert_equal "lib/foo.rb => test/foo_test.rb", item[:message] + end + end + + def test_process_changes_applies_on_change_hook + with_tmp_project do |dir| + write_file(dir, "lib/foo.rb", "# frozen_string_literal: true\n") + write_file(dir, "test/foo_test.rb", "# frozen_string_literal: true\n") + write_file(dir, "test/extra_test.rb", "# frozen_string_literal: true\n") + + Testerobly.configuration.on_change = Proc.new do |_path, tests| + tests << "test/extra_test.rb" + end + + main = build_main + + Dir.chdir(dir) do + main.process_changes(["lib/foo.rb"], []) + end + + queue = main.instance_variable_get(:@queue) + + assert_equal 1, queue.size + item = queue.pop + assert_equal "bin/test test/foo_test.rb test/extra_test.rb", item[:command] + end + end + + private + + def build_main + main = Testerobly::Main.allocate + main.instance_variable_set(:@queue, Thread::Queue.new) + main.instance_variable_set(:@pause_until, Time.now - 1) + main + end + + def with_tmp_project + Dir.mktmpdir do |dir| + FileUtils.mkdir_p(File.join(dir, "lib")) + FileUtils.mkdir_p(File.join(dir, "test")) + yield dir + end + end + + def write_file(base, relative_path, contents) + full_path = File.join(base, relative_path) + FileUtils.mkdir_p(File.dirname(full_path)) + File.write(full_path, contents) + end +end diff --git a/testerobly.gemspec b/testerobly.gemspec index 8f96b8b..3801f5a 100644 --- a/testerobly.gemspec +++ b/testerobly.gemspec @@ -14,4 +14,7 @@ Gem::Specification.new do |spec| spec.executables = %w[ testerobly ] spec.add_dependency "listen", "~> 3.9.0" + spec.add_dependency "logger" + + spec.add_development_dependency "minitest", "~> 5.0" end From 55a88e90bc1e86f59ef2c10324a0fc0c42501c03 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sun, 28 Dec 2025 12:54:08 +0100 Subject: [PATCH 2/7] CI --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a182566 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,20 @@ +name: CI + +on: + push: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby: ["3.2", "3.3", "3.4", "4.0"] + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run tests + run: bundle exec bin/test From 187e5e2f623e1894ea2a2cdb07c7dc1917d91713 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sun, 28 Dec 2025 12:56:40 +0100 Subject: [PATCH 3/7] logger moved as dev dep --- Gemfile.lock | 2 +- testerobly.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8699c80..2dc62d0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,7 +3,6 @@ PATH specs: testerobly (1.1.1) listen (~> 3.9.0) - logger GEM remote: https://rubygems.org/ @@ -22,6 +21,7 @@ PLATFORMS ruby DEPENDENCIES + logger (~> 1.7) minitest (~> 5.0) testerobly! diff --git a/testerobly.gemspec b/testerobly.gemspec index 3801f5a..2daf21d 100644 --- a/testerobly.gemspec +++ b/testerobly.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |spec| spec.executables = %w[ testerobly ] spec.add_dependency "listen", "~> 3.9.0" - spec.add_dependency "logger" spec.add_development_dependency "minitest", "~> 5.0" + spec.add_development_dependency "logger", "~> 1.7" end From 3719bf46b12463b90927a0773ca0c8977ff67e8e Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sun, 28 Dec 2025 12:57:35 +0100 Subject: [PATCH 4/7] tweak ci trigger --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a182566..1eef948 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,9 @@ name: CI on: push: + branches: [ "main" ] pull_request: + branches: [ "main" ] jobs: test: From bef01e5717061e80919eebee3c4a85bf33284468 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sun, 28 Dec 2025 12:59:04 +0100 Subject: [PATCH 5/7] logger is a listen dep --- Gemfile.lock | 2 +- testerobly.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2dc62d0..c489aab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ PATH specs: testerobly (1.1.1) listen (~> 3.9.0) + logger (~> 1.7) GEM remote: https://rubygems.org/ @@ -21,7 +22,6 @@ PLATFORMS ruby DEPENDENCIES - logger (~> 1.7) minitest (~> 5.0) testerobly! diff --git a/testerobly.gemspec b/testerobly.gemspec index 2daf21d..d2e3254 100644 --- a/testerobly.gemspec +++ b/testerobly.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |spec| spec.executables = %w[ testerobly ] spec.add_dependency "listen", "~> 3.9.0" + spec.add_dependency "logger", "~> 1.7" spec.add_development_dependency "minitest", "~> 5.0" - spec.add_development_dependency "logger", "~> 1.7" end From c339e3e4e1ea841e2aecc32a0f42ed0f99430aff Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sun, 28 Dec 2025 12:59:28 +0100 Subject: [PATCH 6/7] bump version --- Gemfile.lock | 2 +- testerobly.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c489aab..a311a82 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - testerobly (1.1.1) + testerobly (1.1.2) listen (~> 3.9.0) logger (~> 1.7) diff --git a/testerobly.gemspec b/testerobly.gemspec index d2e3254..6a258f4 100644 --- a/testerobly.gemspec +++ b/testerobly.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |spec| spec.name = "testerobly" - spec.version = "1.1.1" + spec.version = "1.1.2" spec.summary = "Test runner to launch alongside your developer session for immediate feedback" spec.description = "" spec.authors = ["Robert Starsi"] From 7b92de862b5af1260b447f8d40608b021e547bff Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sun, 28 Dec 2025 13:02:34 +0100 Subject: [PATCH 7/7] tweaks --- config/testerobly.rb | 4 ++-- test/{custom_on_change.rb => custom_on_change_test.rb} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename test/{custom_on_change.rb => custom_on_change_test.rb} (100%) diff --git a/config/testerobly.rb b/config/testerobly.rb index 2d3b83f..6a7eab8 100644 --- a/config/testerobly.rb +++ b/config/testerobly.rb @@ -1,6 +1,6 @@ Testerobly.configure do |config| - config.test_command = "ruby %s" - config.test_all_command = "echo 'sample test all command'" + config.test_command = "bin/test %s" + config.test_all_command = "bin/test" config.on_change = Proc.new do |path, tests| if path == "config/testerobly.rb" tests << "test/custom_on_change.rb" diff --git a/test/custom_on_change.rb b/test/custom_on_change_test.rb similarity index 100% rename from test/custom_on_change.rb rename to test/custom_on_change_test.rb