Skip to content

Instantly share code, notes, and snippets.

@bbasata
Created November 5, 2011 01:49
Show Gist options
  • Save bbasata/1340960 to your computer and use it in GitHub Desktop.
Save bbasata/1340960 to your computer and use it in GitHub Desktop.
How DRY & expressive can we get by making the subject a "let"-defined helper?
describe BowlingGame, '#score' do
subject { score }
let(:game) { BowlingGame.new }
let(:score) do
rolls.flatten.each { |roll| game.roll(roll) }
game.score
end
context "when there are no spares or strikes" do
context "all gutter balls" do
let(:rolls) { [0] * 20 }
it { should == 0 }
end
context "a 5, and 19 gutter balls" do
let(:rolls) { [5, [0] * 19] }
it { should == 5 }
end
context "0 through 9, rolled twice each" do
let(:rolls) { [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9] }
it { should == 90 }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment