A script to run tests changed since master, pretty handy when checking PRs:

test_runner = File.exists?("Gemfile") ? "bundle exec " : ""
test_runner += if File.exists?("config/application.rb")
"rails test"
elsif File.directory?("spec")
elsif File.directory?("test")
"ruby -Itest"
changed_test_files = `git log --name-only --pretty=oneline --full-index master..HEAD`.split.select { |f| f =~ /\Atest|spec/ }
exec "#{test_runner} #{changed_test_files.join(' ')}"

I put it in a file called `~/bin/test-diff` and mark it as executable.

@james Very interesting idea... 🤔 Even more powerful would be to also runs tests for any non-test files changed since master. Assuming that your test <-> non-test directory structure is predictable.

(too lazy to write the right bash to do that though 😁)

@jeromedalbert I believe something like guard’s mapping might help with that

Sign in to participate in the conversation

A Mastodon instance for Rubyists & friends