Created
February 22, 2013 10:51
-
-
Save riywo/5012566 to your computer and use it in GitHub Desktop.
webmock spec_helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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