Sha256: 4390c8ba707dee3b2643f720f5d7e6c24e109b000c5e870a5cb2cee391c0c065

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

require 'mechanize/test_case'

class TestMechanizeFile < Mechanize::TestCase

  def setup
    super

    @parser = Mechanize::File
  end

  def test_save
    uri = URI 'http://example/name.html'
    page = Mechanize::File.new uri, nil, '0123456789'

    Dir.mktmpdir do |dir|
      Dir.chdir dir do
        page.save 'test.html'

        assert File.exist? 'test.html'
        assert_equal '0123456789', File.read('test.html')
        
        page.save 'test.html'
        
        assert File.exist? 'test.html.1'
        assert_equal '0123456789', File.read('test.html.1')
        
        page.save 'test.html'
        
        assert File.exist? 'test.html.2'
        assert_equal '0123456789', File.read('test.html.2')
      end
    end
  end

  def test_save_default
    uri = URI 'http://example/test.html'
    page = Mechanize::File.new uri, nil, ''

    Dir.mktmpdir do |dir|
      Dir.chdir dir do
        page.save

        assert File.exist? 'test.html'

        page.save

        assert File.exist? 'test.html.1'

        page.save

        assert File.exist? 'test.html.2'
      end
    end
  end

  def test_save_default_dots
    uri = URI 'http://localhost/../test.html'
    page = Mechanize::File.new uri, nil, ''

    Dir.mktmpdir do |dir|
      Dir.chdir dir do
        page.save
        assert File.exist? 'test.html'

        page.save
        assert File.exist? 'test.html.1'
      end
    end
  end

  def test_filename
    uri = URI 'http://localhost/test.html'
    page = Mechanize::File.new uri, nil, ''

    assert_equal "test.html", page.filename
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mechanize-2.5.1 test/test_mechanize_file.rb
mechanize-2.5 test/test_mechanize_file.rb