Larry’s Blog

Test Runner for Rails 5

| Comments

With Rails PR #19216 by @senny and @arthurnn merged into Rails master branch, Rails will have a test runner for Rails 5.0. And it’s awesome.

Remember @tenderlove wrote a blog to describe his experience with Minitest and RSpec, and he listed things he disliked about Minitest?

Well, it will work now if you are using rails test runner on the command line. But of course it has to be a Rails app, and specifies Rails version to github master branch.

Here I’m gonna just paste @arhurnn’s example posted on the pull request.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[arthurnn@ralph myapp]$ bin/rails test /Users/arthurnn/dev/railstest/myapp/test/models/comment_test.rb:8
Run options: --seed 28435

# Running:

F

Finished in 0.007840s, 127.5510 runs/s, 255.1020 assertions/s.

  1) Failure:
  CommentTest#test_failling_one [/Users/arthurnn/dev/railstest/myapp/test/models/comment_test.rb:10]:
  Failed refutation, no message given

  1 runs, 2 assertions, 1 failures, 0 errors, 0 skips

  Failed tests:

  bin/rails test /Users/arthurnn/dev/railstest/myapp/test/models/comment_test.rb:8

This is exactly what @tenderlove and also, many other rails developers including me (not fans of RSpec) would want. We don’t have to run a single test with typing -n test_failing_one manually.

And with the test runner, we could do exact things like we do with rake tasks before.

When we want to run all controller tests from test/controllers before, we would use a rake task: rake test:controllers. And now (Rails master branch), just bin/rails test test/controllers. As @senny explained PR #19216 (comment) here, the first argument after bin/rails test is just a file or directory, rails test runner won’t support fancy pattern convention/matching.

Kudos to @senny and @arthurnn, and let’s look forward the Rails 5 release!

Comments