-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog_post_spec.rb
125 lines (96 loc) · 4.1 KB
/
blog_post_spec.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# frozen_string_literal: true
require "spec_helper"
RSpec.describe GoldMiner::BlogPost do
describe "#to_s" do
it "creates a blogpost from a list of gold nuggets" do
travel_to "2022-10-07" do
author1 = TestFactories.create_author(name: "John Doe", id: "john.doe", link: "https://example.com/john.doe")
author2 = TestFactories.create_author(name: "Jane Smith", id: "jane.smith", link: "https://example.com/jane.smith")
gold_nuggets = [
TestFactories.create_gold_nugget(content: "TIL 1", author: author1, source: "http://permalink-1.com"),
TestFactories.create_gold_nugget(content: "TIL 2", author: author2, source: "http://permalink-2.com"),
TestFactories.create_gold_nugget(content: "Tip 1", author: author1, source: "http://permalink-3.com")
]
blogpost = GoldMiner::BlogPost.new(slack_channel: "design", gold_nuggets: gold_nuggets, since: "2022-09-30")
result = blogpost.to_s
expect(result).to eq <<~MARKDOWN
---
title: "This week in #design (Sep 30, 2022)"
tags: this week in design, til, tip
teaser: >
Highlights of what happened in our #design channel on Slack this week.
author: Matheus Richard
auto_social_share: true
---
Welcome to another edition of [This Week in #dev](https://thoughtbot.com/blog/tags/this-week-in-dev),
a series of posts where we bring some of our most interesting Slack
conversations to the public.
## http://permalink-1.com
TIL 1
## http://permalink-2.com
TIL 2
## http://permalink-3.com
Tip 1
## Thanks
This edition was brought to you by [Jane Smith][jane.smith] and [John Doe][john.doe]. Thanks to all contributors! 🎉
MARKDOWN
end
end
it "creates a blog post asynchronously" do
sleep_writer = Class.new do
def initialize(seconds_of_sleep:)
@seconds_of_sleep = seconds_of_sleep
end
def extract_topics_from(message)
sleep @seconds_of_sleep
["test", "test2"]
end
def give_title_to(message)
sleep @seconds_of_sleep
"test"
end
def summarize(message)
sleep @seconds_of_sleep
"test"
end
end
author1 = TestFactories.create_author(name: "John Doe", id: "john.doe", link: "https://example.com/john.doe")
author2 = TestFactories.create_author(name: "Jane Smith", id: "jane.smith", link: "https://example.com/jane.smith")
gold_nuggets = [
TestFactories.create_gold_nugget(content: "TIL 1", author: author1, source: "http://permalink-1.com"),
TestFactories.create_gold_nugget(content: "TIL 2", author: author2, source: "http://permalink-2.com")
]
seconds_of_sleep = 0.5
blogpost = GoldMiner::BlogPost.new(
slack_channel: "design",
gold_nuggets: gold_nuggets,
since: "2022-09-30",
writer: sleep_writer.new(seconds_of_sleep: seconds_of_sleep)
)
t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
result = blogpost.to_s
elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0
overhead = 0.1
expect(elapsed_time).to be_between(seconds_of_sleep, seconds_of_sleep + overhead)
expect(result).to eq <<~MARKDOWN
---
title: "This week in #design (Sep 30, 2022)"
tags: this week in design, test, test2
teaser: >
Highlights of what happened in our #design channel on Slack this week.
author: Matheus Richard
auto_social_share: true
---
Welcome to another edition of [This Week in #dev](https://thoughtbot.com/blog/tags/this-week-in-dev),
a series of posts where we bring some of our most interesting Slack
conversations to the public.
## test
test
## test
test
## Thanks
This edition was brought to you by [Jane Smith][jane.smith] and [John Doe][john.doe]. Thanks to all contributors! 🎉
MARKDOWN
end
end
end