rspec 2.14.1 から rspec 3.0.0 に対応したときに正規表現で一括で置換して大体何とかなった部分のメモ
下記以外では、be_true -> be_truthy, be_false -> be_falseyとas_null_objectを削除するくらいしかしてないので割愛
stubの置き換え
before
target.stub(:method).and_return(result)
after
allow(target).to receive(:method).and_return(result)
置換正規表現
^(\s*)(.*)\.stub(.*)
=>$1allow($2).to receive$3
should_receive, should_not_receiveの置き換え
before
target.should_receive(:method).and_return(result)
target.should_not_receive(:method)
after
expect(target).to receive(:method).and_return(result)
expect(target).not_to receive(:method)
置換正規表現
^(\s*)(.*)\.should_receive(.*)
=> $1expect($2).to receive$3
^(\s*)(.*)\.should_not_receive(.*)
=> $1expect($2).not_to receive$3
should, should_notの置き換え
before
target.should == expected
target.should_not == not_expected
target.should be_true
target.should_not be_nil
after
expect(target).to eq(expected)
expect(target).not_to eq(expected)
expect(target).to be_true
expect(target).to be_nil
置換正規表現
^(\s*)(.*)\.should\s==\s(.*)
=> $1expect($2).to eq($3)
^(\s*)(.*)\.should_not\s==\s(.*)
=> $1expect($2).not_to eq($3)
^(\s*)(.*)\.should\s(.*)
=> $1expect($2).to $3
^(\s*)(.*)\.should_not\s==\s(.*)
=> $1expect($2).not_to eq($3)
えーっと。。。。。
before
target.is_a?(Array).should be_true
after
expect(target).to be_a(Array)
置換正規表現
^(\s*)(.*)\.is_a\?\((.*)\).should be_true
=> $1expect($2).to be_a($3)
追記
こんな感じでやったよーと伝えたら、後輩に「ご存知かも知れませんが」と教えてもらった。
Transpec
でもまあ、変なコードあったり、これテストになってないじゃん的なコードがあったりで
見直すいい機会ではあったので、手動でやるのもいいと思う。