Created
July 22, 2011 17:57
-
-
Save kyanny/1099986 to your computer and use it in GitHub Desktop.
mocha example
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 'net/http' | |
module LWP | |
class Simple | |
def self.getprint(url) | |
uri = URI(url) | |
Net::HTTP.start(uri.host, uri.port){ |http| | |
http.get(uri.path).body | |
} | |
end | |
end | |
end | |
if $0 == __FILE__ | |
eval DATA.read | |
end | |
__END__ | |
require 'test/unit' | |
require 'mocha' | |
class TestLWPSimple < Test::Unit::TestCase | |
def test_valid_path | |
Net::HTTP.any_instance.expects(:get).with{ |path| | |
path == '/a666666/about' | |
}.returns(stub('response', :body)) | |
LWP::Simple.getprint("http://d.hatena.ne.jp/a666666/about") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment