Created
March 20, 2012 01:53
-
-
Save alkema/2129918 to your computer and use it in GitHub Desktop.
vcr-page-rankr.rb
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
I expect there to be two cassettes, and there is just one... |
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
source 'https://rubygems.org' | |
gem 'vcr' | |
gem 'fakeweb' | |
gem 'PageRankr' |
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
➜ vcr-test-thing sudo ngrep -q '^GET .* HTTP/1.[01]' | |
T 10.0.2.40:55124 -> 23.21.145.76:80 [AP] | |
GET /data?cli=10&dat=snbamz&url=boingboing.net HTTP/1.1..Host: data.alexa.com..Accept: */*..Accept-Encoding: deflate, gzip..User-Agent: Page Rankr.... | |
^C% |
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
➜ vcr-page-rankr bundle exec ruby vcr-page-rankr.rb | |
Loaded suite vcr-page-rankr | |
Started | |
.. | |
Finished in 0.346584 seconds. | |
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips | |
Test run options: --seed 12708 | |
➜ vcr-page-rankr ls fixtures/vcr_cassettes | |
synopsis.yml |
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 'rubygems' | |
require 'test/unit' | |
require 'vcr' | |
require 'page_rankr' | |
require 'pp' | |
VCR.configure do |c| | |
c.cassette_library_dir = 'fixtures/vcr_cassettes' | |
c.hook_into :fakeweb | |
end | |
class VCRTest < Test::Unit::TestCase | |
def test_page_rank_boing_boing | |
VCR.use_cassette('boing-boing') do | |
response = PageRankr.ranks('http://boingboing.net', :alexa_global) | |
assert_equal 2316, response[:alexa_global] | |
end | |
end | |
def test_example_dot_com | |
VCR.use_cassette('synopsis') do | |
response = Net::HTTP.get_response(URI('http://www.iana.org/domains/example/')) | |
assert_match /Example Domains/, response.body | |
end | |
end | |
end |
That works great. Thanks Myron.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PageRankr uses Typhoeus, not Net::HTTP:
https://github.com/blatyo/page_rankr/blob/v3.1.1/lib/page_rankr/tracker.rb#L28
FakeWeb only supports Net::HTTP. To record requests made by page rankr, configure VCR to have it hook into Typhoeus:
Alternately, you could just use
:webmock
as it supports both Net::HTTP and Typhoeus (plus a bunch of others).