File: test_registering_with_io.rb

package info (click to toggle)
ruby-fakeweb 1.3.0%2Bgit20131202.48208f9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 364 kB
  • ctags: 435
  • sloc: ruby: 1,997; sh: 24; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 2,032 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'test_helper'

class TestRegisteringWithIO < Test::Unit::TestCase

  def _test_registering_a_file_handle_without_transfer_encoding
    file = File.new(fixture_path("google_response_without_transfer_encoding"))
    FakeWeb.register_uri(:get, "http://google.com", :response => file)
    response = Net::HTTP.start("google.com") { |query| query.get('/') }
    assert response.body.include?("<title>Google</title>")
  end

  def _test_registering_a_file_handle_with_transfer_encoding
    file = File.new(fixture_path("google_response_with_transfer_encoding"))
    FakeWeb.register_uri(:get, "http://google.com", :response => file)
    response = Net::HTTP.start("google.com") { |query| query.get('/') }
    assert response.body.include?("<title>Google</title>")
  end

  def _test_registering_a_file_handle_from_curl
    file = File.new(fixture_path("google_response_from_curl"))
    FakeWeb.register_uri(:get, "http://google.com", :response => file)
    response = Net::HTTP.start("google.com") { |query| query.get('/') }
    assert response.body.include?("<title>Google</title>")
  end

  def _test_registering_a_stringio
    stringio = StringIO.new(File.read(fixture_path("google_response_from_curl")))
    FakeWeb.register_uri(:get, "http://google.com", :response => stringio)
    response = Net::HTTP.start("google.com") { |query| query.get('/') }
    assert response.body.include?("<title>Google</title>")
  end

  def _test_creating_net_buffered_io_directly_with_an_unsupported_underlying_object
    # It's not possible to exercise this code path through an end-user API because
    # FakeWeb::Responder performs an equivalent check on the object before passing
    # it on to Net::BufferedIO. So this is just an internal sanity check.
    string = ""
    Net::BufferedIO.new(string)

    stringio = StringIO.new(File.read(fixture_path("google_response_from_curl")))
    Net::BufferedIO.new(stringio)

    unsupported = Time.now
    assert_raises ArgumentError do
      Net::BufferedIO.new(unsupported)
    end
  end
end