Skip to content

Instantly share code, notes, and snippets.

@takkanm
Created April 22, 2013 01:46
Show Gist options
  • Save takkanm/5431923 to your computer and use it in GitHub Desktop.
Save takkanm/5431923 to your computer and use it in GitHub Desktop.
#検証したいUserクラス
class User < ActiveRecord::Base
belongs_to :room
def wait(room)
room.wait
self.room = room
end
end
describe User do
let(:user) { User.new }
describe '#wait' do
#beforeで呼ぶとshould_receiveが検証できず困る
#before { subject.wait(room) }
let(:room){ mock_model(Room) }
let(:wait_action) { user.wait(room) }
it "引数のroomのwaitが呼ばれること" do
room.should_receive(:wait)
user.wait(room)
end
it 'roomがセットされること' do
expect {
user.wait(room)
}.to chage(user, :room).to(room)
end
describe 'room' do
before { user.wait }
subject { user.room }
it { should eq room }
end
#afterで呼ぶとsubject.roomが設定されているかがわからず困る
#after { subject.wait(room) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment