Sha256: 7dd36f02c4b38546463b0330c83b187652950ba23dbbf93d0d467d8c9b055ebe

Contents?: true

Size: 1.27 KB

Versions: 23

Compression:

Stored size: 1.27 KB

Contents

require 'mechanize/test_case'

class TestMechanizeDirectorySaver < Mechanize::TestCase

  def setup
    super

    @uri = URI 'http://example/relative/tc_relative_links.html'
    @io = StringIO.new 'hello world'
  end

  def test_self_save_to
    in_tmpdir do
      saver = Mechanize::DirectorySaver.save_to 'dir'

      saver.new @uri, nil, @io, 200

      assert File.exist? 'dir/tc_relative_links.html'
      refute File.exist? 'dir/relative'
    end
  end

  def test_self_save_to_cd
    in_tmpdir do
      saver = Mechanize::DirectorySaver.save_to 'dir'

      FileUtils.mkdir 'other'

      Dir.chdir 'other' do
        saver.new @uri, nil, @io, 200
      end

      assert File.exist? 'dir/tc_relative_links.html'
      refute File.exist? 'dir/relative'
    end
  end

  def test_with_decode_filename
    in_tmpdir do
      saver = Mechanize::DirectorySaver.save_to 'dir', :decode_filename => true
      uri = URI 'http://example.com/foo+bar.html'
      saver.new uri, nil, @io, 200

      assert File.exist? 'dir/foo bar.html'
    end
  end

  def test_initialize_no_save_dir
    in_tmpdir do
      e = assert_raises Mechanize::Error do
        Mechanize::DirectorySaver.new @uri, nil, @io, 200
      end

      assert_match %r%no save directory specified%, e.message
    end
  end

end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
mechanize-2.10.0 test/test_mechanize_directory_saver.rb
mechanize-2.9.2 test/test_mechanize_directory_saver.rb
mechanize-2.9.1 test/test_mechanize_directory_saver.rb
mechanize-2.9.0 test/test_mechanize_directory_saver.rb
mechanize-2.8.5 test/test_mechanize_directory_saver.rb
mechanize-2.8.4 test/test_mechanize_directory_saver.rb
mechanize-2.8.3 test/test_mechanize_directory_saver.rb
mechanize-2.8.2 test/test_mechanize_directory_saver.rb
mechanize-2.8.1 test/test_mechanize_directory_saver.rb
mechanize-2.8.0 test/test_mechanize_directory_saver.rb
mechanize-2.7.7 test/test_mechanize_directory_saver.rb
husc-0.2.1 vendor/bundle/gems/mechanize-2.7.6/test/test_mechanize_directory_saver.rb
husc-0.2.0 vendor/bundle/gems/mechanize-2.7.6/test/test_mechanize_directory_saver.rb
husc-0.1.1 vendor/bundle/gems/mechanize-2.7.6/test/test_mechanize_directory_saver.rb
husc-0.1.0 vendor/bundle/gems/mechanize-2.7.6/test/test_mechanize_directory_saver.rb
mechanize-2.7.6 test/test_mechanize_directory_saver.rb
mechanize-2.7.5 test/test_mechanize_directory_saver.rb
mechanize-2.7.4 test/test_mechanize_directory_saver.rb
mechanize-2.7.3 test/test_mechanize_directory_saver.rb
mechanize-2.7.2 test/test_mechanize_directory_saver.rb