Follow

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")
"rspec"
elsif File.directory?("test")
"ruby -Itest"
else
"ruby"
end
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 @james I've always wanted a persistent test runner w/ a database. every time the tests run (locally), it would log the output + results. then you can quickly run commands like "run the tests that failed last time" or "run the remaining test that *wasn't* run last time"

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

@james this reminds me we need to pr against mastodon core to do markdown parsing. should be simple in theory 🤔

@inv0cat10n I wonder if it’s already been considered…?

Sign in to participate in the conversation
Ruby.social

A Mastodon instance for Rubyists & friends