Refactor StubRootPage

pull/200/head
Thibaut 10 years ago
parent e52bbcd64c
commit 9ecb1f9498

@ -149,5 +149,29 @@ module Docs
def parse(string)
Parser.new(string).html
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
end
end

@ -1,5 +1,7 @@
module Docs
class Angular < UrlScraper
include StubRootPage
self.name = 'Angular.js'
self.slug = 'angular'
self.type = 'angular'
@ -28,27 +30,7 @@ module Docs
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: get_root_page_body)
Typhoeus.stub(root_url.to_s).and_return(response)
end
def get_root_page_body
def root_page_body
require 'capybara'
Capybara.current_driver = :selenium
Capybara.visit("https://code.angularjs.org/#{self.class.version}/docs/api")

@ -1,5 +1,7 @@
module Docs
class Meteor < UrlScraper
include StubRootPage
self.type = 'meteor'
self.version = '1.1.0'
self.base_url = 'http://docs.meteor.com'
@ -21,27 +23,7 @@ module Docs
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: get_root_page_body)
Typhoeus.stub(root_url.to_s).and_return(response)
end
def get_root_page_body
def root_page_body
require 'capybara'
Capybara.current_driver = :selenium
Capybara.visit(root_url.to_s)

Loading…
Cancel
Save