When I started mocking objects using RSpec Mocks, I never thought I’d end up using them outside of actual unit testing.
But this week, while working on a new internal gem to build out how we register documents, I found myself wanting to get some early acceptance testing from the end users. To do this I build a throw-away Sinatra application that took some user input. I then used this input the mock the return values for one of the methods in my actual class instance. This allowed my users to test all sorts of different scenarios, even ones I may have missed in my unit tests.
To use this yourself, you just need to include the following line to use the RSpec Mock standalone in your application:
Then just use mock your instance as before:
#stub method . . .
obj = MyObject.new
obj.stub(:method_name => params[:key]) #user-entered values returned
#. . . and call
You can find more details here.