Test Unit -> Minitest VS Rspec

So we have a fairly large rails 3 app using Test Unit. We’re wanting to switch to either MiniTest with spec, or Rspec and are doing some research on pros/cons. I would love any of your feedback. A few questions I have:

  • What major items does RSpec have that you would really miss with Minitest (with minitest/spec)?
  • What major differences do you see between them?
  • With Rspec’s wide usage, does the community support grant using it, and/or does anyone see a trajectory for either framework as far as community support goes?. .trends?
  • Moving to minitest we can do right now, but would using both test unit and rspec in an intermediate time be a major pain?
  • I’ve heard a pro for minitest for it’s simplicity/debugging… what are some examples of issues being run into because of Rspec’s complexity?

Thanks!

Redoing all your specs is pretty awful, and brings with it some technical risk. Minitest is backwards compatible with TestUnit, so while I like RSpec better, I think you’re better off just moving forward with Minitest if your app is already established and has test coverage.

Yeah, that’s definitely a pro that I had on the Minitest side. We would have to run both until we get them all going, we probably wouldn’t do it all at once.

I have somewhat of a preference for RSpec, but honestly the difference between the testing libraries you mentioned is fairly small.

If I had a very large app with a Test Unit suite, I would avoid rewriting it in RSpec. That’s lots of boring work for very little gain.

If I were you, I’d probably start converting my T::U tests into MiniTest, but I’d do it slowly. One approach I’ve used with success is to only convert a file of tests when you need to change it otherwise (though make sure it happens in its own commit).

Thanks Ben. Yeah that’s my thought: use Minitest and convert slowly over time. My teammates’ biggest concern is community support. And you don’t see any feature’s you would really miss?

I’m not super familiar with MiniTest, so I can’t really say.

However, I mostly only use the core features of RSpec, so I don’t think there’d be much for me to miss.

Actually Test::Unit and Minitest (versions < 5) are virtually the same for recent version of ruby and rails:

https://github.com/ruby/ruby/blob/trunk/lib/test/unit.rb#L12
https://github.com/ruby/ruby/blob/trunk/lib/test/unit/assertions.rb#L7

That being said, I to prefer RSpec, but mostly for the syntax. In terms of functionality I believe they go hand in hand, so in your case Minitest 4 is probably the best choice.

Hope it helps.

Yeah, I ended up getting our test suite up and running with minitest pretty quick which is awesome.

Just now I’m realizing minitest stubbing class methods are a bit funky since they only support running code within a block, so I think we’d have to use mocha as well.

I love minitest, but I also use Mocha. Baker’s mocking library (MiniMock) hasn’t been updated for years!

However, I will caveat mocha with this… if you are using stub_chain or any_instance, then please STOP!

2 Likes