Browse Source

Add VCR to fetcher and scraper specs

master
Dylan Baker 2 years ago
parent
commit
db3bdae43f
2 changed files with 17 additions and 11 deletions
  1. 14
    10
      spec/fetcher_spec.rb
  2. 3
    1
      spec/scraper_spec.rb

+ 14
- 10
spec/fetcher_spec.rb View File

10
 
10
 
11
   describe '#thread' do
11
   describe '#thread' do
12
     it "fetches a thread" do
12
     it "fetches a thread" do
13
-      result = subject.thread({ remote_id: 49668 })
14
-      aggregate_failures do
15
-        expect(result).to be_a(Nokogiri::HTML::Document)
16
-        expect(result.at_css('.post:first-child').text)
17
-          .to include('reddwarf posted this March 30th, 2020 @ 3:29:23 am')
13
+      VCR.use_cassette "fetch_a_thread" do
14
+        result = subject.thread({ remote_id: 49668 })
15
+        aggregate_failures do
16
+          expect(result).to be_a(Nokogiri::HTML::Document)
17
+          expect(result.at_css('.post:first-child').text)
18
+            .to include('reddwarf posted this March 30th, 2020 @ 3:29:23 am')
19
+        end
18
       end
20
       end
19
     end
21
     end
20
   end
22
   end
21
 
23
 
22
   describe '#page' do
24
   describe '#page' do
23
     it "fetches a page of threads" do
25
     it "fetches a page of threads" do
24
-      result = subject.page(0)
25
-      aggregate_failures do
26
-        expect(result).to be_a(Nokogiri::HTML::Document)
27
-        expect(result.at_css('h3').text).to eq('VLV: politics, food, and aging')
28
-        expect(result.css('.even, .odd').length).to eq(110)
26
+      VCR.use_cassette "fetch_a_page_of_threads" do
27
+        result = subject.page(0)
28
+        aggregate_failures do
29
+          expect(result).to be_a(Nokogiri::HTML::Document)
30
+          expect(result.at_css('h3').text).to eq('VLV: politics, food, and aging')
31
+          expect(result.css('.even, .odd').length).to eq(110)
32
+        end
29
       end
33
       end
30
     end
34
     end
31
   end
35
   end

+ 3
- 1
spec/scraper_spec.rb View File

12
 
12
 
13
   describe '#initialize' do
13
   describe '#initialize' do
14
     it 'authenticates' do
14
     it 'authenticates' do
15
-      expect(subject.send(:cookie)).to_not be_nil
15
+      VCR.use_cassette "authentication" do
16
+        expect(subject.send(:cookie)).to_not be_nil
17
+      end
16
     end
18
     end
17
   end
19
   end
18
 
20
 

Loading…
Cancel
Save