Search code examples
rubyminitestguard

Ignore directories with Guard


I'm using guard-minitest to automatically run my tests.

I also have a skeleton gem inside the test/fixtures directory.

The problem is, now Guard is running the tests in the skeleton gem also.

How can I tell Guard to only run my tests for my actual project and not any projects in the test/fixtures directory?

I've tried the following, but it isn't working:

guard :minitest, :exclude => "test/fixtures/*" do
  # with Minitest::Unit
  watch(%r{^test/(.*)\/?test_(.*)\.rb$})
  watch(%r{^lib/(.*/)?([^/]+)\.rb$})     { |m| "test/#{m[1]}test_#{m[2]}.rb" }
  watch(%r{^test/test_helper\.rb$})      { 'test' }
end

Edit:

The docs make it seem like I can add an ignore path, this also didn't work:

ignore %r{^test/fixtures/}

guard :minitest do
  watch(%r{^test/(.*)\/?test_(.*)\.rb$})
  watch(%r{^lib/(.*/)?([^/]+)\.rb$})     { |m| "test/#{m[1]}test_#{m[2]}.rb" }
  watch(%r{^test/test_helper\.rb$})      { 'test' }
end

Edit:

As recommended below I tried removing the asterisk, also doesn't work:

ignore %r{^test/fixtures/}

guard :minitest do
  watch(%r{^test/test_(.*)\.rb$})
  watch(%r{^lib/(.*/)?([^/]+)\.rb$})     { |m| "test/#{m[1]}test_#{m[2]}.rb" }
  watch(%r{^test/test_helper\.rb$})      { 'test' }
end

Solution

  • Make a more specific directory, add a more specific watcher regular expression, and add a test_folders: options docs

    This is my working guard file and test dir:

    guard :minitest, test_folders: 'test/real' do
      watch(%r{^test/real/(.*)\/?test_(.*)\.rb$})
      watch(%r{^lib/(.*/)?([^/]+)\.rb$})     { |m| "test/real/#{m[1]}test_#{m[2]}.rb" }
      watch(%r{^test/test_helper\.rb$})      { 'test/real' }
    end
    

    dir structure:

    $ tree -L 2 test
    test
    ├── fixtures
    │   └── newgem
    └── real
        ├── devify
        ├── test_devify.rb
        └── test_helper.rb
    
    4 directories, 2 files