Browse Source

Add a test for parsing

master
Dylan Baker 4 months ago
parent
commit
3c82d382ef
1 changed files with 47 additions and 0 deletions
  1. 47
    0
      spec/parser_spec.rb

+ 47
- 0
spec/parser_spec.rb View File

@@ -0,0 +1,47 @@
1
+require_relative '../lib/parse'
2
+
3
+RSpec.describe 'Parser' do
4
+  it 'should parse threads' do
5
+    html = Nokogiri::HTML(<<~HTML)
6
+      <div class="even" id="thread_12345">
7
+        <ul class="list read">
8
+          <li class="member">
9
+            <span>Thread By: </span>
10
+            <a href="/member/view/creator1/" class="memberlink">creator1</a>
11
+          </li>
12
+          <li class="subject">
13
+            <span>Subject: </span>
14
+            <a href="/thread/view/12345/&p=999">
15
+              <strong>Sticky:</sticky> Thread title 1
16
+            </a>
17
+          </li>
18
+          <li class="posts"><span>Posts: </span>999</li>
19
+          <li class="lastpost">
20
+            <span>Last Post By:</span>
21
+            <a href="/member/view/lastposter1/" class="memberlink">lastposter1</a> on Fri&nbsp;Apr&nbsp;10&nbsp;2020&nbsp;01:23&nbsp;am</li>
22
+        </ul>
23
+      </div>
24
+      <div class="even" id="thread_123456">
25
+        <ul class="list read">
26
+          <li class="member">
27
+            <span>Thread By: </span>
28
+            <a href="/member/view/creator2/" class="memberlink">creator2</a>
29
+          </li>
30
+          <li class="subject">
31
+            <span>Subject: </span>
32
+            <a href="/thread/view/123456/&p=999">Thread title 2</a>
33
+          </li>
34
+          <li class="posts"><span>Posts: </span>999</li>
35
+          <li class="lastpost">
36
+            <span>Last Post By:</span>
37
+            <a href="/member/view/lastposter2/" class="memberlink">lastposter2</a> on Fri&nbsp;Apr&nbsp;10&nbsp;2020&nbsp;01:23&nbsp;am</li>
38
+        </ul>
39
+      </div>
40
+    HTML
41
+
42
+    expect(Parse.threads(html)).to eq([
43
+      {remote_id: '12345', title: 'Sticky: Thread title 1', creator: 'creator1', is_sticky: true},
44
+      {remote_id: '123456', title: 'Thread title 2', creator: 'creator2', is_sticky: false},
45
+    ])
46
+  end
47
+end

Loading…
Cancel
Save