Sha256: befe2f3bda2fa05e60ca0d67e9c37286a327c253c802204762f9ba415a06a5e8

Contents?: true

Size: 1017 Bytes

Versions: 6

Compression:

Stored size: 1017 Bytes

Contents

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

require 'test_helper'
require 'hexapdf/data_dir'

describe 'HexaPDF.data_dir' do
  before do
    @local = File.expand_path(File.join(__dir__, '..', '..', 'data', 'hexapdf'))
    @global = File.expand_path(File.join(RbConfig::CONFIG["datadir"], "hexapdf"))
    HexaPDF.remove_instance_variable(:@data_dir) if HexaPDF.instance_variable_defined?(:@data_dir)
  end

  after do
    HexaPDF.remove_instance_variable(:@data_dir) if HexaPDF.instance_variable_defined?(:@data_dir)
  end

  it "returns the 'local' data directory by default, e.g. in case of gem installations" do
    assert_equal(@local, HexaPDF.data_dir)
  end

  it "returns the global data directory if the local one isn't found" do
    File.stub(:directory?, lambda {|path| path == @local ? false : true}) do
      assert_equal(@global, HexaPDF.data_dir)
    end
  end

  it "fails if no data directory is found" do
    File.stub(:directory?, lambda {|_path| false}) do
      assert_raises { HexaPDF.data_dir }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hexapdf-0.6.0 test/hexapdf/test_data_dir.rb
hexapdf-0.5.0 test/hexapdf/test_data_dir.rb
hexapdf-0.4.0 test/hexapdf/test_data_dir.rb
hexapdf-0.3.0 test/hexapdf/test_data_dir.rb
hexapdf-0.2.0 test/hexapdf/test_data_dir.rb
hexapdf-0.1.0 test/hexapdf/test_data_dir.rb