Skip to content

Instantly share code, notes, and snippets.

@codenamev
Created October 1, 2014 14:50
Show Gist options
  • Save codenamev/258fdcbf0d6ddb07ac83 to your computer and use it in GitHub Desktop.
Save codenamev/258fdcbf0d6ddb07ac83 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment