ybakos
ybakos

Reputation: 8630

How does one configure Guard to run Rails 5 system tests?

By default rails test does not run system tests, and one must invoke rails test:system in order to run the system tests. Given that one is using Guard, what is the proper addition to the Guardfile such that guard will:

  1. Run all the tests, including the system tests.
  2. Run the appropriate system test when it changes.

I have tried something like:

guard :minitest, spring: true do
  # ...
  watch(%r{^test/system\/?(.*)_test\.rb$})  { 'test' }
  # ...
end

But it seems I am not educated in configuring Guard.

Upvotes: 0

Views: 266

Answers (1)

coreyward
coreyward

Reputation: 80041

Rails specifically excluded system tests from being run with rails test because they're much slower. The recommended workflow is to run your fast unit tests while you're working (i.e. with guard) and run system tests once you're ready to commit to confirm functionality.

If you wanted to do this anyways, you would need to either add a new Guard plugin (guard :yourthing { ... }), or you can simply configure your rails test command to also include rails test:system using Rake:

# Rakefile
Rake::Task["test"].enhance ["test:system"]

This will make rake, rake test, and rake test:run all run your system tests as well, including when they're run from Guard.

Upvotes: 1

Related Questions