Shoulda-izing the pager test and correcting some formatting issues
This commit is contained in:
parent
e1dbda47ed
commit
605adf88d5
|
@ -15,8 +15,3 @@ Feature: Site pagination
|
||||||
When I run jekyll
|
When I run jekyll
|
||||||
Then the _site/page2 directory should exist
|
Then the _site/page2 directory should exist
|
||||||
And the _site/page2/index.html file should exist
|
And the _site/page2/index.html file should exist
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ module Jekyll
|
||||||
@total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page)
|
@total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page)
|
||||||
|
|
||||||
if @page > @total_pages
|
if @page > @total_pages
|
||||||
raise RuntimeError, "page number can't be grater than total pages: #{@page} > #{@total_pages}"
|
raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}"
|
||||||
end
|
end
|
||||||
|
|
||||||
init = (@page - 1) * @per_page
|
init = (@page - 1) * @per_page
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
require File.dirname(__FILE__) + '/helper'
|
require File.dirname(__FILE__) + '/helper'
|
||||||
|
|
||||||
class TestPager < Test::Unit::TestCase
|
class TestPager < Test::Unit::TestCase
|
||||||
|
context "pagination enabled" do
|
||||||
def setup
|
setup do
|
||||||
stub(Jekyll).configuration do
|
stub(Jekyll).configuration do
|
||||||
Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir,
|
Jekyll::DEFAULTS.merge({
|
||||||
'paginate' => 2})
|
'source' => source_dir,
|
||||||
|
'destination' => dest_dir,
|
||||||
|
'paginate' => 2
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@config = Jekyll.configuration
|
@config = Jekyll.configuration
|
||||||
|
@ -13,15 +16,11 @@ class TestPager < Test::Unit::TestCase
|
||||||
@posts = @site.read_posts('')
|
@posts = @site.read_posts('')
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
should "calculate number of pages" do
|
||||||
@config = Jekyll.configuration('paginate' => nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_calculate_pages
|
|
||||||
assert_equal(2, Pager.calculate_pages(@posts, @config['paginate']))
|
assert_equal(2, Pager.calculate_pages(@posts, @config['paginate']))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_first_pager
|
should "create first pager" do
|
||||||
pager = Pager.new(@config, 1, @posts)
|
pager = Pager.new(@config, 1, @posts)
|
||||||
assert_equal(@config['paginate'].to_i, pager.posts.size)
|
assert_equal(@config['paginate'].to_i, pager.posts.size)
|
||||||
assert_equal(2, pager.total_pages)
|
assert_equal(2, pager.total_pages)
|
||||||
|
@ -29,7 +28,7 @@ class TestPager < Test::Unit::TestCase
|
||||||
assert_equal(2, pager.next_page)
|
assert_equal(2, pager.next_page)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_second_pager
|
should "create second pager" do
|
||||||
pager = Pager.new(@config, 2, @posts)
|
pager = Pager.new(@config, 2, @posts)
|
||||||
assert_equal(@posts.size - @config['paginate'].to_i, pager.posts.size)
|
assert_equal(@posts.size - @config['paginate'].to_i, pager.posts.size)
|
||||||
assert_equal(2, pager.total_pages)
|
assert_equal(2, pager.total_pages)
|
||||||
|
@ -37,11 +36,12 @@ class TestPager < Test::Unit::TestCase
|
||||||
assert_nil(pager.next_page)
|
assert_nil(pager.next_page)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_third_pager
|
should "not create third pager" do
|
||||||
assert_raise(RuntimeError) { Pager.new(@config, 3, @posts) }
|
assert_raise(RuntimeError) { Pager.new(@config, 3, @posts) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_pagination_enabled_with_command_option
|
should "report that pagination is enabled" do
|
||||||
assert_equal(true, Pager.pagination_enabled?(@config, 'index.html'))
|
assert Pager.pagination_enabled?(@config, 'index.html')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue