LoginSignup
2
4

More than 5 years have passed since last update.

minitestでassertした行・ファイルを素早く開く

Posted at

Ruby on Railsにおいて特に指定しないとテストにはminitestが採用されるようになっている。

私は普段の開発においてテストにはrspecを採用し、Emacsのrspec-modeを経由して使っていたのだが、さすがに標準のほうを使ったことがないってのはよくないなと考えてminitest + minitest-modeを使ってみることにした。

-*- mode: minitest-compilation; default-directory: "~/gitwork/minitest-project/" -*-
 started at Mon Mar 27 10:10:21

 bundle exec ruby -Ilib\:test\:spec test/controllers/minitest_controller_test.rb
Run options: --seed 33436

# Running:

F

Failure:
MiniTestControllerTest#test_test_yaml [test/controllers/minitest_controller_test.rb:40]:
Expected false to be truthy.


bin/rails test test/controllers/minitest_controller_test.rb:39



Finished in 0.455735s, 2.1943 runs/s, 2.1943 assertions/s.

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

 exited abnormally with code 1 at Mon Mar 27 10:10:24

この書式だとなぜかminitest-compilation-modeなのにTABキーでエラーに移動し、RETキーで開くができないんだなあ。

いろいろ試行錯誤した結果、以下の手順をした。

minitest-reportersの採用

Gemfilegroup :development, :test do ブロックに以下を追加。

  gem 'minitest-reporters'

テストの結果フォーマット変更

test/test_helper.rb で設定する

test/test_helper.rb
  Minitest::Reporters.use!(
    Minitest::Reporters::SpecReporter.new,
    ENV,
    Minitest.backtrace_filter
  )

変更後のテスト結果表示 & ジャンプ

表示を以下のようにかえることができた。この書式だとTABキーでエラーに移動し、RETキーで素早く開くことができた。

-*- mode: minitest-compilation; default-directory: "~/gitwork/minitest-project/" -*-
 started at Mon Mar 27 10:30:02

 bundle exec ruby -Ilib\:test\:spec test/controllers/minitest_controller_test.rb
Run options: --seed 33436

MiniTestControllerTest
  test_test_yaml                                                  FAIL (0.39s)
Minitest::Assertion:         Expected false to be truthy.
        test/controllers/minitest_controller_test.rb:40:in `block in <class: MiniTestControllerTest>'


Finished in 0.39460s
1 tests, 1 assertions, 1 failures, 0 errors, 0 skips

 exited abnormally with code 1 at Mon Mar 27 10:30:04

ていうか

こんなはずじゃなくねえ? rspec-modeminitest-mode の切り替えもいまいちピンとこないし、なんかもっといい方法あったら教えてください。 rspec-compilation-mode では g 一発でrerunできるのに minitest-*mode ではいちいちコマンド叩いてます。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4