require 'test/unit'
require_relative 'game' 

class GameTest < Test::Unit::TestCase

  def setup
    @game = Game.new
  end

  def roll_many(n, pins)
    n.times do
      @game.roll(pins)
    end
  end

  def test_gutter_game
    setup
    roll_many(20, 0)
    assert_equal 0, @game.score
  end

  def test_all_ones
    setup
    roll_many(20, 1)
    assert_equal 20, @game.score
  end
end

require 'test/unit'
require_relative 'game' 

class GameTest < Test::Unit::TestCase

  def test_gutter_game
    game = Game.new
    20.times do
      game.roll(0)
    end
    assert_equal 0, game.score
  end

  def test_all_ones
    game = Game.new
    20.times do
      game.roll(1)
    end
    assert_equal 20, game.score
  end
end

--- 
+++ 
@@ -3,19 +3,25 @@
 
 class GameTest < Test::Unit::TestCase
 
+  def setup
+    @game = Game.new
+  end
+
+  def roll_many(n, pins)
+    n.times do
+      @game.roll(pins)
+    end
+  end
+
   def test_gutter_game
-    game = Game.new
-    20.times do
-      game.roll(0)
-    end
-    assert_equal 0, game.score
+    setup
+    roll_many(20, 0)
+    assert_equal 0, @game.score
   end
 
   def test_all_ones
-    game = Game.new
-    20.times do
-      game.roll(1)
-    end
-    assert_equal 20, game.score
+    setup
+    roll_many(20, 1)
+    assert_equal 20, @game.score
   end
 end
Refactor test to extract duplicate code
