---
title: "How to add additional directories to test"
description: "This blog discusses how to add additional directories to test"
canonical_url: "https://www.bigbinary.com/blog/adding-directory-to-rake-test"
markdown_url: "https://www.bigbinary.com/blog/adding-directory-to-rake-test.md"
---

# How to add additional directories to test

This blog discusses how to add additional directories to test

- Author: Neeraj Singh
- Published: April 26, 2014
- Categories: Rails

In a project we needed to write different parsers for different services. Rather
than putting all those parsers in _app/models_ or in _lib_ we created a new
directory. We put all the parsers in _app/parsers_ .

We put all the tests for these parsers in _test/parsers_ directory.

We can run tests parsers individually by executing _rake test
test/parsers/email_parser_test.rb_. However when we run _rake_ then tests in
_test/parsers_ are not picked up.

We added following code to _Rakefile_ to make _rake_ pickup tests in
_test/parsers_.

```ruby

# Adding test/parsers directory to rake test.
namespace :test do
  desc "Test tests/parsers/* code"
  Rails::TestTask.new(parsers: 'test:prepare') do |t|
    t.pattern = 'test/parsers/**/*_test.rb'
  end
end

Rake::Task['test:run'].enhance ["test:parsers"]

```

Now when we run _rake_ or _rake test_ then tests under _test/parsers_ are also
picked up.

Above code adds a rake task _rake test:parsers_ which would run all tests under
_test/parsers_ directory.

We can see this task by execute _rake -T test_.

```plaintext

$ rake -T test
rake test         # Runs test:units, test:functionals, test:integration together
rake test:all     # Run tests quickly by merging all types and not resetting db
rake test:all:db  # Run tests quickly, but also reset db
rake test:parsers # Test tests/parsers/* code
rake test:recent  # Run tests for {:recent=>["test:deprecated", "test:prepare"]} / Deprecated; Test recent changes

```

## Links

- [Human page](https://www.bigbinary.com/blog/adding-directory-to-rake-test)
