Shortcut for creating an instance of Spec::Mocks::Mock.
name is used for failure reporting, so you should use the role that the mock is playing in the example.
# File lib/spec/mocks/spec_methods.rb, line 23 def mock(*args) Spec::Mocks::Mock.new(*args) end
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