Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating from RSpec to Minitest::Spec?

Tags:

rspec

minitest

Is there a strategy or set of steps to follow to migrate from RSpec 2 to MiniTest::Spec? I'd like to take a look at doing this for a large project but I'm not sure where to begin.

like image 893
John Feminella Avatar asked Dec 07 '11 22:12

John Feminella


1 Answers

I haven't used MiniTest::Spec for that long, I'm working on porting over some of our tests myself, but here are the few things I've noticed coming from RSpec:

  • The matchers are of course different -- it's must/wont instead of should/should_not, and predicate matchers are gone so you can't say must_be_true/must_be_false or the like.
  • That said, if you've written custom RSpec matchers, or are using shoulda-matchers or the like, you should be able to use them with MiniTest thanks to the minitest-matchers gem. But YMMV.
  • MiniTest::Spec doesn't provide context, so you'll need to either change this to describe or alias it.
  • MiniTest::Spec also doesn't provide described_class.
  • You also don't have before :all.
  • subject must be set manually (I think, someone correct me if I'm wrong).

So to answer your question, in terms of porting an existing suite of tests, I'm afraid you can't really do a simple find and replace, you'll have to port over each test file one at a time. Obviously, this means you have to determine whether the effort is worth it.

like image 195
Elliot Winkler Avatar answered Oct 18 '22 02:10

Elliot Winkler