メモ:rspecで変更が無いことをテストする
自分用メモ
expect{hoge}.not_to change{fuga}
で変更が無いことをテストできる
Rank.get_rank_id では、パラメータによって次のランクが返却されるイメージ User#calc_rank!では、Rank.get_rank_id を呼び出し、その結果をDBに保存するイメージ
require 'spec_helper' describe User do describe '#calc_rank!' do let!(:user) { FactoryGirl.create(:user, rank_id: 2) } it do Rank.stub(:get_rank_id).and_return(2) expect{user.calc_rank!}.not_to change{User.find(user.id).rank_id} end end end
rbenvをインストール
環境:Mac OS X 10.8.4
rbenvのインストール
基本、下記の通り。
https://github.com/sstephenson/rbenv
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
その後、書いてある通り、ruby-buildを入れる。
https://github.com/sstephenson/ruby-build
ちなみに、入ってないと、rbenv installってやっても
rbenv: no such command `install'
てエラーが出る。
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
これで、下記のコマンドが実行できる
rbenv install -l
2.0.0-p247 ってのがあったので、それをインストールする。
rbenv install 2.0.0-p247 rbenv rehash rbenv global 2.0.0-p247
下記も参考にしました。
http://rochefort.hatenablog.com/entry/20121015/p1
http://qiita.com/sifue/items/b7d252b18ebbae636fa9