Skip to content

Instantly share code, notes, and snippets.

@riywo
Created February 22, 2013 10:51
Show Gist options
  • Save riywo/5012566 to your computer and use it in GitHub Desktop.
Save riywo/5012566 to your computer and use it in GitHub Desktop.
webmock spec_helper
require 'rspec'
require 'webmock/rspec'
require 'find'
RSpec.configure do |config|
config.before(:each) do
stub_files(File.expand_path("../mock_files/", __FILE__))
end
end
def stub_files(root_path)
Find.find(root_path) do |path|
next if FileTest.directory?(path)
file = File.new(path)
url = path.gsub(/#{root_path}/, 'http://')
stub_request(:any, url).to_return(body: file, status: 200)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment