forked from jekyll/jekyll
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_related_posts.rb
66 lines (53 loc) · 1.93 KB
/
test_related_posts.rb
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true
require "helper"
class TestRelatedPosts < JekyllUnitTest
context "building related posts without lsi" do
setup do
@site = fixture_site
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_ten_recent_posts = (@site.posts.docs.reverse - [last_post]).first(10)
assert_equal last_ten_recent_posts, related_posts
end
end
context "building related posts with LSI" do
setup do
if jruby?
skip(
"JRuby does not perform well with CExt, test disabled."
)
end
allow_any_instance_of(Jekyll::RelatedPosts).to receive(:display)
@site = fixture_site(
"lsi" => true
)
@site.reset
@site.read
require "classifier-reborn"
Jekyll::RelatedPosts.lsi = nil
end
should "index Jekyll::Post objects" do
@site.posts.docs = @site.posts.docs.first(1)
expect_any_instance_of(::ClassifierReborn::LSI).to \
receive(:add_item).with(kind_of(Jekyll::Document))
Jekyll::RelatedPosts.new(@site.posts.last).build_index
end
should "find related Jekyll::Post objects, given a Jekyll::Post object" do
post = @site.posts.last
allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index)
expect_any_instance_of(::ClassifierReborn::LSI).to \
receive(:find_related).with(post, 11).and_return(@site.posts[-1..-9])
Jekyll::RelatedPosts.new(post).build
end
should "use LSI for the related posts" do
allow_any_instance_of(::ClassifierReborn::LSI).to \
receive(:find_related).and_return(@site.posts[-1..-9])
allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index)
assert_equal @site.posts[-1..-9], Jekyll::RelatedPosts.new(@site.posts.last).build
end
end
end