Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

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
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
PATH
remote: .
specs:
testerobly (1.1.1)
testerobly (1.1.2)
listen (~> 3.9.0)
logger (~> 1.7)

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
Expand Down
15 changes: 15 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions config/testerobly.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 0 additions & 4 deletions test/custom_on_change.rb

This file was deleted.

9 changes: 9 additions & 0 deletions test/custom_on_change_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require "bundler/setup"
require "minitest/autorun"
require "fileutils"
require "tmpdir"

require "testerobly"
104 changes: 103 additions & 1 deletion test/testerobly_test.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion testerobly.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -14,4 +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"
end