Sha256: fb01c6cc25e19ba694057dd7e8c3b0a14ef20053264cce64a9df71c6f40f41f5

Contents?: true

Size: 1.51 KB

Versions: 5

Compression:

Stored size: 1.51 KB

Contents

require 'test_helper'

class DatafilesTest < MiniTest::Test
  def setup
    @config = YAML.load_file(File.join(FIXTURES_DIR, 'nanoc.yaml')).deep_symbolize_keys
  end

  def test_it_collects_the_files
    files = Datafiles.collect_data(File.join(FIXTURES_DIR, 'data'))
    names = %w(categories/category reusables/intro reusables/names variables/empty variables/product)
    names.map! { |name| File.join(FIXTURES_DIR, 'data', "#{name}.yml") }
    assert_equal files, names
  end

  def test_it_creates_nested_hash
    string = %w(this is deep)
    value = 42
    hash = Datafiles.create_nested_hash(string, value)
    value = { 'this' => { 'is' => { 'deep' => 42 } } }
    assert_equal value, hash
  end

  def test_it_applies_conref_conditionals
    file = File.join(FIXTURES_DIR, 'data', 'variables', 'product.yml')
    content = File.read(file)
    result = Datafiles.apply_conditionals(@config, file, content)
    assert_includes result.to_s, 'No caveats!'

    @config[:data_variables][0][:values][:version] = 'foof'
    result = Datafiles.apply_conditionals(@config, file, content)
    assert_includes result.to_s, 'Well.....there is one.'
  end

  def test_it_leaves_liquid_substitutions_alone
    file = File.join(FIXTURES_DIR, 'data', 'reusables', 'intro.yml')
    content = File.read(file)
    result = Datafiles.apply_conditionals(@config, file, content)
    assert_includes result.to_s, 'We use {{ site.data.reusables.names.new_name }}'
    assert_includes result.to_s, '{{ site.data.variables.product.product_name }} is great'
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nanoc-conref-fs-0.2.1 test/datafiles_test.rb
nanoc-conref-fs-0.2.0 test/datafiles_test.rb
nanoc-conref-fs-0.1.1 test/datafiles_test.rb
nanoc-conref-fs-0.1.0 test/datafiles_test.rb
nanoc-conref-fs-0.0.1 test/datafiles_test.rb