Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
mock and stub in Rspec
2 Posts
mock and stub in Rspec

Hi , Am new to Rspec.Can anybody tell the difference between mock and stub. In which scenarios we use these

Person
Forum Rating: 50
Sign In To Rate Post

Hi Lucky,

Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'.

Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

just go through following link.

http://rspec.rubyforge.org/rspec/1.1.12/classes/Spec/Mocks.html

http://www.martinfowler.com/articles/mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs

I hope this will help you.

Cheerrsss!! -Ganesh K

Person
Jruby, Ruby, Rails Programmer
Sign In To Rate Post
2 Posts
Login to add your message