Skip to content

Instantly share code, notes, and snippets.

@megatux
Created January 30, 2012 20:13
Show Gist options
  • Save megatux/1706396 to your computer and use it in GitHub Desktop.
Save megatux/1706396 to your computer and use it in GitHub Desktop.
mock web access (http open) with webmock
#In Gemfile:
group :test do
gem 'webmock'
end
#In test class:
def setup
mock_file = Rails.root.join("test", "fixtures", "some_saved_website.html")
stub_request(:get, /http:\/\/www.some_web.com\/*/).
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
to_return(:status => 200, :body => File.new(mock_file), :headers => {})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment