Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created July 22, 2011 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/1099986 to your computer and use it in GitHub Desktop.
Save kyanny/1099986 to your computer and use it in GitHub Desktop.
mocha example
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