Skip to content

Instantly share code, notes, and snippets.

@dkubb
Created December 5, 2011 18:26
Show Gist options
  • Save dkubb/1434673 to your computer and use it in GitHub Desktop.
Save dkubb/1434673 to your computer and use it in GitHub Desktop.
Test Feedzirra w/VCR using an HTTP proxy
#!/usr/bin/env ruby -Ku
# encoding: utf-8
# = Usage
#
# $ rspec test.rb
require 'io/wait'
require 'webrick'
require 'webrick/httpproxy'
require 'rubygems'
require 'active_support/deprecation' # for feedzirra
require 'feedzirra'
require 'rspec'
require 'vcr'
module WEBrick
class VCRProxyServer < HTTPProxyServer
def service(*args)
VCR.use_cassette('proxied') { super(*args) }
end
end
end
VCR.config do |config|
config.stub_with :fakeweb
config.cassette_library_dir = 'cassettes'
config.default_cassette_options = { :record => :new_episodes }
end
describe 'A test with vcr and a transparent proxy' do
IP = '127.0.0.1'
PORT = 9000
before :all do
reader, writer = IO.pipe
@pid = fork do
reader.close
$stderr = writer
server = WEBrick::VCRProxyServer.new(:BindAddress => IP, :Port => PORT)
trap('INT') { server.shutdown }
server.start
end
raise 'VCR Proxy did not start in 10 seconds' unless reader.wait(10)
end
after :all do
Process.kill('INT', @pid)
end
it 'proxies to an RSS feed' do
feed = Feedzirra::Feed.fetch_and_parse(
'http://blog.wildfireapp.com/?feed=rss2',
:proxy_url => IP,
:proxy_port => PORT
)
feed.should be_instance_of(Feedzirra::Parser::RSS)
end
end
@phoet
Copy link

phoet commented Jan 9, 2012

thx, very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment