• Stars
    star
    246
  • Rank 164,726 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 14 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Guard::Minitest automatically run your tests (much like autotest)

Guard::Minitest

Gem Version Build Status Dependency Status Code Climate Coverage Status

Guard::Minitest allows to automatically & intelligently launch tests with the minitest framework when files are modified.

  • Compatible with minitest >= 3.0 (optimal support for 5.x).
  • Tested against Ruby 1.9.3, 2.0.0, JRuby and Rubinius (1.9 mode).

IMPORTANT NOTE: guard-minitest does not depend on guard due to obscure issues - you must either install guard first or add it explicitly in your Gemfile (see: #131 for details)

Install

Please be sure to have Guard installed before you continue.

The simplest way to install Guard::Minitest is to use Bundler.

Add Guard::Minitest to your Gemfile:

group :development do
  gem 'guard' # NOTE: this is necessary in newer versions
  gem 'guard-minitest'
end

and install it by running Bundler:

$ bundle

Add guard definition to your Guardfile by running the following command:

guard init minitest

Ruby on Rails

Spring

Due to complexities in how arguments are handled and running tests for selected files, it's best to use the following spring command:

guard "minitest", spring: "bin/rails test" do
  # ...
end

(For details see issue #130).

Rails gem dependencies

Ruby on Rails lazy loads gems as needed in its test suite. As a result Guard::Minitest may not be able to run all tests until the gem dependencies are resolved.

To solve the issue either add the missing dependencies or remove the tests.

Example:

Specify ruby-prof as application's dependency in Gemfile to run benchmarks.

Rails automatically generates a performance test stub in the test/performance directory which can trigger this error. Either add ruby-prof to your Gemfile (inside the test group):

group :test do
   gem 'ruby-prof'
end

Or remove the test (or even the test/performance directory if it isn't necessary).

Usage

Please read Guard usage doc

Guardfile

Guard::Minitest can be adapated to all kind of projects. Please read guard doc for more info about the Guardfile DSL.

Standard Guardfile when using Minitest::Unit

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

Standard Guardfile when using Minitest::Spec

guard :minitest do
  watch(%r{^spec/(.*)_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})         { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
end

Options

List of available options

all_on_start: false               # run all tests in group on startup, default: true
all_after_pass: true              # run all tests in group after changed specs pass, default: false
cli: '--test'                     # pass arbitrary Minitest CLI arguments, default: ''
test_folders: ['tests']           # specify an array of paths that contain test files, default: %w[test spec]
include: ['lib']                  # specify an array of include paths to the command that runs the tests
test_file_patterns: %w[test_*.rb] # specify an array of patterns that test files must match in order to be run, default: %w[*_test.rb test_*.rb *_spec.rb]
spring: true                      # enable spring support, default: false
zeus: true                        # enable zeus support; default: false
drb: true                         # enable DRb support, default: false
bundler: false                    # don't use "bundle exec" to run the minitest command, default: true
rubygems: true                    # require rubygems when running the minitest command (only if bundler is disabled), default: false
env: {}                           # specify some environment variables to be set when the test command is invoked, default: {}
all_env: {}                       # specify additional environment variables to be set when all tests are being run, default: false
autorun: false                    # require 'minitest/autorun' automatically, default: true

Options usage examples

:test_folders and :test_file_patterns

You can change the default location of test files using the :test_folders option and change the pattern of test files using the :test_file_patterns option:

guard :minitest, test_folders: 'test/unit', test_file_patterns: '*_test.rb' do
  # ...
end

:cli

You can pass any of the standard MiniTest CLI options using the :cli option:

guard :minitest, cli: '--seed 123456 --verbose' do
  # ...
end

:spring

Spring is supported (Ruby 1.9.X / Rails 3.2+ only), but you must enable it:

guard :minitest, spring: true do
  # ...
end

Since version 2.3.0, the default Spring command works is bin/rake test making the integration with your Rails >= 4.1 app effortless.

If you're using an older version of Rails (or no Rails at all), you might want to customize the Spring command, e.g.:

guard :minitest, spring: 'spring rake test' do
  # ...
end

:zeus

Zeus is supported, but you must enable it. Please note that notifications support is very basic when using Zeus. The zeus client exit status is evaluated, and a Guard :success or :failed notification is triggered. It does not include the test results though.

If you're interested in improving it, please open a new issue.

If your test helper matches the test_file_patterns, it can lead to problems as guard-minitest will submit the test helper itself to the zeus test command when running all tests. For example, if the test helper is called test/test_helper.rb it will match test_*.rb. In this case you can either change the test_file_patterns or rename the test helper.

guard :minitest, zeus: true do
  # ...
end

:drb

Spork / spork-testunit is supported, but you must enable it:

guard :minitest, drb: true do
  # ...
end

The drb test runner honors the :include option, but does not (unlike the default runner) automatically include :test_folders. If you want to include the test paths, you must explicitly add them to :include.

Development

Pull requests are very welcome! Please try to follow these simple rules if applicable:

  • Please create a topic branch for every separate change you make.
  • Make sure your patches are well tested. All specs run by Travis CI must pass.
  • Update the README.
  • Please do not change the version number.

For questions please join us in our Google group or on #guard (irc.freenode.net).

Maintainer

Eric Steele

Author

Yann Lugrin

Contributors

https://github.com/guard/guard-minitest/graphs/contributors

More Repositories

1

guard

Guard is a command line tool to easily handle events on file system modifications.
Ruby
6,191
star
2

guard-livereload

Guard::LiveReload automatically reload your browser when 'view' files are modified.
JavaScript
2,100
star
3

listen

The Listen gem listens to file modifications and notifies you about the changes.
Ruby
1,915
star
4

guard-rspec

Guard::RSpec automatically run your specs (much like autotest)
Ruby
1,301
star
5

rb-inotify

A thorough inotify wrapper for Ruby using FFI.
Ruby
311
star
6

guard-jasmine

The Swiss Army knife for automated Jasmine specs in your console.
Ruby
305
star
7

guard-spork

Guard::Spork automatically manage Spork DRb servers
Ruby
300
star
8

rb-fsevent

FSEvents API with signals handled (without RubyCocoa)
C
245
star
9

guard-bundler

Guard::Bundler automatically install/update your gem bundle when needed
Ruby
116
star
10

guard-test

Guard::Test automatically run your tests (much like autotest)
Ruby
95
star
11

guard-less

Guard::Less automatically compiles less (like lessc --watch)
Ruby
44
star
12

guard-pow

Guard::Pow automatically manage Pow applications restart
Ruby
43
star
13

guard-process

Guard extension to run cli processes
Ruby
43
star
14

guard-haml

Watch haml files with guard
Ruby
40
star
15

guard-nanoc

A Guard for nanoc
39
star
16

notiffany

wrapper for popular notification libs
Ruby
34
star
17

guard-yield

Run any Ruby code when files are changed/added/removed
Ruby
14
star
18

shellany

portable shell command output capturing
Ruby
8
star
19

guard-phpcs

Guard::PHPCS automatically runs PHP Code Sniffer when watched files are modified
Ruby
5
star
20

guard-compat

Test helper for testing Guard plugins
Ruby
5
star
21

guard-ronn

Guard::Ronn automatically builds manuals.
Ruby
5
star
22

guard-steering

Guard for Steering, a Handlebars.js Ruby precompiler wrapper.
Ruby
4
star
23

guard-phpmd

Guard::PHPMD automatically runs PHP Mess Detector when watched files are modified
Ruby
3
star
24

guard-premailer

Inline your css into html for e-mail templates with guard
Ruby
2
star
25

guard.github.com

Guard homepage (work in progress)
Ruby
1
star
26

guard-post

Watch Static Files, Convert them to Database Records (Mongoid, ActiveRecord, etc.)
Ruby
1
star
27

listen-compat

Compatibility wrapper for the Listen gem
Ruby
1
star