Sha256: ebd27ddbfad1a18840a6365f49d3332d18749a0734f0e9f1bacfc58b7ed304b3

Contents?: true

Size: 1.92 KB

Versions: 15

Compression:

Stored size: 1.92 KB

Contents

# -*- encoding: utf-8 -*-

require 'minitest/autorun'
require 'tmpdir'
require 'fileutils'
require 'rbconfig'
require 'webgen/source/file_system'

class TestSourceFileSystem < Minitest::Test

  def setup
    @root = root = File.expand_path(File.dirname(__FILE__))
    @website = Object.new
    @website.define_singleton_method(:directory) { root }
  end

  def test_initialize
    source = Webgen::Source::FileSystem.new(@website, 'test', '**/*.page')
    assert_equal('**/*.page', source.glob)
    assert_equal(File.join(@root, 'test'), source.root)

    if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
      source = Webgen::Source::FileSystem.new(@website, 'c:/tmp/hallo')
      assert_equal('c:/tmp/hallo', source.root)
    else
      source = Webgen::Source::FileSystem.new(@website, '/tmp/hallo')
      assert_equal('{*,**/*}', source.glob)
      assert_equal('/tmp/hallo', source.root)
    end
    source = Webgen::Source::FileSystem.new(@website, '../hallo')
    assert_equal(File.expand_path(File.join(@root, '../hallo')), source.root)
  end

  def test_paths
    source = Webgen::Source::FileSystem.new(@website, '.')
    assert_equal(4, source.paths.length)
    assert(source.paths.include?(Webgen::Path.new('/')))
    assert(source.paths.include?(Webgen::Path.new('/test_file_system.rb')))

    source = Webgen::Source::FileSystem.new(@website, '.', '/../source/{*,**/*}')
    assert_equal(4, source.paths.length)
    assert(source.paths.include?(Webgen::Path.new('/source/')))
    assert(source.paths.include?(Webgen::Path.new('/source/test_file_system.rb')))
  end

  def test_handling_of_invalid_link
    skip if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
    Dir.mktmpdir('webgen-link-test') do |dir|
      FileUtils.touch(File.join(dir, 'test'))
      File.symlink('non-existing-file', File.join(dir, 'invalid-link'))
      source = Webgen::Source::FileSystem.new(@website, dir, '/t*')
      assert(source.paths.length == 1)
    end
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
webgen-1.7.3 test/webgen/source/test_file_system.rb
webgen-1.7.2 test/webgen/source/test_file_system.rb
webgen-1.7.1 test/webgen/source/test_file_system.rb
webgen-1.7.0 test/webgen/source/test_file_system.rb
webgen-1.6.0 test/webgen/source/test_file_system.rb
webgen-1.5.2 test/webgen/source/test_file_system.rb
webgen-1.5.1 test/webgen/source/test_file_system.rb
webgen-1.5.0 test/webgen/source/test_file_system.rb
webgen-1.4.1 test/webgen/source/test_file_system.rb
webgen-1.4.0 test/webgen/source/test_file_system.rb
webgen-1.3.0 test/webgen/source/test_file_system.rb
webgen-1.2.1 test/webgen/source/test_file_system.rb
webgen-1.2.0 test/webgen/source/test_file_system.rb
webgen-1.1.0 test/webgen/source/test_file_system.rb
webgen-1.0.0 test/webgen/source/test_file_system.rb