瀏覽代碼

Update URL stubs

Thibaut Courouble 9 年之前
父節點
當前提交
adba5c1cac
共有 3 個文件被更改,包括 4 次插入34 次删除
  1. 0 24
      lib/docs/core/scraper.rb
  2. 1 5
      lib/docs/scrapers/angular.rb
  3. 3 5
      lib/docs/scrapers/dojo.rb

+ 0 - 24
lib/docs/core/scraper.rb

@@ -188,30 +188,6 @@ module Docs
       @pipeline = nil
     end
 
-    module StubRootPage
-      private
-
-      def request_one(url)
-        stub_root_page if url == root_url.to_s
-        super
-      end
-
-      def request_all(urls, &block)
-        stub_root_page
-        super
-      end
-
-      def stub_root_page
-        response = Typhoeus::Response.new(
-          effective_url: root_url.to_s,
-          code: 200,
-          headers: { 'Content-Type' => 'text/html' },
-          body: root_page_body)
-
-        Typhoeus.stub(root_url.to_s).and_return(response)
-      end
-    end
-
     module FixInternalUrlsBehavior
       def self.included(base)
         base.extend ClassMethods

+ 1 - 5
lib/docs/scrapers/angular.rb

@@ -1,7 +1,5 @@
 module Docs
   class Angular < UrlScraper
-    include StubRootPage
-
     self.name = 'Angular.js'
     self.slug = 'angular'
     self.type = 'angular'
@@ -59,9 +57,7 @@ module Docs
       self.base_url = "https://code.angularjs.org/#{release}/docs/partials/"
     end
 
-    private
-
-    def root_page_body
+    stub '' do
       require 'capybara/dsl'
       Capybara.current_driver = :selenium
       Capybara.run_server = false

+ 3 - 5
lib/docs/scrapers/dojo.rb

@@ -2,8 +2,6 @@ require 'yajl/json_gem'
 
 module Docs
   class Dojo < UrlScraper
-    include StubRootPage
-
     self.type = 'dojo'
     self.release = '1.10'
     self.base_url = "http://dojotoolkit.org/api/#{release}/"
@@ -31,15 +29,15 @@ module Docs
       Licensed under the AFL 2.1 and BSD 3-Clause licenses.
     HTML
 
-    private
-
-    def root_page_body
+    stub '' do
       response = request_one("#{self.base_url}tree.json")
       json = JSON.parse(response.body)
       urls = get_url_list(json)
       urls.map { |url| "<a href='#{url}'>#{url}</a>" }.join
     end
 
+    private
+
     def get_url_list(json, set = Set.new)
       set.add("#{self.class.base_url}#{json['fullname']}.html?xhr=true")
       json['children'].each { |child| get_url_list(child, set) } if json['children']