Search code examples
rubyunit-testingautotest

How do I manually specify the test files to run in autotest?


How do I manually specify which test/unit test files should be run when a non-test file gets updated?


Solution

  • You can create custom mappings in ~/.autotest or <project_path>/.autotest file like this:

    Autotest.add_hook :initialize do |at|
      at.add_mapping(/lib\/foo\/(.*).rb/, true) do |filename, matchdata|
        ["spec/lib/foo/#{matchdata[1]}_spec.rb"]
      end
    end
    

    This matches specs in spec/lib/foo directory to lib/foo files, so these specs will run once files under lib/foo are being changed. I guess you can do the same with test directory.