method
mock

Register or
log in
to add new notes.
hosiawak -
June 4, 2009

2 thanks
A typical usage for a mock
You want to use a mock when you’re testing a behaviour of one of your methods that interacts with some outside world service (eg. an FTP server).
it "should login to ftp server" do ftp = mock('Ftp server', :null_object => true) Net::FTP.should_receive(:new).and_return(ftp) ftp.should_receive(:login).with('username', 'password') some_obj.connect end def connect session = Net::FTP.new('server.com') session.login('username', 'password') session.close end