net-httpstub - a stub of Net::HTTP.

by momotaro <[email protected]>

Description

net-httpstub is a stub of Net::HTTP.

This changes the operation of the Net::HTTP, and returns the response originally specified.

Installation

Archive Installation

rake install

Gem Installation

gem install nethttpstub

Features/Problems

This depends on internal processing of Net::HTTP. Therefore, it is likely not to move excluding the following environment.

  • ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-mswin32]

Synopsis

class SampleTest < Test::Unit:TestCase
  def test_get_request
    Net::HTTP.push "response body"
      Net::HTTP.start('www.example.com') do |http|
      res = http.get('/')
      assert_instance_of Net::HTTPOK, res
      assert_equal "200", res.code
      assert_equal "response body", res.body
    end
  end
end

The HTTP response header can be specified.

class SampleTest < Test::Unit:TestCase
  def test_get_request
    Net::HTTP.push <<-EOF
HTTP/1.1 404 Not Found
    EOF
      Net::HTTP.start('www.example.com') do |http|
      res = http.get('/')
      assert_instance_of Net::HTTPNotFound, res
      assert_equal "404", res.code
      assert_equal "", res.body
    end
  end
end
Author

momotaro <[email protected]>

Copyright

Copyright © 2000-2009 momotaro

License

Ruby’s