Skip to content

Instantly share code, notes, and snippets.

@madx
Last active December 20, 2015 06:39
Show Gist options
  • Save madx/6087634 to your computer and use it in GitHub Desktop.
Save madx/6087634 to your computer and use it in GitHub Desktop.
Parameterized subject blocks for MiniTest
describe DiceRoller do
describe "initialization" do
subject { ->(*dice) { DiceRoller.new(*dice) } }
it "accepts a single die" do
die = Die.new(6)
subject[die].dice.count.must_equal 1
end
it "accepts multiple dice" do
die1, die2 = Array.new(2) { Die.new(6) }
subject[die1, die2].dice.count.must_equal 2
end
end
end

This is an example of writing parameterized subject blocks in MiniTest.

It also works with let declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment