Skip to content

Commit

Permalink
Copy the examples to the README, since a few rdoc renderers don't see…
Browse files Browse the repository at this point in the history
…m to handle the :include
  • Loading branch information
chrisk committed Nov 2, 2008
1 parent 4bcc868 commit 02e3a0d
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
= Name
= FakeWeb

FakeWeb - Helper for Faking Web Requests
A Helper for Faking Web Requests

= Synopsis
= Examples

require 'test/unit'
require 'fake_web'
require 'open-uri'

class FakeWebExampleTest < Test::Unit::TestCase
def test_request
FakeWeb.register_uri('http://example.com/test_me', :string => "Hello World!")
content = Net::HTTP.get(URI.parse('http://example.com/test_me'))
assert_equal "Hello World!", content
end

def test_request_with_response
FakeWeb.register_uri('http://www.google.com/', :response => `curl -is http://www.google.com/`)
Net::HTTP.start('www.google.com') do |req|
response = req.get('/')
if response.code == 200
assert_equal "OK", response.message
assert response.body.include?('<title>Google')
elsif response.code == 302
# Google redirects foreign sites to ccTLDs.
assert_equal "Found", response.message
assert response.body.include?('The document has moved')
end
end
end

def test_request_with_custom_status
FakeWeb.register_uri('http://example.com/', :string => "Nothing to be found 'round here",
:status => ['404', 'Not Found'])
Net::HTTP.start('example.com') do |req|
response = req.get('/')
assert_equal "404", response.code
assert_equal "Not Found", response.message
assert_equal "Nothing to be found 'round here", response.body
end
end

def test_open_uri
FakeWeb.register_uri('http://example.com/', :string => "Hello, World!")
content = open('http://example.com/').string
assert_equal "Hello, World!", content
end
end

:include:test/test_examples.rb

= Description

Expand Down

0 comments on commit 02e3a0d

Please sign in to comment.