test/base/test_item.rb in nanoc-3.8.0 vs test/base/test_item.rb in nanoc-4.0.0a1

- old
+ new

@@ -1,32 +1,34 @@ # encoding: utf-8 -class Nanoc::ItemTest < Nanoc::TestCase +class Nanoc::Int::ItemTest < Nanoc::TestCase def test_initialize_with_attributes_with_string_keys - item = Nanoc::Item.new('foo', { 'abc' => 'xyz' }, '/foo/') + item = Nanoc::Int::Item.new('foo', { 'abc' => 'xyz' }, '/foo/') assert_equal nil, item.attributes['abc'] assert_equal 'xyz', item.attributes[:abc] end def test_initialize_with_unclean_identifier - item = Nanoc::Item.new('foo', {}, '/foo') + item = Nanoc::Int::Item.new('foo', {}, '/foo') - assert_equal '/foo/', item.identifier + assert_equal '/foo/', item.identifier.to_s end - def test_frozen_identifier - item = Nanoc::Item.new('foo', {}, '/foo') + def test_reference + item = Nanoc::Int::Item.new( + 'content', + { one: 'one in item' }, + '/path/' + ) - assert_raises_frozen_error do - item.identifier.chop! - end + assert_equal([:item, '/path/'], item.reference) end def test_lookup # Create item - item = Nanoc::Item.new( + item = Nanoc::Int::Item.new( 'content', { one: 'one in item' }, '/path/' ) @@ -36,11 +38,11 @@ # Test finding two assert_equal(nil, item[:two]) end def test_set_attribute - item = Nanoc::Item.new('foo', {}, '/foo') + item = Nanoc::Int::Item.new('foo', {}, '/foo') assert_equal nil, item[:motto] item[:motto] = 'More human than human' assert_equal 'More human than human', item[:motto] end @@ -54,11 +56,11 @@ def rep.compiled_content(params) "content at #{params[:snapshot].inspect}" end # Mock item - item = Nanoc::Item.new('foo', {}, '/foo') + item = Nanoc::Int::Item.new('foo', {}, '/foo') item.expects(:reps).returns([rep]) # Check assert_equal 'content at nil', item.compiled_content end @@ -72,11 +74,11 @@ def rep.compiled_content(params) "content at #{params[:snapshot].inspect}" end # Mock item - item = Nanoc::Item.new('foo', {}, '/foo') + item = Nanoc::Int::Item.new('foo', {}, '/foo') item.expects(:reps).returns([rep]) # Check assert_equal 'content at nil', item.compiled_content(rep: :foo) end @@ -90,24 +92,24 @@ def rep.compiled_content(params) "content at #{params[:snapshot].inspect}" end # Mock item - item = Nanoc::Item.new('foo', {}, '/foo') + item = Nanoc::Int::Item.new('foo', {}, '/foo') item.expects(:reps).returns([rep]) # Check assert_equal 'content at :blah', item.compiled_content(snapshot: :blah) end def test_compiled_content_with_custom_nonexistant_rep # Mock item - item = Nanoc::Item.new('foo', {}, '/foo') + item = Nanoc::Int::Item.new('foo', {}, '/foo') item.expects(:reps).returns([]) # Check - assert_raises(Nanoc::Errors::Generic) do + assert_raises(Nanoc::Int::Errors::Generic) do item.compiled_content(rep: :lkasdhflahgwfe) end end def test_path_with_default_rep @@ -115,11 +117,11 @@ rep = mock rep.expects(:name).returns(:default) rep.expects(:path).returns('the correct path') # Mock item - item = Nanoc::Item.new('foo', {}, '/foo') + item = Nanoc::Int::Item.new('foo', {}, '/foo') item.expects(:reps).returns([rep]) # Check assert_equal 'the correct path', item.path end @@ -129,19 +131,19 @@ rep = mock rep.expects(:name).returns(:moo) rep.expects(:path).returns('the correct path') # Mock item - item = Nanoc::Item.new('foo', {}, '/foo') + item = Nanoc::Int::Item.new('foo', {}, '/foo') item.expects(:reps).returns([rep]) # Check assert_equal 'the correct path', item.path(rep: :moo) end def test_freeze_should_disallow_changes - item = Nanoc::Item.new('foo', { a: { b: 123 } }, '/foo/') + item = Nanoc::Int::Item.new('foo', { a: { b: 123 } }, '/foo/') item.freeze assert_raises_frozen_error do item[:abc] = '123' end @@ -150,17 +152,17 @@ item[:a][:b] = '456' end end def test_dump_and_load - item = Nanoc::Item.new( + item = Nanoc::Int::Item.new( 'foobar', { a: { b: 123 } }, '/foo/') item = Marshal.load(Marshal.dump(item)) - assert_equal '/foo/', item.identifier + assert_equal Nanoc::Identifier.new('/foo/'), item.identifier assert_equal 'foobar', item.raw_content assert_equal({ a: { b: 123 } }, item.attributes) end end