Sha256: 398dd602b4610172952cfd3519017d78d9d682ab0d716681cd361e7eacdb5930

Contents?: true

Size: 945 Bytes

Versions: 10

Compression:

Stored size: 945 Bytes

Contents

require 'mechanize/test_case'

class TestMechanizeFileConnection < Mechanize::TestCase

  def test_request
    file_path = File.expand_path(__FILE__)
    uri = URI.parse "file://#{file_path}"
    conn = Mechanize::FileConnection.new

    body = ''

    conn.request uri, nil do |response|
      assert_equal(file_path, response.file_path)
      response.read_body do |part|
        body << part
      end
    end

    assert_equal File.read(__FILE__), body.gsub(/\r\n/, "\n")
  end

  def test_request_on_uri_with_windows_drive
    uri_string = "file://C:/path/to/file.html"
    expected_file_path = "C:/path/to/file.html"

    uri = URI.parse(uri_string)
    conn = Mechanize::FileConnection.new

    called = false
    yielded_file_path = nil
    conn.request(uri, nil) do |response|
      called = true
      yielded_file_path = response.file_path
    end

    assert(called)
    assert_equal(expected_file_path, yielded_file_path)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mechanize-2.10.0 test/test_mechanize_file_connection.rb
mechanize-2.9.2 test/test_mechanize_file_connection.rb
mechanize-2.9.1 test/test_mechanize_file_connection.rb
mechanize-2.9.0 test/test_mechanize_file_connection.rb
mechanize-2.8.5 test/test_mechanize_file_connection.rb
mechanize-2.8.4 test/test_mechanize_file_connection.rb
mechanize-2.8.3 test/test_mechanize_file_connection.rb
mechanize-2.8.2 test/test_mechanize_file_connection.rb
mechanize-2.8.1 test/test_mechanize_file_connection.rb
mechanize-2.8.0 test/test_mechanize_file_connection.rb