File: test_spider.rb

package info (click to toggle)
ruby-spider 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 252 kB
  • sloc: ruby: 1,125; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 983 bytes parent folder | download
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
require_relative 'test_helper'
local_require 'spider'

class TestSpider < Minitest::Test
  def test_should_find_two_pages_without_cycles_using_defaults
    u = []
    with_web_server(LoopingServlet) do
      u = find_pages_with_static_server
    end
    assert_equal static_server_pages, u
  end

  def test_should_find_two_pages_without_cycles_using_memcached
    u = []
    with_web_server(LoopingServlet) do
      with_memcached do
        # Use mock memcached for fast, reliable testing
        memcached_client = MockIncludedInMemcached.new('localhost:11211')
        
        u = find_pages_with_static_server do |s|
          s.check_already_seen_with memcached_client
        end
      end
    end
    assert_equal static_server_pages, u
  end

  private

  def find_pages_with_static_server(&block)
    pages = []
    Spider.start_at('http://localhost:8888/') do |s|
      block.call(s) unless block.nil?
      s.on(:every){ |u,r,p| pages << u }
    end
    pages
  end
end