Created
December 5, 2011 18:26
-
-
Save dkubb/1434673 to your computer and use it in GitHub Desktop.
Test Feedzirra w/VCR using an HTTP proxy
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
cassettes |
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx, very helpful!