How to set up MiniTest?

This question is similar to How to run all tests with minitest? Using Ruby 1.9.3 and Rake 0.9.2.2, given a directory layout like this: Rakefile lib/alpha.rb spec/alpha_spec.rb Here is what alpha_spec.rb might look like: require ‘minitest/spec’ require ‘minitest/autorun’ # arranges for minitest to run (in an exit handler, so it runs last) require ‘alpha’ describe …

Read more

How do I stub things in MiniTest?

# Create a mock object book = MiniTest::Mock.new # Set the mock to expect :title, return “War and Piece” # (note that unless we call book.verify, minitest will # not check that :title was called) book.expect :title, “War and Piece” # Stub Book.new to return the mock object # (only within the scope of the …

Read more

How to run all tests with minitest?

Here’s a link to Rake::TestTask. There is an example in the page to get you started. I’ll post another one that I’m using right now for a gem: require ‘rake/testtask’ Rake::TestTask.new do |t| t.pattern = “spec/*_spec.rb” end As you can see, I assume that my files are all in /lib and that my specs are …

Read more

What is the expected syntax for checking exception messages in MiniTest’s assert_raises/must_raise?

You can use the assert_raises assertion, or the must_raise expectation. it “must raise” do assert_raises RuntimeError do bar.do_it end -> { bar.do_it }.must_raise RuntimeError lambda { bar.do_it }.must_raise RuntimeError proc { bar.do_it }.must_raise RuntimeError end If you need to test something on the error object, you can get it from the assertion or expectation like …

Read more