File: test_related_posts.rb

package info (click to toggle)
jekyll 2.2.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,908 kB
  • ctags: 687
  • sloc: ruby: 6,811; sh: 121; xml: 106; makefile: 35
file content (47 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'helper'

class TestRelatedPosts < Test::Unit::TestCase
  context "building related posts without lsi" do
    setup do
      stub(Jekyll).configuration do
        Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir,
                                               'destination' => dest_dir})
      end
      @site = Site.new(Jekyll.configuration)
    end

    should "use the most recent posts for related posts" do
      @site.reset
      @site.read

      last_post     = @site.posts.last
      related_posts = Jekyll::RelatedPosts.new(last_post).build

      last_10_recent_posts = (@site.posts.reverse - [last_post]).first(10)
      assert_equal last_10_recent_posts, related_posts
    end
  end

  context "building related posts with lsi" do
    setup do
      stub(Jekyll).configuration do
        Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir,
                                               'destination' => dest_dir,
                                               'lsi' => true})
      end
      any_instance_of(Jekyll::RelatedPosts) { |i| stub(i).display }
      @site = Site.new(Jekyll.configuration)
    end

    should "use lsi for the related posts" do
      @site.reset
      @site.read
      require 'classifier'
      any_instance_of(::Classifier::LSI) do |c|
        stub(c).find_related { @site.posts[-1..-9] }
        stub(c).build_index
      end
      assert_equal @site.posts[-1..-9], Jekyll::RelatedPosts.new(@site.posts.last).build
    end
  end
end