Sha256: 033fda0029445b789ee53564ee3ec15b870899672fe2bb44d27ed5cfb6a2a1d9

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

# encoding: utf-8

class Nanoc::DataSourceTest < Nanoc::TestCase
  def test_loading
    # Create data source
    data_source = Nanoc::DataSource.new(nil, nil, nil, nil)
    data_source.expects(:up).times(1)
    data_source.expects(:down).times(1)

    # Test nested loading
    assert_equal(0, data_source.instance_eval { @references })
    data_source.loading do
      assert_equal(1, data_source.instance_eval { @references })
      data_source.loading do
        assert_equal(2, data_source.instance_eval { @references })
      end
      assert_equal(1, data_source.instance_eval { @references })
    end
    assert_equal(0, data_source.instance_eval { @references })
  end

  def test_not_implemented
    # Create data source
    data_source = Nanoc::DataSource.new(nil, nil, nil, nil)

    # Test optional methods
    data_source.up
    data_source.down

    # Test methods - loading data
    assert_equal [], data_source.items
    assert_equal [], data_source.layouts
  end

  def test_new_item
    data_source = Nanoc::DataSource.new(nil, nil, nil, nil)

    item = data_source.new_item('stuff', { title: 'Stuff!' }, '/asdf/')
    assert_equal 'stuff', item.raw_content
    assert_equal 'Stuff!', item.attributes[:title]
    assert_equal Nanoc::Identifier.new('/asdf/'), item.identifier
  end

  def test_new_layout
    data_source = Nanoc::DataSource.new(nil, nil, nil, nil)

    layout = data_source.new_layout('stuff', { title: 'Stuff!' }, '/asdf/')
    assert_equal 'stuff', layout.raw_content
    assert_equal 'Stuff!', layout.attributes[:title]
    assert_equal Nanoc::Identifier.new('/asdf/'), layout.identifier
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nanoc-4.0.0b2 test/base/test_data_source.rb
nanoc-4.0.0b1 test/base/test_data_source.rb
nanoc-4.0.0a2 test/base/test_data_source.rb