Set the default FileScraper::base_url to localhost

pull/15/head
Thibaut 11 years ago
parent 5c4775201b
commit 9089d03211

@ -4,16 +4,23 @@ module Docs
class << self
attr_accessor :dir
def inherited(subclass)
super
subclass.base_url = base_url
end
end
self.base_url = 'http://localhost/'
private
def request_one(url)
Response.new read_file(file_path_for(url)), URL.parse(url)
end
def request_all(start_url)
queue = [start_url]
def request_all(url)
queue = [url]
until queue.empty?
result = yield request_one(queue.shift)
queue.concat(result) if result.is_a? Array

@ -3,8 +3,7 @@ require 'docs'
class FileScraperTest < MiniTest::Spec
class Scraper < Docs::FileScraper
self.dir = '/dir'
self.base_url = 'http://example.com'
self.dir = '/'
self.html_filters = Docs::FilterStack.new
self.text_filters = Docs::FilterStack.new
end
@ -17,19 +16,30 @@ class FileScraperTest < MiniTest::Spec
OpenStruct.new body: 'body', url: Docs::URL.parse(Scraper.base_url)
end
describe ".inherited" do
it "sets .base_url" do
assert_equal Scraper.base_url, Class.new(Scraper).base_url
end
end
describe "#request_one" do
let :url do
File.join(Scraper.base_url, 'path')
let :path do
File.join(Scraper.dir, 'path')
end
let :result do
scraper.send :request_one, url
scraper.send :request_one, path
end
before do
stub(scraper).read_file
end
it "reads a file" do
mock(scraper).read_file(path)
result
end
describe "the returned response object" do
it "has a #body" do
stub(scraper).read_file { 'body' }
@ -37,15 +47,10 @@ class FileScraperTest < MiniTest::Spec
end
it "has a #url" do
assert_equal url, result.url.to_s
assert_equal path, result.url.to_s
assert_instance_of Docs::URL, result.url
end
end
it "reads .dir/path when the url is .base_url/path" do
stub(scraper).read_file(File.join(Scraper.dir, 'path')) { 'test' }
assert_equal 'test', result.body
end
end
describe "#request_all" do

Loading…
Cancel
Save