Sha256: 3e77f73c34d8b2309caf145f2cb12455b0c4d1e9cf56bb47b96580249131a2cf

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 KB

Contents

require 'mechanize/test_case'

class TestMechanizeDownload < Mechanize::TestCase

  def setup
    super

    @parser = Mechanize::Download
  end

  def test_body
    uri = URI.parse 'http://example/foo.html'
    body_io = StringIO.new '0123456789'

    download = @parser.new uri, nil, body_io

    assert_equal '0123456789', download.body
    assert_equal 0, download.body_io.pos
  end

  def test_save_string_io
    uri = URI.parse 'http://example/foo.html'
    body_io = StringIO.new '0123456789'

    download = @parser.new uri, nil, body_io

    in_tmpdir do
      download.save

      assert File.exist? 'foo.html'
    end
  end

  def test_save_tempfile
    uri = URI.parse 'http://example/foo.html'
    Tempfile.open __name__ do |body_io|
      body_io.unlink
      body_io.write '0123456789'

      body_io.flush
      body_io.rewind

      download = @parser.new uri, nil, body_io

      in_tmpdir do
        download.save

        assert File.exist? 'foo.html'
      end
    end
  end

  def test_filename
    uri = URI.parse 'http://example/foo.html'
    body_io = StringIO.new '0123456789'

    download = @parser.new uri, nil, body_io

    assert_equal "foo.html", download.filename
  end

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
mechanize-2.6.0 test/test_mechanize_download.rb
mechanize-2.5.1 test/test_mechanize_download.rb
mechanize-2.5 test/test_mechanize_download.rb
mechanize-2.4 test/test_mechanize_download.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/mechanize-2.3/test/test_mechanize_download.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/mechanize-2.3/test/test_mechanize_download.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/mechanize-2.3/test/test_mechanize_download.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/mechanize-2.3/test/test_mechanize_download.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/mechanize-2.3/test/test_mechanize_download.rb
mechanize-2.3 test/test_mechanize_download.rb