Browse Source

Specs

master
Dylan Baker 2 years ago
parent
commit
ed3e225aba
6 changed files with 66 additions and 2 deletions
  1. 1
    0
      .gitignore
  2. 2
    1
      Gemfile
  3. 14
    0
      Gemfile.lock
  4. 9
    1
      Rakefile
  5. 28
    0
      spec/scraper_spec.rb
  6. 12
    0
      spec/spec_helper.rb

+ 1
- 0
.gitignore View File

3
 web/public/*.css
3
 web/public/*.css
4
 web/public/*.js
4
 web/public/*.js
5
 db/log
5
 db/log
6
+spec/vcr

+ 2
- 1
Gemfile View File

13
 gem 'sassc', '~> 2.2'
13
 gem 'sassc', '~> 2.2'
14
 gem 'sequel', '~> 5.30'
14
 gem 'sequel', '~> 5.30'
15
 gem 'sinatra', '~> 2.0'
15
 gem 'sinatra', '~> 2.0'
16
-
17
 gem "truncato", "~> 0.7.11"
16
 gem "truncato", "~> 0.7.11"
17
+gem "vcr", "~> 6.0"
18
+gem "webmock", "~> 3.14"

+ 14
- 0
Gemfile.lock View File

1
 GEM
1
 GEM
2
   remote: https://rubygems.org/
2
   remote: https://rubygems.org/
3
   specs:
3
   specs:
4
+    addressable (2.8.0)
5
+      public_suffix (>= 2.0.2, < 5.0)
6
+    crack (0.4.5)
7
+      rexml
4
     diff-lcs (1.3)
8
     diff-lcs (1.3)
5
     dotenv (2.7.5)
9
     dotenv (2.7.5)
6
     ffi (1.12.2)
10
     ffi (1.12.2)
11
+    hashdiff (1.0.1)
7
     htmlentities (4.3.4)
12
     htmlentities (4.3.4)
8
     httparty (0.18.0)
13
     httparty (0.18.0)
9
       mime-types (~> 3.0)
14
       mime-types (~> 3.0)
18
     nokogiri (1.10.9)
23
     nokogiri (1.10.9)
19
       mini_portile2 (~> 2.4.0)
24
       mini_portile2 (~> 2.4.0)
20
     pg (1.2.3)
25
     pg (1.2.3)
26
+    public_suffix (4.0.6)
21
     rack (2.2.2)
27
     rack (2.2.2)
22
     rack-protection (2.0.8.1)
28
     rack-protection (2.0.8.1)
23
       rack
29
       rack
24
     rake (13.0.1)
30
     rake (13.0.1)
31
+    rexml (3.2.5)
25
     rspec (3.9.0)
32
     rspec (3.9.0)
26
       rspec-core (~> 3.9.0)
33
       rspec-core (~> 3.9.0)
27
       rspec-expectations (~> 3.9.0)
34
       rspec-expectations (~> 3.9.0)
48
     truncato (0.7.11)
55
     truncato (0.7.11)
49
       htmlentities (~> 4.3.1)
56
       htmlentities (~> 4.3.1)
50
       nokogiri (>= 1.7.0, <= 2.0)
57
       nokogiri (>= 1.7.0, <= 2.0)
58
+    vcr (6.0.0)
59
+    webmock (3.14.0)
60
+      addressable (>= 2.8.0)
61
+      crack (>= 0.3.2)
62
+      hashdiff (>= 0.4.0, < 2.0.0)
51
 
63
 
52
 PLATFORMS
64
 PLATFORMS
53
   ruby
65
   ruby
64
   sequel (~> 5.30)
76
   sequel (~> 5.30)
65
   sinatra (~> 2.0)
77
   sinatra (~> 2.0)
66
   truncato (~> 0.7.11)
78
   truncato (~> 0.7.11)
79
+  vcr (~> 6.0)
80
+  webmock (~> 3.14)
67
 
81
 
68
 BUNDLED WITH
82
 BUNDLED WITH
69
    2.1.4
83
    2.1.4

+ 9
- 1
Rakefile View File

15
 task 'migrate_test' do
15
 task 'migrate_test' do
16
   require_relative './db/migrate'
16
   require_relative './db/migrate'
17
 
17
 
18
+  TEST_DB = Sequel.connect(
19
+    adapter: :postgres,
20
+    database: ENV['DB_DATABASE'] + '_test',
21
+    user: ENV['DB_USERNAME'],
22
+    password: ENV['DB_PASSWORD'],
23
+    logger: ENV['APP_ENV'] == 'development' ? Logger.new('db/log') : nil
24
+  )
25
+
18
   migrate(db: TEST_DB)
26
   migrate(db: TEST_DB)
19
 end
27
 end
20
 
28
 
21
 task 'scrape' do
29
 task 'scrape' do
22
-  require_relative './db/scrape'
30
+  require_relative './db/scraper'
23
 
31
 
24
   should_log = ENV['APP_ENV'] == 'development' || ARGV.include?('--log')
32
   should_log = ENV['APP_ENV'] == 'development' || ARGV.include?('--log')
25
   scraper = Scraper.new(log: should_log)
33
   scraper = Scraper.new(log: should_log)

+ 28
- 0
spec/scraper_spec.rb View File

1
+require 'dotenv/load'
2
+require 'spec_helper'
3
+
4
+require_relative '../db/scraper'
5
+
6
+RSpec.describe Scraper do
7
+  around(:each) do |example|
8
+    DB.transaction(rollback: :always, auto_savepoint: true) { example.run }
9
+  end
10
+
11
+  subject { described_class.new(log: true) }
12
+
13
+  describe '#initialize' do
14
+    it 'authenticates' do
15
+      expect(subject.send(:cookie)).to_not be_nil
16
+    end
17
+  end
18
+
19
+  describe '#scrape' do
20
+    it 'creates new threads and posts' do
21
+      VCR.use_cassette "create_new_threads_and_posts" do
22
+        expect { subject.scrape }
23
+          .to  change { VLV::Thread.count }.by(109)
24
+          .and change { VLV::Post.count   }.by_at_least(5000)
25
+      end
26
+    end
27
+  end
28
+end

+ 12
- 0
spec/spec_helper.rb View File

1
+require 'vcr'
2
+require "webmock/rspec"
3
+
4
+ENV["DB_DATABASE"] = ENV["DB_DATABASE"] + '_test'
5
+
6
+WebMock.disable_net_connect!(allow_localhost: true)
7
+
8
+VCR.configure do |c|
9
+  c.cassette_library_dir = "spec/vcr"
10
+  c.hook_into :webmock
11
+  c.ignore_localhost = true
12
+end

Loading…
Cancel
Save