Run a specific test or only last failed test

2,986 views
Skip to first unread message

Lephyrius

unread,
Feb 21, 2013, 10:07:26 AM2/21/13
to minitest-rails
How can I run a specific test or just the last failed test in minitest-
rails?
Right now I can only control what group I want to run with:
bundle exec rake minitest:controllers

Mike Moore

unread,
Feb 21, 2013, 1:18:49 PM2/21/13
to minites...@googlegroups.com
There are several ways to run specific tests. If you want to run one test file, you can use the rake task and specify the file using the TEST environment variable: (You will need to install 0.5.2 to get this to work.)

$ rake test TEST=test/models/widget_test.rb

Or, if you want to avoid the test preparation that the rake tasks perform, you can call the file directly:

$ ruby -Ilib:test test/models/widget_test.rb

If you want to run just one test method, you have to call the file directly:

    def test_refresh
      # Do some testing here
    end

$ ruby -Ilib:test test/models/widget_test.rb -n test_refresh

If your test is using the spec DSL, you need to find the name of the generated test method and call that:

    it 'refreshes' do
      # Do some testing here
    end

$ ruby -Ilib:test test/models/widget_test.rb -n test_0003_refreshes



--
-- You received this message because you are subscribed to the Google Groups minitest-rails group. To post to this group, send email to minites...@googlegroups.com. To unsubscribe from this group, send email to minitest-rail...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/minitest-rails?hl=en
---
You received this message because you are subscribed to the Google Groups "minitest-rails" group.
To unsubscribe from this group and stop receiving emails from it, send an email to minitest-rail...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Mike Moore

unread,
Feb 21, 2013, 5:23:01 PM2/21/13
to minites...@googlegroups.com
Ugh! I left off one option. I was working up to it, then got distracted, and sent the email without completing my thought.

If you are using the spec DSL and don't want to figure out the method name, or just don't like typing, you should use the awesome m gem. Its metal! :metal:


You can reference the line of the test method:

$ m test/models/widget_test.rb:63

Or you can run the whole test file:

$ m test/models/widget_test.rb

Or you can run all the test files in a directory:

$ m test/models

Tim Griffin

unread,
Mar 5, 2013, 8:39:07 PM3/5/13
to minites...@googlegroups.com
Hi Mike;

I have model tests running normally in my Rails 3.2 project if I do 

$ rake minitest:models

The tests run only once. 

But, if I use the metal gem, they're running twice. 

$ m test/models/package/package_test.rb

I know you had GitHub Issue (95) about this for minitest-rails itself, but I was wondering if you might know why the metal gem would be kicking things off twice. In that issue, I did quite understand how to suppress the "default testing railtie". 

Can you enlighten me?

Thanks,
Tim

Tim Griffin

unread,
Mar 5, 2013, 8:43:26 PM3/5/13
to minites...@googlegroups.com
Ah, I'm working with an older Rails 2.x app that's now running under Rails 3.2. My config/application.rb has only this line:

 require 'rails/all'

whereas I see that newer-generated apps would have this replaced with:

 require "action_mailer/railtie"
 require "active_resource/railtie"
 require "active_record/railtie"
 require "rails/test_unit/railtie"
 require "sprockets/railtie"

So, I guess I just have to split out "require 'rails/all'" to include just what I need, yes? 

Tim Griffin

unread,
Mar 5, 2013, 10:21:33 PM3/5/13
to minites...@googlegroups.com
Mike, I just saw your posting on stackoverflow, from Feb 23 confirming my guess below. 

So, I've done this:

require "rails"
 
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
require "minitest/rails/railtie"

But, oddly, the "metal" gem is still running tests twice. 

Still hunting...

Tim Griffin

unread,
Mar 5, 2013, 10:25:10 PM3/5/13
to minites...@googlegroups.com
Darn. I see this is an open issue (26) with the "metal" gem. 

Sorry to have troubled anyone here.

T

Артём Петров

unread,
Dec 13, 2015, 7:46:07 PM12/13/15
to minitest-rails
https://github.com/artempartos/minitest-failed

четверг, 21 февраля 2013 г., 18:07:26 UTC+3 пользователь Lephyrius написал:
Reply all
Reply to author
Forward
0 new messages