Falling back to original method in rspec-mocks
# 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