No commit activity in last 3 years
No release in over 3 years
A command-line tool for converting minitest files to rspec.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.7
~> 9.1
~> 12.1
~> 3.5
~> 0.51.0

Runtime

~> 2.3
~> 2.1
 Project Readme

MinitestToRspec

Converts minitest files to rspec.

Build Status

Example

Input:

require 'test_helper'
class ArrayTest < ActiveSupport::TestCase
  test "changes length" do
    ary = []
    assert_difference "ary.length" do
      ary.push(:x)
    end
  end
end

Output:

require("spec_helper")
RSpec.describe(Array) do
  it("changes length") do
    ary = []
    expect { ary.push(:x) }.to(change { ary.length })
  end
end

You might not like the code style of the output. More on that below.

Install

gem install minitest_to_rspec

Usage

CLI

mt2rspec [--rails] [--mocha] source_file [target_file]
mt2rspec --help

Ruby

require 'minitest_to_rspec'
converter = MinitestToRspec::Converter.new(rails: false, mocha: false)
converter.convert("assert('banana')")
#=> "expect(\"banana\").to(be_truthy)"

Output

The only goal is correctness. Code style is not a consideration. Providing the level of configuration necessary to make everyone happy would be a huge distraction from the main purpose.

After conversion, I recommend using rubocop's awesome --auto-correct feature to apply your preferred code style.

Comments are discarded by ruby_parser, so we have no way of preserving them.

Supported Assertions

Selected assertions from minitest, Test::Unit, and ActiveSupport. See doc/supported_assertions.md for rationale. Contributions are welcome.

Assertion Arity Source
assert
assert_difference 1,2
assert_equal 2,3 Test::Unit
assert_not_equal 2,3 Test::Unit
assert_match
assert_nil
assert_not_nil
assert_no_difference ActiveSupport
assert_nothing_raised Test::Unit
assert_raise 0..2 Test::Unit
assert_raises 0..2 Minitest
refute
refute_equal
refute_raise
refute_raises

Supported Mocha

Mocha Arity Block Notes
any_instance 0 n/a
expects 1 n/a
once 0 n/a
stub 0,1,2 no
stub_everything 0,1,2 no Uses as_null_object, not the same.
stubs 1 n/a
twice 0 n/a

To do: at_least, never, raises, etc.

Supported shoulda-context methods

Mocha Arity Block Notes
context 1 yes
setup 1,2 no
should 1,2 yes

Acknowledgements

This project would not be possible without ruby_parser, sexp_processor, and ruby2ruby by Ryan Davis.