最初からMediatorにする実験(奇跡的にテストが通った状態)

・直接 Player.new しないようにして Mediator.new から player_at で取得した player を使うようにした
・playerからmediator.boardを参照している部分や、sandbox_forがスマートに書けるか確認
・かけるならリファクタしてmasterへ
orgモードの表記まで置換していた→修正
テストのリファクタリング(letの撲滅等)
log_stock の場所変更
moved_point は使ってないかつ扱いが微妙なので一旦削除
CPUが駒の価値を把握
持駒表記相互変換部分をUtilsに移動
平手・香車落ちなど先手後手それぞれに設定できるようにした
Marshal.dump時にMatchDataの呪縛で死ぬのを再現するテスト追加
Marshal.dump時にMatchDataの呪縛で死ぬ→修正
ruby 2.0.0 対応
rspecに依存しないようにした
rspec → minitest に移行
Revert "rspec → minitest に移行"

This reverts commit eff975cd402766b30d02fa149e2fac06127ce0bc.
specでtest_*があるとminitestの場合に実行されるので
frame → mediator リネーム
テスト用のメソッドはspec_helperで定義するようにした

diff --git a/lib/bushido/mediator.rb b/lib/bushido/mediator.rb
index 49a71ff..c9fef23 100644
--- a/lib/bushido/mediator.rb
+++ b/lib/bushido/mediator.rb
@@ -188,27 +188,6 @@ module Bushido
       attr_reader :counter, :simple_kif_logs, :human_kif_logs, :point_logs
     end

-    module ClassMethods
-      def testcase3(params = {})
-        params = {
-          :nplayers => 2,
-        }.merge(params)
-        mediator = start
-        mediator.players = mediator.players.first(params[:nplayers])
-        (params[:init] || []).each_with_index{|init, index|mediator.current_player(index).initial_soldiers(init)}
-        mediator.execute(params[:exec])
-        mediator
-      end
-      # def testcase4(params = {})
-      #   params = {
-      #   }.merge(params)
-      #   mediator = new
-      #   (params[:init] || []).each_with_index{|init, index|mediator.current_player(index).initial_soldiers(init, :from_piece => false)}
-      #   mediator.execute(params[:exec])
-      #   mediator
-      # end
-    end
-
     def initialize(*)
       super
       @point_logs = []
@@ -244,6 +223,23 @@ module Bushido
     end
   end

+  module MediatorTestHelper
+    extend ActiveSupport::Concern
+
+    module ClassMethods
+      def test(params = {})
+        params = {
+          :nplayers => 2,
+        }.merge(params)
+        mediator = start
+        mediator.players = mediator.players.first(params[:nplayers])
+        (params[:init] || []).each_with_index{|init, index|mediator.current_player(index).initial_soldiers(init)}
+        mediator.execute(params[:exec])
+        mediator
+      end
+    end
+  end
+
   class Mediator
     include PlayerSelector
     include Boardable
diff --git a/spec/mediator_spec.rb b/spec/mediator_spec.rb
index 53c0d61..a115004 100644
--- a/spec/mediator_spec.rb
+++ b/spec/mediator_spec.rb
@@ -83,7 +83,7 @@ EOT
     end

     it "状態の復元" do
-      mediator = Mediator.testcase3(:init => [["１五玉", "１四歩"], ["１一玉", "１二歩"]], :exec => ["１三歩成", "１三歩"])
+      mediator = Mediator.test(:init => [["１五玉", "１四歩"], ["１一玉", "１二歩"]], :exec => ["１三歩成", "１三歩"])
       dup = mediator.deep_dup
       mediator.counter.should            == dup.counter
       mediator.simple_kif_logs.should    == dup.simple_kif_logs
@@ -99,7 +99,7 @@ EOT
     end

     it "相手が前回打った位置を復元するので同歩ができる" do
-      mediator = Mediator.testcase3(:init => ["１五歩", "１三歩"], :exec => "１四歩")
+      mediator = Mediator.test(:init => ["１五歩", "１三歩"], :exec => "１四歩")
       mediator = Marshal.load(Marshal.dump(mediator))
       mediator.execute("同歩")
       mediator.prev_player.parsed_info.last_kif_pair.should == ["1四歩(13)", "同歩"]
@@ -120,7 +120,7 @@ EOT
     end

     it "フレームのサンドボックス実行(重要)" do
-      mediator = Mediator.testcase3(:init => ["１二歩"])
+      mediator = Mediator.test(:init => ["１二歩"])
       mediator.player_at(:black).to_s_soldiers.should == "1二歩"
       mediator.player_at(:black).board.to_s_soldiers.should == "1二歩"
       mediator.sandbox_for { mediator.player_at(:black).execute("２二歩打") }
@@ -129,10 +129,13 @@ EOT
     end

     it "「打」にすると Marshal.dump できない件→修正" do
-      mediator = Mediator.testcase3(:exec => "１二歩打")
+      mediator = Mediator.test(:exec => "１二歩打")
       mediator.deep_dup
     end

+    # it "" do
+    # end
+
     # it "盤面初期設定" do
     #   def board_reset_test(value)
     #     mediator = Mediator.new
