| @@ -3,8 +3,7 @@ require 'docs' · 2 unmodified lines |
| 3 | | 3 | |
| 4 | class FileScraperTest < MiniTest::Spec | 4 | class FileScraperTest < MiniTest::Spec |
| 5 | class Scraper < Docs::FileScraper | 5 | class Scraper < Docs::FileScraper |
| 6 | self.dir = '/dir' | 6 | self.dir = '/' |
| 7 | self.base_url = 'http://example.com' | | |
| 8 | self.html_filters = Docs::FilterStack.new | 7 | self.html_filters = Docs::FilterStack.new |
| 9 | self.text_filters = Docs::FilterStack.new | 8 | self.text_filters = Docs::FilterStack.new |
| 10 | end | 9 | end |
| @@ -17,19 +16,30 @@ class FileScraperTest < MiniTest::Spec · 6 unmodified lines |
| 17 | OpenStruct.new body: 'body', url: Docs::URL.parse(Scraper.base_url) | 16 | OpenStruct.new body: 'body', url: Docs::URL.parse(Scraper.base_url) |
| 18 | end | 17 | end |
| 19 | | 18 | |
| | 19 | describe ".inherited" do |
| | 20 | it "sets .base_url" do |
| | 21 | assert_equal Scraper.base_url, Class.new(Scraper).base_url |
| | 22 | end |
| | 23 | end |
| | 24 | |
| 20 | describe "#request_one" do | 25 | describe "#request_one" do |
| 21 | let :url do | 26 | let :path do |
| 22 | File.join(Scraper.base_url, 'path') | 27 | File.join(Scraper.dir, 'path') |
| 23 | end | 28 | end |
| 24 | | 29 | |
| 25 | let :result do | 30 | let :result do |
| 26 | scraper.send :request_one, url | 31 | scraper.send :request_one, path |
| 27 | end | 32 | end |
| 28 | | 33 | |
| 29 | before do | 34 | before do |
| 30 | stub(scraper).read_file | 35 | stub(scraper).read_file |
| 31 | end | 36 | end |
| 32 | | 37 | |
| | 38 | it "reads a file" do |
| | 39 | mock(scraper).read_file(path) |
| | 40 | result |
| | 41 | end |
| | 42 | |
| 33 | describe "the returned response object" do | 43 | describe "the returned response object" do |
| 34 | it "has a #body" do | 44 | it "has a #body" do |
| 35 | stub(scraper).read_file { 'body' } | 45 | stub(scraper).read_file { 'body' } |
| @@ -37,15 +47,10 @@ class FileScraperTest < MiniTest::Spec · 1 unmodified line |
| 37 | end | 47 | end |
| 38 | | 48 | |
| 39 | it "has a #url" do | 49 | it "has a #url" do |
| 40 | assert_equal url, result.url.to_s | 50 | assert_equal path, result.url.to_s |
| 41 | assert_instance_of Docs::URL, result.url | 51 | assert_instance_of Docs::URL, result.url |
| 42 | end | 52 | end |
| 43 | end | 53 | end |
| 44 | | | |
| 45 | it "reads .dir/path when the url is .base_url/path" do | | |
| 46 | stub(scraper).read_file(File.join(Scraper.dir, 'path')) { 'test' } | | |
| 47 | assert_equal 'test', result.body | | |
| 48 | end | | |
| 49 | end | 54 | end |
| 50 | | 55 | |
| 51 | describe "#request_all" do | 56 | describe "#request_all" do |