I’ve seen it used many times, and never really stopped to question it. Now it’s got me wondering if there is a difference between stub and stub!
Is there? Or is it historical? Does stub! mean it stubs it once? and returns back to the normal method call?
In both version 2, and v1.3.2, they are simply aliases of each other. In v1.3.2
stubis an alias ofstub!https://github.com/dchelimsky/rspec/blob/v1.3.2/lib/spec/mocks/methods.rb#L12
While in v2.6 of rspec 2,
stub!is an alias ofstubhttps://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/methods.rb#L12
However in v1.1.4,
stubis an alias formock, andstub!is a separate method. From the docs, it would seem thatstub!in this early version was used to add methods to existing objects, creating a “partial mock”.The explanation:
https://github.com/dchelimsky/rspec/blob/1.1.4/lib/spec/mocks.rb#L43
The definitions:
https://github.com/dchelimsky/rspec/blob/1.1.4/lib/spec/mocks/spec_methods.rb#L27
https://github.com/dchelimsky/rspec/blob/1.1.4/lib/spec/mocks/methods.rb#L12