diff --git a/spec/player_spec.rb b/spec/player_spec.rb
index 5ab43e7..8ff81c0 100644
--- a/spec/player_spec.rb
+++ b/spec/player_spec.rb
@@ -162,7 +162,7 @@ EOT
       describe "取る" do
         describe "取れる" do
           it "座標指定で" do
-            mediator = Mediator.testcase3(:init => [["１五玉", "１四歩"], ["１一玉", "１二歩"]], :exec => ["１三歩成", "１三歩"])
+            mediator = Mediator.test(:init => [["１五玉", "１四歩"], ["１一玉", "１二歩"]], :exec => ["１三歩成", "１三歩"])
             mediator.prev_player.last_piece.name.should == "歩"
             mediator.prev_player.to_s_pieces.should == "歩九 角 飛 香二 桂二 銀二 金二"
             mediator.prev_player.to_s_soldiers.should == "1一玉 1三歩"
@@ -170,7 +170,7 @@ EOT
             mediator.current_player.to_s_soldiers.should == "1五玉"
           end
           it "同歩で取る" do
-            mediator = Mediator.testcase3(:init => ["２五歩", "２三歩"], :exec => ["２四歩", "同歩"])
+            mediator = Mediator.test(:init => ["２五歩", "２三歩"], :exec => ["２四歩", "同歩"])
             mediator.prev_player.last_piece.name.should == "歩"
             mediator.prev_player.to_s_pieces.should == "歩九 角 飛 香二 桂二 銀二 金二 玉"
             mediator.prev_player.to_s_soldiers.should == "2四歩"
@@ -178,17 +178,17 @@ EOT
             mediator.current_player.to_s_soldiers.should == ""
           end
           it "２五の地点にたたみ掛けるときki2形式で同が連続すること" do
-            mediator = Mediator.testcase3(:init => [["２七歩", "２八飛"], ["２三歩", "２二飛"]], :exec => ["２六歩", "２四歩", "２五歩", "同歩", "同飛", "同飛"])
+            mediator = Mediator.test(:init => [["２七歩", "２八飛"], ["２三歩", "２二飛"]], :exec => ["２六歩", "２四歩", "２五歩", "同歩", "同飛", "同飛"])
             mediator.human_kif_logs.should == ["▲2六歩", "▽2四歩", "▲2五歩", "▽同歩", "▲同飛", "▽同飛"]
           end
         end

         describe "取れない" do
           it "初手に同歩" do
-            expect { Mediator.testcase3(:exec => "同歩") }.to raise_error(BeforePointNotFound, /同に対する座標が不明です/)
+            expect { Mediator.test(:exec => "同歩") }.to raise_error(BeforePointNotFound, /同に対する座標が不明です/)
           end
           it "一人で同を使った場合、その座標は自分の駒があるため、その上に移動することはできず、そこに移動できる駒がないエラーになる" do
-            expect { Mediator.testcase3(:nplayers => 1, :init => ["１九香", "１八香"], :exec => ["１五香", "同香"]) }.to raise_error(MovableSoldierNotFound)
+            expect { Mediator.test(:nplayers => 1, :init => ["１九香", "１八香"], :exec => ["１五香", "同香"]) }.to raise_error(MovableSoldierNotFound)
           end
         end
       end
@@ -228,7 +228,7 @@ EOT
           expect { player_test2(:init => "５五飛", :exec => "５五角打") }.to raise_error(PieceAlredyExist)
         end
         it "相手の駒の上に" do
-          expect { Mediator.testcase3(:exec => ["５五飛打", "５五角打"]) }.to raise_error(PieceAlredyExist)
+          expect { Mediator.test(:exec => ["５五飛打", "５五角打"]) }.to raise_error(PieceAlredyExist)
         end
         it "卍という駒がないので" do
           expect { player_test2(:exec => "５五卍打") }.to raise_error(SyntaxError)
@@ -387,7 +387,7 @@ EOT
       end

       it "同" do
-        Mediator.testcase3(:init => ["２五歩", "２三歩"], :exec => ["２四歩", "同歩"]).prev_player.parsed_info.last_kif_pair.should == ["2四歩(23)", "同歩"]
+        Mediator.test(:init => ["２五歩", "２三歩"], :exec => ["２四歩", "同歩"]).prev_player.parsed_info.last_kif_pair.should == ["2四歩(23)", "同歩"]
       end

       it "直と不成が重なるとき「不成」と「直」の方が先にくる" do
@@ -558,7 +558,7 @@ EOT
     # end

     # it "フレームのサンドボックス実行(FIXME:もっと小さなテストにする)" do
-    #   mediator = Mediator.testcase3(:init => ["１二歩"])
+    #   mediator = Mediator.test(:init => ["１二歩"])
     #   mediator.player_at(:black).to_s_soldiers.should == "1二歩"
     #   # mediator.player_at(:black).to_s_pieces.should == "歩八 角 飛 香二 桂二 銀二 金二 玉"
     #   # mediator.player_at(:black).board.to_s_soldiers.should == "1二歩"
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 3028de4..a6a45a8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -3,6 +3,10 @@ require "bundler/setup"
 require "tapp"
 require "bushido"

+module Bushido
+  Mediator.send(:include, MediatorTestHelper)
+end
+
 RSpec.configure do |config|
   config.before(:each) do
   end
勢いだけで作った囲いをチェックする処理追加(要リファクタ)