~ubuntu-branches/ubuntu/trusty/ruby-webrobots/trusty

« back to all changes in this revision

Viewing changes to .pc/disable-internet-tests/test/test_webrobots.rb

  • Committer: Package Import Robot
  • Author(s): Gunnar Wolf
  • Date: 2013-09-30 17:11:41 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130930171141-q3jdhc7nzot7lj3n
Tags: 0.1.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
384
384
Option2: Hello
385
385
Crawl-Delay: 1.5
386
386
 
 
387
User-Agent: HerBot
 
388
Disallow: /2heavy/
 
389
Allow: /2heavy/*.html
 
390
Option1: Baz
 
391
Option2: Qux
 
392
 
387
393
User-Agent: *
388
394
Disallow: /2heavy/
389
395
Allow: /2heavy/*.html
400
406
      }
401
407
 
402
408
      @robots_mybot = WebRobots.new('MyBot', :http_get => http_get)
 
409
      @robots_mybot_ignore = WebRobots.new('MyBot', :http_get => http_get, :crawl_delay => :ignore)
 
410
      @robots_mybot_custom = WebRobots.new('MyBot', :http_get => http_get, :crawl_delay => proc { |*args| @delay_args = args })
 
411
      @robots_herbot = WebRobots.new('HerBot', :http_get => http_get)
403
412
      @robots_hisbot = WebRobots.new('HisBot', :http_get => http_get)
404
413
    end
405
414
 
411
420
      assert_equal 'Hello', @robots_mybot.option('http://www.example.org/', 'Option2')
412
421
      assert_equal 'Hello', options['option2']
413
422
 
 
423
      options = @robots_mybot_ignore.options('http://www.example.org/')
 
424
      assert_equal 2, options.size
 
425
      assert_equal 'Foo',   @robots_mybot_ignore.option('http://www.example.org/', 'Option1')
 
426
      assert_equal 'Foo',   options['option1']
 
427
      assert_equal 'Hello', @robots_mybot_ignore.option('http://www.example.org/', 'Option2')
 
428
      assert_equal 'Hello', options['option2']
 
429
 
 
430
      options = @robots_mybot_custom.options('http://www.example.org/')
 
431
      assert_equal 2, options.size
 
432
      assert_equal 'Foo',   @robots_mybot_custom.option('http://www.example.org/', 'Option1')
 
433
      assert_equal 'Foo',   options['option1']
 
434
      assert_equal 'Hello', @robots_mybot_custom.option('http://www.example.org/', 'Option2')
 
435
      assert_equal 'Hello', options['option2']
 
436
 
 
437
      options = @robots_herbot.options('http://www.example.org/')
 
438
      assert_equal 2, options.size
 
439
      assert_equal 'Baz',   @robots_herbot.option('http://www.example.org/', 'Option1')
 
440
      assert_equal 'Baz',   options['option1']
 
441
      assert_equal 'Qux',    @robots_herbot.option('http://www.example.org/', 'Option2')
 
442
      assert_equal 'Qux',    options['option2']
 
443
 
414
444
      options = @robots_hisbot.options('http://www.example.org/')
415
445
      assert_equal 2, options.size
416
446
      assert_equal 'Bar',   @robots_hisbot.option('http://www.example.org/', 'Option1')
425
455
      assert_equal %w[
426
456
        http://www.example.org/sitemap-host1.xml
427
457
        http://www.example.org/sitemap-host2.xml
 
458
      ], @robots_mybot_ignore.sitemaps('http://www.example.org/')
 
459
      assert_equal %w[
 
460
        http://www.example.org/sitemap-host1.xml
 
461
        http://www.example.org/sitemap-host2.xml
 
462
      ], @robots_herbot.sitemaps('http://www.example.org/')
 
463
      assert_equal %w[
 
464
        http://www.example.org/sitemap-host1.xml
 
465
        http://www.example.org/sitemap-host2.xml
428
466
      ], @robots_hisbot.sitemaps('http://www.example.org/')
429
467
 
 
468
      assert_equal 1.5, @robots_mybot.crawl_delay('http://www.example.org/')
 
469
      assert_equal 1.5, @robots_mybot_ignore.crawl_delay('http://www.example.org/')
 
470
      assert_equal 1.5, @robots_mybot_custom.crawl_delay('http://www.example.org/')
 
471
      assert_equal 0, @robots_herbot.crawl_delay('http://www.example.org/')
 
472
      assert_equal 0, @robots_hisbot.crawl_delay('http://www.example.org/')
 
473
 
430
474
      t1 = Time.now
431
475
      @robots_mybot.allowed?('http://www.example.org/')
432
476
      @robots_mybot.allowed?('http://www.example.org/article1.html')
435
479
      @robots_mybot.allowed?('http://www.example.org/article2.html')
436
480
      t3 = Time.now
437
481
      assert_in_delta 1.5, t3 - t2, 0.1
 
482
 
 
483
      t1 = Time.now
 
484
      @robots_mybot_ignore.allowed?('http://www.example.org/')
 
485
      @robots_mybot_ignore.allowed?('http://www.example.org/article1.html')
 
486
      t2 = Time.now
 
487
      assert_in_delta 0, t2 - t1, 0.1
 
488
      @robots_mybot_ignore.allowed?('http://www.example.org/article2.html')
 
489
      t3 = Time.now
 
490
      assert_in_delta 0, t3 - t2, 0.1
 
491
 
 
492
      t1 = Time.now
 
493
      @robots_mybot_custom.allowed?('http://www.example.org/')
 
494
      @robots_mybot_custom.allowed?('http://www.example.org/article1.html')
 
495
      t2 = Time.now
 
496
      assert_in_delta 0, t2 - t1, 0.1
 
497
      assert_instance_of Array, @delay_args
 
498
      assert_equal 2, @delay_args.size
 
499
      assert_equal 1.5, @delay_args[0]
 
500
      assert_instance_of Time, @delay_args[1]
438
501
    end
439
502
  end
440
503