Sha256: 9058e80619cf6f3dd750c02e8ffdd05e6273a2e57f29ddd8f9aabd71f54664a0

Contents?: true

Size: 1.88 KB

Versions: 16

Compression:

Stored size: 1.88 KB

Contents

# -*- coding: utf-8 -*-

require 'test_helper'
require 'review/makerhelper'
require 'tmpdir'
require 'fileutils'


class MakerHelperTest < Test::Unit::TestCase
  include ReVIEW

  def setup
    @tmpdir1 = Dir.mktmpdir
    @tmpdir2 = Dir.mktmpdir
  end

  def teardown
    FileUtils.rm_rf @tmpdir1
    FileUtils.rm_rf @tmpdir2
  end

  def test_copy_images_to_dir
    types = %w{png gif jpg jpeg svg pdf eps}
    types.each do |type|
      touch_file("#{@tmpdir1}/foo.#{type}")
    end
    FileUtils.mkdir("#{@tmpdir1}/subdir")
    touch_file("#{@tmpdir1}/subdir/foo.png")

    image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2)

    types.each do |type|
      assert File.exist?("#{@tmpdir2}/foo.#{type}"), "Copying #{type} file failed"
      assert image_files.include?("#{@tmpdir1}/foo.#{type}")
    end
    assert File.exist?("#{@tmpdir2}/subdir/foo.png"), "Copying a image file in a subdirectory"
    assert image_files.include?("#{@tmpdir1}/subdir/foo.png")
  end

  def test_copy_images_to_dir_convert
    touch_file("#{@tmpdir1}/foo.eps")

    image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2,
                                                 :convert => {:eps => :png})

    assert File.exist?("#{@tmpdir2}/foo.eps.png"), "EPS to PNG conversion failed"
    assert image_files.include?("#{@tmpdir1}/foo.eps.png")
  end

  def test_copy_images_to_dir_with_exts
    types = %w{png gif jpg jpeg svg pdf eps}
    types4epub = %w{png gif jpg jpeg svg}
    types.each do |type|
      touch_file("#{@tmpdir1}/foo.#{type}")
    end
    image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2, :exts=>types4epub)

    types4epub.each do |type|
      assert image_files.include?("#{@tmpdir1}/foo.#{type}"), "foo.#{type} is not included"
    end
    (types - types4epub).each do |type|
      assert !image_files.include?("#{@tmpdir1}/foo.#{type}"), "foo.#{type} is included"
    end
  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
review-1.7.2 test/test_makerhelper.rb
review-1.7.1 test/test_makerhelper.rb
review-peg-0.2.2 test/test_makerhelper.rb
review-peg-0.2.1 test/test_makerhelper.rb
review-peg-0.2.0 test/test_makerhelper.rb
review-peg-0.1.3 test/test_makerhelper.rb
review-peg-0.1.2 test/test_makerhelper.rb
review-peg-0.1.1 test/test_makerhelper.rb
review-peg-0.1.0 test/test_makerhelper.rb
review-1.7.0 test/test_makerhelper.rb
review-1.6.0 test/test_makerhelper.rb
review-2.0.0.beta1 test/test_makerhelper.rb
review-1.5.0 test/test_makerhelper.rb
review-1.4.0 test/test_makerhelper.rb
review-1.3.0 test/test_makerhelper.rb
review-1.2.0 test/test_makerhelper.rb