test/base/test_item_rep.rb in nanoc-3.7.3 vs test/base/test_item_rep.rb in nanoc-3.7.4

- old
+ new

@@ -64,11 +64,11 @@ end def test_compiled_content_with_uncompiled_content # Create rep item = Nanoc::Item.new( - "blah blah", {}, '/', + 'blah blah', {}, '/', :binary => false ) rep = Nanoc::ItemRep.new(item, nil) rep.expects(:compiled?).returns(false) @@ -85,11 +85,11 @@ site.expect(:config, []) site.expect(:layouts, []) # Mock item item = Nanoc::Item.new( - %[<%= '<%= "blah" %' + '>' %>], {}, '/', + %(<%= '<%= "blah" %' + '>' %>), {}, '/', :binary => false ) # Create item rep item_rep = Nanoc::ItemRep.new(item, :foo) @@ -99,25 +99,25 @@ end # Filter once item_rep.assigns = {} item_rep.filter(:erb) - assert_equal(%[<%= "blah" %>], item_rep.instance_eval { @content[:last] }) + assert_equal(%(<%= "blah" %>), item_rep.instance_eval { @content[:last] }) # Filter twice item_rep.assigns = {} item_rep.filter(:erb) - assert_equal(%[blah], item_rep.instance_eval { @content[:last] }) + assert_equal(%(blah), item_rep.instance_eval { @content[:last] }) end def test_layout # Mock layout - layout = Nanoc::Layout.new(%[<%= "blah" %>], {}, '/somelayout/') + layout = Nanoc::Layout.new(%(<%= "blah" %>), {}, '/somelayout/') # Mock item item = Nanoc::Item.new( - "blah blah", {}, '/', + 'blah blah', {}, '/', :binary => false ) # Create item rep item_rep = Nanoc::ItemRep.new(item, :foo) @@ -127,11 +127,11 @@ end # Layout item_rep.assigns = {} item_rep.layout(layout, :erb, {}) - assert_equal(%[blah], item_rep.instance_eval { @content[:last] }) + assert_equal(%(blah), item_rep.instance_eval { @content[:last] }) end def test_snapshot # Mock site site = MiniTest::Mock.new @@ -139,11 +139,11 @@ site.expect(:config, []) site.expect(:layouts, []) # Mock item item = Nanoc::Item.new( - %[<%= '<%= "blah" %' + '>' %>], {}, '/foobar/', + %(<%= '<%= "blah" %' + '>' %>), {}, '/foobar/', :binary => false ) # Create item rep item_rep = Nanoc::ItemRep.new(item, :foo) @@ -159,19 +159,19 @@ item_rep.snapshot(:bar) item_rep.filter(:erb) item_rep.snapshot(:qux) # Check snapshots - assert_equal(%[<%= '<%= "blah" %' + '>' %>], item_rep.instance_eval { @content[:foo] }) - assert_equal(%[<%= "blah" %>], item_rep.instance_eval { @content[:bar] }) - assert_equal(%[blah], item_rep.instance_eval { @content[:qux] }) + assert_equal(%(<%= '<%= "blah" %' + '>' %>), item_rep.instance_eval { @content[:foo] }) + assert_equal(%(<%= "blah" %>), item_rep.instance_eval { @content[:bar] }) + assert_equal(%(blah), item_rep.instance_eval { @content[:qux] }) end def test_snapshot_should_be_written # Mock item item = Nanoc::Item.new( - "blah blah", {}, '/', + 'blah blah', {}, '/', :binary => false ) # Create rep item_rep = Nanoc::ItemRep.new(item, :foo) @@ -196,17 +196,17 @@ end def test_write_should_not_touch_identical_textual_files # Mock item item = Nanoc::Item.new( - "blah blah", {}, '/', + 'blah blah', {}, '/', :binary => false ) # Create rep item_rep = Nanoc::ItemRep.new(item, :foo) - def item_rep.generate_diff ; end + def item_rep.generate_diff; end item_rep.instance_eval { @content[:last] = 'Lorem ipsum, etc.' } item_rep.raw_path = 'foo/bar/baz/quux.txt' # Write once item_rep.write @@ -220,11 +220,11 @@ end def test_write # Mock item item = Nanoc::Item.new( - "blah blah", {}, '/', + 'blah blah', {}, '/', :binary => false ) # Create rep item_rep = Nanoc::ItemRep.new(item, :foo) @@ -240,23 +240,23 @@ end def test_filter_text_to_binary # Mock item item = Nanoc::Item.new( - "blah blah", {}, '/', + 'blah blah', {}, '/', :binary => false ) # Create rep rep = Nanoc::ItemRep.new(item, :foo) - def rep.assigns ; {} ; end + def rep.assigns; {}; end # Create fake filter def rep.filter_named(name) @filter ||= Class.new(::Nanoc::Filter) do type :text => :binary - def run(content, params={}) + def run(content, params = {}) File.open(output_filename, 'w') { |io| io.write(content) } end end end @@ -268,23 +268,23 @@ end def test_filter_with_textual_rep_and_binary_filter # Mock item item = Nanoc::Item.new( - "blah blah", {}, '/', + 'blah blah', {}, '/', :binary => false ) # Create rep rep = Nanoc::ItemRep.new(item, :foo) - def rep.assigns ; {} ; end + def rep.assigns; {}; end # Create fake filter def rep.filter_named(name) @filter ||= Class.new(::Nanoc::Filter) do type :binary - def run(content, params={}) + def run(content, params = {}) File.open(output_filename, 'w') { |io| io.write(content) } end end end @@ -327,22 +327,22 @@ assert_equal(file_content, File.read(out_filename)) end def test_converted_binary_rep_can_be_layed_out # Mock layout - layout = Nanoc::Layout.new(%[<%= "blah" %> <%= yield %>], {}, '/somelayout/') + layout = Nanoc::Layout.new(%(<%= "blah" %> <%= yield %>), {}, '/somelayout/') # Create item and item rep item = create_binary_item rep = create_rep_for(item, :foo) rep.assigns = { :content => 'meh' } # Create filter Class.new(::Nanoc::Filter) do - type :binary => :text + type :binary => :text identifier :binary_to_text - def run(content, params={}) + def run(content, params = {}) content + ' textified' end end # Run and check @@ -365,23 +365,23 @@ assert rep.binary? def rep.filter_named(name) Class.new(::Nanoc::Filter) do type :binary => :text - def run(content, params={}) - "Some textual content" + def run(content, params = {}) + 'Some textual content' end end end rep.filter(:binary_to_text) assert !rep.binary? def rep.filter_named(name) Class.new(::Nanoc::Filter) do type :text - def run(content, params={}) - "Some textual content" + def run(content, params = {}) + 'Some textual content' end end end rep.filter(:text_filter) assert !rep.binary? @@ -401,61 +401,61 @@ assert rep.binary? def rep.filter_named(name) @filter ||= Class.new(::Nanoc::Filter) do type :binary => :text - def run(content, params={}) - "Some textual content" + def run(content, params = {}) + 'Some textual content' end end end rep.filter(:binary_to_text) refute rep.binary? assert_raises(Nanoc::Errors::CannotUseBinaryFilter) { rep.filter(:binary_filter) } end def test_new_content_should_be_frozen filter_class = Class.new(::Nanoc::Filter) do - def run(content, params={}) + def run(content, params = {}) content.gsub!('foo', 'moo') content end end - item = Nanoc::Item.new("foo bar", {}, '/foo/') + item = Nanoc::Item.new('foo bar', {}, '/foo/') rep = Nanoc::ItemRep.new(item, :default) rep.instance_eval { @filter_class = filter_class } - def rep.filter_named(name) ; @filter_class ; end + def rep.filter_named(name); @filter_class; end assert_raises_frozen_error do rep.filter(:whatever) end end def test_filter_should_freeze_content filter_class = Class.new(::Nanoc::Filter) do - def run(content, params={}) + def run(content, params = {}) content.gsub!('foo', 'moo') content end end - item = Nanoc::Item.new("foo bar", {}, '/foo/') + item = Nanoc::Item.new('foo bar', {}, '/foo/') rep = Nanoc::ItemRep.new(item, :default) rep.instance_eval { @filter_class = filter_class } - def rep.filter_named(name) ; @filter_class ; end + def rep.filter_named(name); @filter_class; end assert_raises_frozen_error do rep.filter(:erb) rep.filter(:whatever) end end def test_raw_path_should_generate_dependency items = [ - Nanoc3::Item.new("foo", {}, '/foo/'), - Nanoc3::Item.new("bar", {}, '/bar/') + Nanoc3::Item.new('foo', {}, '/foo/'), + Nanoc3::Item.new('bar', {}, '/bar/') ] item_reps = [ Nanoc3::ItemRep.new(items[0], :default), Nanoc3::ItemRep.new(items[1], :default) ] @@ -465,17 +465,17 @@ Nanoc3::NotificationCenter.post(:visit_started, items[0]) item_reps[1].raw_path Nanoc3::NotificationCenter.post(:visit_ended, items[0]) dt.stop - assert_equal [ items[1] ], dt.objects_causing_outdatedness_of(items[0]) + assert_equal [items[1]], dt.objects_causing_outdatedness_of(items[0]) end def test_path_should_generate_dependency items = [ - Nanoc3::Item.new("foo", {}, '/foo/'), - Nanoc3::Item.new("bar", {}, '/bar/') + Nanoc3::Item.new('foo', {}, '/foo/'), + Nanoc3::Item.new('bar', {}, '/bar/') ] item_reps = [ Nanoc3::ItemRep.new(items[0], :default), Nanoc3::ItemRep.new(items[1], :default) ] @@ -485,15 +485,15 @@ Nanoc3::NotificationCenter.post(:visit_started, items[0]) item_reps[1].path Nanoc3::NotificationCenter.post(:visit_ended, items[0]) dt.stop - assert_equal [ items[1] ], dt.objects_causing_outdatedness_of(items[0]) + assert_equal [items[1]], dt.objects_causing_outdatedness_of(items[0]) end def test_access_compiled_content_of_binary_item - item = Nanoc::Item.new("content/somefile.dat", {}, '/somefile/', :binary => true) + item = Nanoc::Item.new('content/somefile.dat', {}, '/somefile/', :binary => true) item_rep = Nanoc::ItemRep.new(item, :foo) assert_raises(Nanoc::Errors::CannotGetCompiledContentOfBinaryItem) do item_rep.compiled_content end end @@ -501,11 +501,11 @@ def test_write_should_calculate_is_modified_correctly_for_binary_items_new # Mock item FileUtils.mkdir_p('content') File.open('content/meow.dat', 'w') { |io| io.write('asdf') } item = Nanoc::Item.new( - "content/meow.dat", {}, '/', + 'content/meow.dat', {}, '/', :binary => true ) # Create rep item_rep = Nanoc::ItemRep.new(item, :foo) @@ -529,11 +529,11 @@ def test_write_should_calculate_is_modified_correctly_for_binary_items_existing # Mock item FileUtils.mkdir_p('content') File.open('content/meow.dat', 'w') { |io| io.write('asdf') } item = Nanoc::Item.new( - "content/meow.dat", {}, '/', + 'content/meow.dat', {}, '/', :binary => true ) # Create rep item_rep = Nanoc::ItemRep.new(item, :foo) @@ -554,15 +554,15 @@ item_rep.write assert notified Nanoc::NotificationCenter.remove(:rep_written, self) end -private + private def create_binary_item Nanoc::Item.new( - "/a/file/name.dat", {}, '/', + '/a/file/name.dat', {}, '/', :binary => true ) end def mock_and_stub(params) @@ -578,20 +578,20 @@ end def create_textual_filter f = create_filter(:text) f.class_eval do - def run(content, params={}) - "" + def run(content, params = {}) + '' end end f end def create_binary_filter f = create_filter(:binary) f.class_eval do - def run(content, params={}) + def run(content, params = {}) File.open(output_filename, 'w') { |io| io.write(content) } end end f end