RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Finnaly figured out how to run single example easily with Guard Minitest/Spec

EDIT Looks like minitest-focus is the way to go here. Can’t believe that I haven’t heard of this until now!

I have been griping about how I would like to have an easy way to run a single it block spec for a long time and today I finally stopped griping and made it happen.

Using the below examples, you can now add “SOLO” to any it description and then run only that block for that file.

guard example: https://gist.github.com/mfpiccolo/0546c66092e964234f56

bash example: https://gist.github.com/mfpiccolo/501c2421a5a1d2fde940

Comments

Couldn’t you just as easily run the tests in just one file instead of the entire test suite for your app? Why did you need to run just one it block? For debugging?

What is the difference between this and it "works", :focus?

I had not had focus pointed out to me until today.

But isn’t the syntax

focus it “works” do assert_something end

I’m sorry, I was confusing MiniTest with RSpec (which supports the focus it "works" syntax as well as it “works”, :focus`—you taught me something there!) I don’t know if it applies to MiniTest, but if not yours looks like a great solution!

I am glad you pointed it out because it lead me to the gem minitest-focus which is what I wanted so thank you.

There is also minitest-line, for running a test nearest to the given line (it allows you to pass --line N in the command-line).

I would also highly recommend this article, just to understand how does it work exactly and what’s possible.

If you’re using Vim, I created vim-test some times ago, which should be able to run tests nearest to the cursor without any plugins, whichever Minitest syntax you’re using.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in