Skip to content

Instantly share code, notes, and snippets.

@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active December 10, 2022 13:34
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@panthomakos
panthomakos / benchmark.rb
Created March 12, 2012 06:16
Rails ActiveSupport::Autoload Benchmark
# Rails 3.2 @ d5d241cb2c696f13e2c16efca0d24565a6e1c0a5
require 'active_support/dependencies/autoload'
require 'benchmark'
GC.disable
FILES = (1..1_000_000).map do |file|
["Base#{file}".to_sym, "base/#{file}"]
end