From 605adf88d5a296c79b4fb3a676d1756e7ebddf6e Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Sat, 9 May 2009 11:23:45 -0400 Subject: [PATCH] Shoulda-izing the pager test and correcting some formatting issues --- features/pagination.feature | 9 +---- lib/jekyll/pager.rb | 4 +- test/test_pager.rb | 78 ++++++++++++++++++------------------- 3 files changed, 43 insertions(+), 48 deletions(-) diff --git a/features/pagination.feature b/features/pagination.feature index 6901ef92..439ea90b 100644 --- a/features/pagination.feature +++ b/features/pagination.feature @@ -9,14 +9,9 @@ Feature: Site pagination And I have an "index.html" file that contains "Basic Site" And I have a _posts directory And I have the following post: - | title | date | layout | content | - | Wargames | 3/27/2009 | default | The only winning move is not to play. | + | title | date | layout | content | + | Wargames | 3/27/2009 | default | The only winning move is not to play. | | Wargames2 | 4/27/2009 | default | The only winning move is not to play2. | When I run jekyll Then the _site/page2 directory should exist And the _site/page2/index.html file should exist - - - - - diff --git a/lib/jekyll/pager.rb b/lib/jekyll/pager.rb index ea46b4f0..883579a4 100644 --- a/lib/jekyll/pager.rb +++ b/lib/jekyll/pager.rb @@ -18,7 +18,7 @@ module Jekyll @total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page) 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 init = (@page - 1) * @per_page @@ -42,4 +42,4 @@ module Jekyll } end end -end \ No newline at end of file +end diff --git a/test/test_pager.rb b/test/test_pager.rb index dc0b66e8..34ffc164 100644 --- a/test/test_pager.rb +++ b/test/test_pager.rb @@ -1,47 +1,47 @@ require File.dirname(__FILE__) + '/helper' class TestPager < Test::Unit::TestCase - - def setup - stub(Jekyll).configuration do - Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, - 'paginate' => 2}) + context "pagination enabled" do + setup do + stub(Jekyll).configuration do + Jekyll::DEFAULTS.merge({ + 'source' => source_dir, + 'destination' => dest_dir, + 'paginate' => 2 + }) + end + + @config = Jekyll.configuration + @site = Site.new(@config) + @posts = @site.read_posts('') end - @config = Jekyll.configuration - @site = Site.new(@config) - @posts = @site.read_posts('') - end - - def teardown - @config = Jekyll.configuration('paginate' => nil) - end - - def test_calculate_pages - assert_equal(2, Pager.calculate_pages(@posts, @config['paginate'])) - end + should "calculate number of pages" do + assert_equal(2, Pager.calculate_pages(@posts, @config['paginate'])) + end - def test_create_first_pager - pager = Pager.new(@config, 1, @posts) - assert_equal(@config['paginate'].to_i, pager.posts.size) - assert_equal(2, pager.total_pages) - assert_nil(pager.previous_page) - assert_equal(2, pager.next_page) - end + should "create first pager" do + pager = Pager.new(@config, 1, @posts) + assert_equal(@config['paginate'].to_i, pager.posts.size) + assert_equal(2, pager.total_pages) + assert_nil(pager.previous_page) + assert_equal(2, pager.next_page) + end - def test_create_second_pager - pager = Pager.new(@config, 2, @posts) - assert_equal(@posts.size - @config['paginate'].to_i, pager.posts.size) - assert_equal(2, pager.total_pages) - assert_equal(1, pager.previous_page) - assert_nil(pager.next_page) + should "create second pager" do + pager = Pager.new(@config, 2, @posts) + assert_equal(@posts.size - @config['paginate'].to_i, pager.posts.size) + assert_equal(2, pager.total_pages) + assert_equal(1, pager.previous_page) + assert_nil(pager.next_page) + end + + should "not create third pager" do + assert_raise(RuntimeError) { Pager.new(@config, 3, @posts) } + end + + should "report that pagination is enabled" do + assert Pager.pagination_enabled?(@config, 'index.html') + end end - - def test_create_third_pager - assert_raise(RuntimeError) { Pager.new(@config, 3, @posts) } - end - - def test_pagination_enabled_with_command_option - assert_equal(true, Pager.pagination_enabled?(@config, 'index.html')) - end -end \ No newline at end of file +end