codenamev
10/1/2014 - 2:50 PM

Falling back to original method in rspec-mocks Credit: https://stackoverflow.com/questions/12536256/falling-back-to-original-method-in-rspe

# spec/support/rspec_stub_helpers.rb
#
# include in spec_helper.rb like so:
#   Rspec.configure do |config|
#     config.include RspecStubHelpers
#   end
#
# usage example:
#   stub_with_fallback(File, :exist?).with(/txt/).and_return(true)
module RspecStubHelpers
  def stub_with_fallback(obj, method)
    original_method = obj.method(method)
    obj.stub(method).with(anything()) { |*args| original_method.call(*args) }
    return obj.stub(method)
  end
end