Skip to content
Instant code-reloader and test runner for Elixir in one package
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
docs
lib
test
.gitignore
.travis.yml
CHANGELOG.md
README.md
mix.exs
mix.lock

README.md

MrT

Build status Hex version Hex downloads

alt text

Instant code-reloader and test runner for Elixir in one package. Currently tightly coupled to ExUnit and the conventional folder structure of Elixir packages.

Installation

  1. Add mr_t to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:mr_t, "~> 0.6.0", only: [:test, :dev]}]
end
```

Why pick this library instead of other alternatives?

Well... Because of the cool name, of course!

People ask me what the "T" stands for in my name. If you're a man, the "T" stands for TESTING. If you're a woman or child, it also stands for TESTING!

Mr. T

Back to serious...

In development mode this library allows you to iterate really quickly on your code, in similar fashion like the the Clojure REPL does. You can type in the editor and see the effect directly in IEx, without explicit "recompile" call. That feels a bit like magic... Good magic! On syntax errors you'll get the backtrace, but besides the library stays out of your way. And you have to start it explictly, just in case you don't want magic code reloading in the IEx.

In test mode it executes test code directly in current IEx, so you dont have to run a separate Mix process in the background. That keeps the feedback loop really tight, especially for large projects.

Skip loading all the code / tests again and again for every test run, you will feel the difference quite quickly. Also I'd like to have a concept of RunStrategies, that is a flexible way to match a changed file to corresponding test files.

Right now there is only a very simple RootName strategy, that turns a file like "lib/logic/email_sender.ex" to "email_sender" and runs all test files with that string in the full paths, like:

- tests/email_sender_test.exs
- tests/email_sender/mandrill_adapter_test.exs

This simple strategy allows you to run just the relevant tests quickly on each save-file stroke, directly in the IEx. It works also with Phoenix controllers / models quite nicely. Because we're keeping the Erlang VM running, the feedback for our TDD cycle is exceptionally fast.

Demo: MrT Dev mode

Demo

  • Installation
  • Starting MrT
  • Code reloading in dev mode
  • Feedback on syntax errors
  • Reloading continues to work after syntax errors fixed



Demo: MrT Test mode

Demo

  • TDD cycle
  • Starting MrT
  • Code reloading in test mode
  • Changes to code without matching tests files
  • Changes to code where only the relevant tests files are executed



Code Reloader

$ iex -S mix
# this starts only the code reloading, because we are in the :dev environment
iex> MrT.start
# now write some code in the editor, it will be immediately available in the IEx console

Testrunner

$ MIX_ENV=test iex -S mix
# this starts test runner and  code reloading, because we are in the :test environment
iex> MrT.start
# now code / write unit tests

## for more manual control:
# run tests only with "user" in filename
iex> MrT.run_matching("user")
# run all tests
iex> MrT.run_all

# run only tests with tag :focus in matched files
iex> MrT.focus(:focus)

# can be combined with RunAll strategy to run focused tests in all test files
iex> MrT.run_all_strategy_on


### when finished with focused test, reset and turn back to RootName strategy
# run only files matching basename
iex> MrT.run_all_strategy_off
# reverse / reset  ExUnit focus
iex> MrT.unfocus


### debugging with verbose mode
iex> MrT.verbosity_on
iex> MrT.verbosity_off

Stopping

iex> MrT.stop

Alternatives:

Desktop Notifications

TODO

[x] remove most of the reloading logic, because now the recompilation happens with IEx.Helpers
[x] allow stopping MrT
[x] make configuration more flexible
[x] configurable verbosity (default is silent)
[x] allow adding ExUnit contraints (tags)
[ ] Add MrT.Doctor for self-diagnosis
[ ] handle fs events properly (deletion / tmp files)
[ ] allow multiple ordered run_strategies
[ ] write unit tests
You can’t perform that action at this time.