transpec古いRSpecをRSpec3の記法に修正[RubyGem]


transpec」は古い記法で記述されたRSpecをRSpec3に対応した記法に修正してくれるRubyGemです。古いプロジェクトのRSpecをいじる場合にはぜひ活用してください。

🚜

変更前

describe Account do
subject(:account) { Account.new(logger) }
let(:logger) { mock('logger') }
describe '#balance' do
context 'initially' do
it 'is zero' do
account.balance.should == 0
end
end
end
describe '#close' do
it 'logs an account closed message' do
logger.should_receive(:account_closed).with(account)
account.close
end
end
describe '#renew' do
context 'when the account is not closed' do
before do
account.stub(:closed?).and_return(false)
end
it 'does not raise error' do
lambda { account.renew }.should_not raise_error(Account::RenewalError)
end
end
end
end

変更後

describe Account do
subject(:account) { Account.new(logger) }
let(:logger) { double('logger') }
describe '#balance' do
context 'initially' do
it 'is zero' do
# should => expect に修正
expect(account.balance).to eq(0)
end
end
end
describe '#close' do
it 'logs an account closed message' do
expect(logger).to receive(:account_closed).with(account)
account.close
end
end
describe '#renew' do
context 'when the account is not closed' do
before do
# Stubの書き方が修正
allow(account).to receive(:closed?).and_return(false)
end
it 'does not raise error' do
# エラーチェックの記法が修正
expect { account.renew }.not_to raise_error
end
end
end
end

👽 インストール手順

対象のプロジェクトフォルダで次のコマンドを実行してインストール。

gem install transpec

🎃 実行手順

あとはプロジェクトフォルダの直下で次のコマンドを実行するだけ。

transpec

📚 おすすめの書籍