Migrating from RSpec to Minitest::Spec?

2019-06-17 23:05发布

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.

1条回答
在下西门庆
2楼-- · 2019-06-17 23:51

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.

查看更多
登录 后发表回答