Giter Club home page Giter Club logo

minitest-emacs's Introduction

minitest.el

A minitest mode for emacs

Build Status MELPA

Usage

Command Description Mode binding
M-x minitest-verify Runs minitest test on the current file C-c , v
M-x minitest-verify-single Runs minitest test on the selected line C-c , s
M-x minitest-rerun Runs the last test again C-c , r
M-x minitest-verify-all Runs all the tests in the project C-c , a

Installation

Manual

Emacs

Just drop minitest.el. somewhere in your load-path. And:

(add-to-list 'load-path "~/emacs.d/vendor")
(require 'minitest)

Spacemacs

The Spacemacs Ruby layer supports minitest-emacs as one of its configurable test runners. To set the default Ruby test runner to use this package, edit the ruby layer entry in the dotspacemacs-configuration-layers list defined in your .spacemacs file:

dotspacemacs-configuration-layers
'(
  (ruby :variables
        ruby-test-runner 'minitest)
)

See the Spacemacs Ruby layer documentation for more info.

Using Marmalade or MELPA

M-x package-install minitest

Configuration

To enable minitest mode on ruby files, simply add to your dotfile:

(add-hook 'ruby-mode-hook 'minitest-mode)

In case you are using Spacemacs, add the above line to dotspacemacs/user-config which is towards the end of your .spacemacs dotfile:

(defun dotspacemacs/user-config ()
	(add-hook 'ruby-mode-hook 'minitest-mode))

If you have another hook already in here make sure to add this hook within its own set of parenthesis so that there is only one hook per parenthesis.

Rails

If you are working on a Rails project, you can set minitest-use-rails to true in order to use the bin/rails test command when running examples.

Docker

You can run tests inside a Docker container by setting minitest-use-docker to true and minitest-docker-container to the name of the container. By default this will use the command docker-compose exec to run the minitest command, which assumes you already have the specified container running. To customize the command, edit the minitest-docker-command variable.

Snippets

If you have yasnippet installed, you can load the snippets:

(eval-after-load 'minitest
  '(minitest-install-snippets))

Scroll Position

The compilation-scroll-output variable, when set to t, scrolls to the bottom of the test output. When set to nil, the test output buffer stays scrolled to the top.

Before version 0.10.0, this variable was set to t before running tests, but after version 0.10.0 it is not set explicitly anymore. In order to get back the old behavior, just set compilation-scroll-output to t yourself.

License

The MIT License (MIT)

Copyright (c) 2013 Arthur Nogueira Neves

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

minitest-emacs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

minitest-emacs's Issues

verify single with rails and docker seems broken

example:

-*- mode: minitest-compilation; default-directory: "~/proj" -*-
 started at Thu Sep 17 12:28:13

 docker-compose exec test bin/rails test test/models/user_test.rb\:153

Run options: --seed 30197

# Running:

.........................................

Finished in 2.451928s, 16.7215 runs/s, 19.1686 assertions/s.
41 runs, 47 assertions, 0 failures, 0 errors, 0 skips

this was with a non anonymous test within a few nested describe blocks. i've noticed this before but never made an issue.

Colons and hash marks in test name not handled properly

Colons : and hashes # are mapped to underscores by Minitest.

Given

  test "#start Do::This" do
     # . . . 
  end

The following runs no test:

%  script/testrb_or_zt  test/models/restorable/organization_user_test.rb -n /test_\#start_Do\:\:This/

# Running tests:

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

Replacing occurrences of both characters with underscores fixes it:

%  script/testrb_or_zt  test/models/restorable/organization_user_test.rb -n /test__start_Do__This/

# Running tests:
.

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

Tests not detected when they're present inside context blocks

Bug:

minitest-verify-single doesn't work when the test under the point is nested within a (non-top-level) context block.

Explanation:

When a test is nested within a context block, the block's description string is prepended to the test's generated method name:

context "validation" do
  test "does not require email" do
    org = Organization.new(:login => "ACME")
    assert org.valid?
  end
end

So the above test's corresponding method name is #test_validation_does_not_require_email, and hence the following finds no test when it's running minitest-verify-single:

 script/testrb_or_zt -v test/models/organization_test.rb -n/test_does_not_require_email/

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

A quick-and-dirty workaround is to modify minitest-verify-single so it doesn't prepend test_ to the -n flag's regex:

(defun minitest-verify-single ()
  "Run on current file."
  (interactive)
  (if (minitest--extract-str)
      (let* ((cmd (match-string 1))
             (str (match-string 2))
             (post_command (cond ((equal "test" cmd) (format "test_%s" (replace-regexp-in-string "[\s#:]" "_" str)))
                                 ((equal "it" cmd) str))))
        (minitest--file-command (minitest--test-name-flag post_command)))
    (error "No test found. Make sure you are on a file that has `def test_foo` or `test \"foo\"`")))
- (format "test_%s" (replace-regexp-in-string "[\s#:]" "_" str))
+ (format "%s" (replace-regexp-in-string "[\s#:]" "_" str))

That works...

script/testrb_or_zt -v test/models/organization_test.rb -n/does_not_require_email/
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips

...but it'll also execute multiple tests in cases where different context blocks each have tests with the same string.

context "validation" do
  test "does not require email" do
    org = Organization.new(:login => "ACME")
    assert org.valid?
  end
end

context "invalidation" do
  test "does not require email" do
    org = Organization.new(:login => "ACME")
    assert org.valid?
  end
end
 script/testrb_or_zt -v test/models/organization_test.rb -n/does_not_require_email/

OrganizationContext#test_invalidation_does_not_require_email_L42 = 1.55 s = .
OrganizationContext#test_validation_does_not_require_email_L33 = 0.02 s = .

2 tests, 2 assertions, 0 failures, 0 errors, 0 skips

Doesn't use correct ruby with rvm

When i try to run tests, it uses my default ruby but not the version mentioned in current project's .ruby-version file.

Maybe if we change directory to project-root before running minitest command we can solve this problem.

Right now it works as bundle exec <command>

How can we change it to
cd <project_root> && bundle exex <command>

Option to use line number instead of regex

Hi!

Is it possible to use line numbers instead of regex to execute the test(s)? In rails, you can run rails test test/foo/bar.rb:21 for instance. It's a bit more reliable than the current regex which fails quite often for me.

Perhaps this can be the default when setting the minitest-use-rails to t?

Switching from compilation mode to inf-ruby

Is there any reason that minitest-emacs isn't included in inf-ruby's list of modes to add inf-ruby-switch-from-compilation to the keymap? It's pretty easy to add the keybinding manually, but I was just curious if this was a conscious omission, and if not, if it'd be okay to make a PR over there and/or add some extra code here to add the keybinding.

Chruby support

Any chance I could get some advice on how to get this working with chruby?

Support new Rails 5 syntax

Beginning with Rails 5.0.0, testing is expected to be run via the rails test command rather than rake test, with rake test being fully deprecated at some point in the future. The effect of this today is that paths and test names passed via rake appear to be ignored, instead running the entire suite.

Not sure if the best solution here is to add a new (defcustom use-rails-5-syntax) or try to infer the appropriate syntax based on the project.

More on the new syntax can be found here. One upside is that the new runner accepts line numbers for running individual tests, which should obviate the need to regex for the test name.

not running minitest from the project directory

When I try and run a test by pressing C-c ,s the test is not being run from the project directory but from my home directory, e.g.

 bundle exec ruby -Ilib\:test\:spec /Users/paulcowan/projects/crm/test/integration/contacts/import_contact_test.rb -ntest_primary_values_set_if_provided

The project directory is /Users/paulcowan/projects/crm. Is there a way that I can specify the project directory? If I am in the home directory then it does not pick up the correct rbenv version.

verify-single command doesn't work

Hi,
I found the verify single command doesn't work. Details:

The test name generated by minitest is: "test_0001_should create a new index file"
However, minitest-emacs creates below parameter which doesn't work
"-n/should_create_a_new_index_file/"

I tried with Intellij and it outputs:
"--name=/test_\d+_should create a new index file/"

This should be easy to fix but I am not familiar with elisp. Could you fix it or let me know where to fix it, I'll raise a PR?

Kind Regards,
He Qi

Consider add snippets?

User always type assert_* and refute_* in test buffers.
If user has yasnippet package installed,
should we provide these snippets?

Documentation

I'm using Spacemacs (just graduated from sublime text) which has it's own way to manually install packages. I figure out how to install it and I'm happy to contribute that in the Readme file. What is your protocol for contributions?

Minitest snippet usage documentation?

Hi, can someone add some additional documentation to the README in regards to the usage of the Minitest snippets? BTW, I have added the following:

(eval-after-load 'minitest
  '(minitest-install-snippets))

However, it's not clear as to how to use them.

Adding this package to non-gnu ELPA

Hello to anyone watching this repository ๐Ÿ˜„ ๐Ÿ‘‹๐Ÿฝ

I would like to get this package included in the NonGNU ELPA package repository. As far as I know, I would just need to submit the source repository to the emacs-devel list and it should be good to go.

However, there's been an push lately to move away from GitHub, as it is not a good/ethical citizen in the free software world. If there are no objections, I plan to fork this repo over to sourcehut or codeberg and serve the package (to ELPA) from there. I understand that people may feel this is a barrier to contributions, so I wanted to give some space for discussion.

Very little of minitest-emacs is work I've contributed to personally, but I use it daily and have an interest in keeping it alive and well in the Emacs ecosystem. Please add your opinions to this discussion, thank you!

Tests hang because external command thinks it's running in interactive terminal

I use minitest-mode to run tests in Rails app that has schema in SQL format, so Rails test helpers run external psql program to load that schema into test database.

psql displays its output through pager (less, more) if it detects it's running in interactive terminal and output is larger than terminal size. compilation-mode's command runner allocates pseudo terminal so psql thinks it's running in interactive terminal:

18046 ttys004    0:02.51 ruby -Ilib:test:spec test/functional/foo_controller_test.rb
18063 ttys004    0:02.41 ruby bin/rails db:test:prepare

Because it's not a real interactive terminal, I can't press a key to skip more and continue, so test process hangs forever.

(Not sure if it can be fixed without fixing underlying compilation-mode)

(The part of the problem is that compilation-mode's tty does not support TIOCGWINSZ ioctl)

Minimal example of test with this behavior (requires psql tool and postgresql server, I think you can replace it with just system "echo|less" because less also checks for interactivity):

require "minitest/autorun"

class ExternalCommandTest < Minitest::Test
  def test_external_command
    system "psql postgres -c 'select 1;'"
  end
end

verify single with anonymous tests

Currently, minitest-emacs extracts the test description to pass as a regex to minitest. the minitest --name flag can take a string or a pattern.

For tests like it { assert true }, there is no string or pattern to pass from the test buffer. It appears that under the hood, minitest defines methods like test_0001_anonymous for these it blocks. The number determined by the order the test is defined in the file.

One way to potentially handle this is to use Emacs to parse the entire test buffer and build up a list of test definitions for the whole file. This could prove useful for other reasons, but may be complicated to accomplish, especially given the various ways that tests can be defined in the minitest ecosystem.

Escape /

If the method has / on the name, it will not work as we are not escaping that.

Test file name regex

Hi! I just started using yasnippet and noticed that minitest-mode isn't identifying my test files (test_*.rb). At first it seemed odd since it does run my tests. Then I looked at the code and noticed it can also run minitest specs, awesome! I came up with a regex for minitest-test-file-name-re that covers test_*.rb, _spec.rb, [-_]test.rb so yasnippet is on by default regardless of test file naming style. Would it be ok to change it or is there a reason behind only covering [-_]test.rb files? Cheers!

verify-single opens many new buffers when using line numbers

due to the buffer naming scheme in the code, we get many open buffers when using verify-single and line numbers. this is mostly harmless, but i'm not sure its expected behavior. if i remember correctly, other test runners replace the current test comint buffer rather than making a new one.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.