test/helpers/test_blogging.rb in nanoc-3.7.4 vs test/helpers/test_blogging.rb in nanoc-3.7.5
- old
+ new
@@ -1,9 +1,8 @@
# encoding: utf-8
class Nanoc::Helpers::BloggingTest < Nanoc::TestCase
-
include Nanoc::Helpers::Blogging
include Nanoc::Helpers::Text
def mock_article
item = mock
@@ -30,21 +29,21 @@
def test_articles
# Create items
@items = [
Nanoc::Item.new(
'blah',
- { :kind => 'item' },
+ { kind: 'item' },
'/0/'
),
Nanoc::Item.new(
'blah blah',
- { :kind => 'article' },
+ { kind: 'article' },
'/1/'
),
Nanoc::Item.new(
'blah blah blah',
- { :kind => 'article' },
+ { kind: 'article' },
'/2/'
)
]
# Check
@@ -59,21 +58,21 @@
def test_sorted_articles
# Create items
@items = [
Nanoc::Item.new(
'blah',
- { :kind => 'item' },
+ { kind: 'item' },
'/0/'
),
Nanoc::Item.new(
'blah',
- { :kind => 'article', :created_at => (Date.today - 1).to_s },
+ { kind: 'article', created_at: (Date.today - 1).to_s },
'/1/'
),
Nanoc::Item.new(
'blah',
- { :kind => 'article', :created_at => (Time.now - 500).to_s },
+ { kind: 'article', created_at: (Time.now - 500).to_s },
'/2/'
)
]
# Check
@@ -100,18 +99,18 @@
@items[1].stubs(:[]).with(:title).returns('Item One')
@items[1].stubs(:[]).with(:custom_path_in_feed).returns(nil)
@items[1].stubs(:[]).with(:custom_url_in_feed).returns(nil)
@items[1].stubs(:[]).with(:excerpt).returns(nil)
@items[1].stubs(:path).returns('/item1/')
- @items[1].expects(:compiled_content).with(:snapshot => :pre).returns('item 1 content')
+ @items[1].expects(:compiled_content).with(snapshot: :pre).returns('item 1 content')
# Create item 2
- @items[2].expects(:compiled_content).with(:snapshot => :pre).returns('item 2 content')
+ @items[2].expects(:compiled_content).with(snapshot: :pre).returns('item 2 content')
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Cool Blog')
@item.stubs(:[]).with(:author_name).returns('Denis Defreyne')
@@ -139,11 +138,11 @@
@items[2].stubs(:[]).with(:created_at).returns(Time.now - 1200)
@items[2].expects(:compiled_content).returns('item 2 content')
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Cool Blog')
@item.stubs(:[]).with(:author_name).returns('Denis Defreyne')
@@ -161,11 +160,11 @@
# Mock items
@items = [mock_item, mock_item]
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@@ -187,11 +186,11 @@
# Create items
@items = [mock_item, mock_article]
# Mock site
@site = mock
- @site.stubs(:config).returns({:base_url => nil})
+ @site.stubs(:config).returns({ base_url: nil })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@@ -213,11 +212,11 @@
# Create items
@items = [mock_item, mock_article]
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns(nil)
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@@ -239,11 +238,11 @@
# Create items
@items = [mock_item, mock_article]
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns(nil)
@@ -270,11 +269,11 @@
@items[0].stubs(:[]).with(:author_uri).returns('http://don.example.com/')
@items[0].expects(:compiled_content).returns('item 1 content')
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com/' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com/' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:kind).returns(nil)
@item.stubs(:[]).with(:title).returns('My Cool Blog')
@@ -313,11 +312,11 @@
# Create items
@items = [mock_item, mock_article]
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@@ -341,11 +340,11 @@
@items[1].stubs(:[]).with(:created_at).returns(Time.now.to_s)
@items[2].stubs(:[]).with(:created_at).returns(nil)
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@@ -364,44 +363,44 @@
def test_atom_feed_with_title_author_name_and_uri_as_params
if_have 'builder' do
# Create items
@items = [mock_item, mock_article]
- @items[1].expects(:compiled_content).with(:snapshot => :pre).returns('asdf')
+ @items[1].expects(:compiled_content).with(snapshot: :pre).returns('asdf')
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns(nil)
@item.stubs(:[]).with(:author_name).returns(nil)
@item.stubs(:[]).with(:author_uri).returns(nil)
@item.stubs(:[]).with(:[]).with(:feed_url).returns('http://example.com/feed')
# Check
atom_feed(
- :author_name => 'Bob',
- :author_uri => 'http://example.com/~bob/',
- :title => 'My Blog Or Something'
+ author_name: 'Bob',
+ author_uri: 'http://example.com/~bob/',
+ title: 'My Blog Or Something'
)
end
end
def test_atom_feed_with_title_author_name_and_uri_from_config
if_have 'builder' do
# Create items
@items = [mock_item, mock_article]
- @items[1].expects(:compiled_content).with(:snapshot => :pre).returns('asdf')
+ @items[1].expects(:compiled_content).with(snapshot: :pre).returns('asdf')
# Mock site
@config = {
- :author_name => 'Bob',
- :author_uri => 'http://example.com/~bob/',
- :title => 'My Blog Or Something',
- :base_url => 'http://example.com'
+ author_name: 'Bob',
+ author_uri: 'http://example.com/~bob/',
+ title: 'My Blog Or Something',
+ base_url: 'http://example.com'
}
@site = mock
@site.stubs(:config).returns(@config)
# Create feed item
@@ -421,25 +420,25 @@
# Mock items
@items = [mock_article, mock_article]
@items[0].expects(:compiled_content).never
@items[1].stubs(:[]).with(:title).returns('Item One')
- @items[1].expects(:compiled_content).with(:snapshot => :pre).returns('asdf')
+ @items[1].expects(:compiled_content).with(snapshot: :pre).returns('asdf')
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
@item.stubs(:[]).with(:[]).with(:feed_url).returns('http://example.com/feed')
# Check
- atom_feed :articles => [@items[1]]
+ atom_feed articles: [@items[1]]
end
end
def test_atom_feed_with_limit_param
if_have 'builder' do
@@ -450,21 +449,21 @@
article.stubs(:[]).with(:created_at).returns(Time.now - i)
end
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
@item.stubs(:[]).with(:feed_url).returns('http://example.com/feed')
# Check
- result = atom_feed :limit => 1, :articles => @items
+ result = atom_feed limit: 1, articles: @items
assert_match(
Regexp.new('Article 0', Regexp::MULTILINE),
result
)
refute_match(
@@ -484,11 +483,11 @@
@items[0].stubs(:[]).with(:created_at).returns('23-02-2009')
@items[1].stubs(:[]).with(:created_at).returns('22-03-2009')
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@@ -509,21 +508,21 @@
# Mock article
@items = [mock_article]
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
@item.stubs(:[]).with(:feed_url).returns('http://example.com/feed')
# Check
- result = atom_feed :content_proc => lambda { |a| 'foobar!' }
+ result = atom_feed content_proc: ->(_a) { 'foobar!' }
assert_match 'foobar!</content>', result
end
end
def test_atom_feed_with_excerpt_proc_param
@@ -531,21 +530,21 @@
# Mock article
@items = [mock_article]
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
@item.stubs(:[]).with(:[]).with(:feed_url).returns('http://example.com/feed')
# Check
- result = atom_feed :excerpt_proc => lambda { |a| 'foobar!' }
+ result = atom_feed excerpt_proc: ->(_a) { 'foobar!' }
assert_match 'foobar!</summary>', result
end
end
def test_atom_feed_with_icon_param
@@ -553,21 +552,21 @@
# Mock article
@items = [mock_article]
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
@item.stubs(:[]).with(:feed_url).returns('http://example.com/feed')
# Check
- result = atom_feed :icon => 'http://example.com/icon.png'
+ result = atom_feed icon: 'http://example.com/icon.png'
assert_match '<icon>http://example.com/icon.png</icon>', result
end
end
def test_atom_feed_with_logo_param
@@ -575,21 +574,21 @@
# Mock article
@items = [mock_article]
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
@item.stubs(:[]).with(:author_name).returns('J. Doe')
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
@item.stubs(:[]).with(:feed_url).returns('http://example.com/feed')
# Check
- result = atom_feed :logo => 'http://example.com/logo.png'
+ result = atom_feed logo: 'http://example.com/logo.png'
assert_match '<logo>http://example.com/logo.png</logo>', result
end
end
def test_atom_feed_with_item_without_path
@@ -598,11 +597,11 @@
@items = [mock_article]
@items[0].stubs(:path).returns(nil)
# Mock site
@site = mock
- @site.stubs(:config).returns({ :base_url => 'http://example.com' })
+ @site.stubs(:config).returns({ base_url: 'http://example.com' })
# Create feed item
@item = mock
@item.stubs(:identifier).returns('/feed/')
@item.stubs(:[]).with(:title).returns('My Cool Blog')
@@ -616,11 +615,11 @@
end
end
def test_url_for_without_custom_path_in_feed
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create article
item = Nanoc::Item.new('content', {}, '/foo/')
item.reps << Nanoc::ItemRep.new(item, :default)
item.reps[0].path = '/foo/bar/'
@@ -632,15 +631,15 @@
@item = nil
end
def test_url_for_with_custom_path_in_feed
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create article
item = Nanoc::Item.new(
- 'content', { :custom_path_in_feed => '/meow/woof/' }, '/foo/')
+ 'content', { custom_path_in_feed: '/meow/woof/' }, '/foo/')
item.reps << Nanoc::ItemRep.new(item, :default)
# Check
assert_equal('http://example.com/meow/woof/', url_for(item))
ensure
@@ -648,15 +647,15 @@
@item = nil
end
def test_url_for_with_custom_url_in_feed
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create article
item = Nanoc::Item.new(
- 'content', { :custom_url_in_feed => 'http://example.org/x' }, '/foo/')
+ 'content', { custom_url_in_feed: 'http://example.org/x' }, '/foo/')
item.reps << Nanoc::ItemRep.new(item, :default)
# Check
assert_equal('http://example.org/x', url_for(item))
ensure
@@ -674,11 +673,11 @@
end
end
def test_url_for_without_path
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create article
item = Nanoc::Item.new('content', {}, '/foo/')
item.reps << Nanoc::ItemRep.new(item, :default)
item.reps[0].path = nil
@@ -687,11 +686,11 @@
assert_equal(nil, url_for(item))
end
def test_feed_url_without_custom_feed_url
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create article
@item = Nanoc::Item.new('content', {}, '/foo/')
@item.reps << Nanoc::ItemRep.new(@item, :default)
@item.reps[0].path = '/foo/bar/'
@@ -703,14 +702,14 @@
@item = nil
end
def test_feed_url_with_custom_feed_url
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create feed item
- @item = Nanoc::Item.new('content', { :feed_url => 'http://example.com/feed/' }, '/foo/')
+ @item = Nanoc::Item.new('content', { feed_url: 'http://example.com/feed/' }, '/foo/')
@item.reps << Nanoc::ItemRep.new(@item, :default)
@item.reps[0].path = '/foo/bar/'
# Check
assert_equal('http://example.com/feed/', feed_url)
@@ -729,68 +728,67 @@
end
end
def test_atom_tag_for_with_path
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create article
- item = Nanoc::Item.new('content', { :created_at => '2008-05-19' }, '/foo/')
+ item = Nanoc::Item.new('content', { created_at: '2008-05-19' }, '/foo/')
item.reps << Nanoc::ItemRep.new(item, :default)
item.reps[0].path = '/foo/bar/'
# Check
assert_equal('tag:example.com,2008-05-19:/foo/bar/', atom_tag_for(item))
end
def test_atom_tag_for_without_path
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create article
- item = Nanoc::Item.new('content', { :created_at => '2008-05-19' }, '/baz/qux/')
+ item = Nanoc::Item.new('content', { created_at: '2008-05-19' }, '/baz/qux/')
item.reps << Nanoc::ItemRep.new(item, :default)
# Check
assert_equal('tag:example.com,2008-05-19:/baz/qux/', atom_tag_for(item))
end
def test_atom_tag_for_with_base_url_in_dir
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com/somedir' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com/somedir' })
# Create article
- item = Nanoc::Item.new('content', { :created_at => '2008-05-19' }, '/foo/')
+ item = Nanoc::Item.new('content', { created_at: '2008-05-19' }, '/foo/')
item.reps << Nanoc::ItemRep.new(item, :default)
item.reps[0].path = '/foo/bar/'
# Check
assert_equal('tag:example.com,2008-05-19:/somedir/foo/bar/', atom_tag_for(item))
end
def test_atom_tag_for_with_time
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create article
- item = Nanoc::Item.new('content', { :created_at => Time.parse('2008-05-19') }, '/foo/')
+ item = Nanoc::Item.new('content', { created_at: Time.parse('2008-05-19') }, '/foo/')
item.reps << Nanoc::ItemRep.new(item, :default)
item.reps[0].path = '/foo/bar/'
# Check
assert_equal('tag:example.com,2008-05-19:/foo/bar/', atom_tag_for(item))
end
def test_atom_tag_for_with_date
# Create site
- @site = Nanoc::Site.new({ :base_url => 'http://example.com' })
+ @site = Nanoc::Site.new({ base_url: 'http://example.com' })
# Create article
- item = Nanoc::Item.new('content', { :created_at => Date.parse('2008-05-19') }, '/foo/')
+ item = Nanoc::Item.new('content', { created_at: Date.parse('2008-05-19') }, '/foo/')
item.reps << Nanoc::ItemRep.new(item, :default)
item.reps[0].path = '/foo/bar/'
# Check
assert_equal('tag:example.com,2008-05-19:/foo/bar/', atom_tag_for(item))
end
-
end