renames rake task update_spec_cases to specs:update
This commit is contained in:
parent
92048366d1
commit
711adc6e5e
2 changed files with 47 additions and 45 deletions
|
@ -70,7 +70,7 @@ If you find bugs, have feature requests or questions, please
|
||||||
To update spec cases that are scraped from other sites.
|
To update spec cases that are scraped from other sites.
|
||||||
**Warning:** This could break specs.
|
**Warning:** This could break specs.
|
||||||
```bash
|
```bash
|
||||||
rake update_spec_cases
|
rake specs:update
|
||||||
```
|
```
|
||||||
|
|
||||||
To run specs
|
To run specs
|
||||||
|
|
90
Rakefile
90
Rakefile
|
@ -3,57 +3,59 @@ require "nokogiri"
|
||||||
require "open-uri"
|
require "open-uri"
|
||||||
require "pp"
|
require "pp"
|
||||||
|
|
||||||
task :update_spec_cases do
|
namespace :specs do
|
||||||
sources = [
|
task :update do
|
||||||
{ urls: ["http://microformats.org/wiki/microformats-2"],
|
sources = [
|
||||||
html_selector: ".source-html4strict",
|
{ urls: ["http://microformats.org/wiki/microformats-2"],
|
||||||
json_selector: ".source-javascript",
|
html_selector: ".source-html4strict",
|
||||||
html_method: "inner_text"
|
json_selector: ".source-javascript",
|
||||||
},
|
html_method: "inner_text"
|
||||||
{ urls: [
|
},
|
||||||
"http://microformat2-node.jit.su/h-adr.html",
|
{ urls: [
|
||||||
"http://microformat2-node.jit.su/h-card.html",
|
"http://microformat2-node.jit.su/h-adr.html",
|
||||||
"http://microformat2-node.jit.su/h-entry.html",
|
"http://microformat2-node.jit.su/h-card.html",
|
||||||
"http://microformat2-node.jit.su/h-event.html",
|
"http://microformat2-node.jit.su/h-entry.html",
|
||||||
"http://microformat2-node.jit.su/h-geo.html",
|
"http://microformat2-node.jit.su/h-event.html",
|
||||||
"http://microformat2-node.jit.su/h-news.html",
|
"http://microformat2-node.jit.su/h-geo.html",
|
||||||
"http://microformat2-node.jit.su/h-org.html",
|
"http://microformat2-node.jit.su/h-news.html",
|
||||||
"http://microformat2-node.jit.su/h-product.html",
|
"http://microformat2-node.jit.su/h-org.html",
|
||||||
"http://microformat2-node.jit.su/h-recipe.html",
|
"http://microformat2-node.jit.su/h-product.html",
|
||||||
"http://microformat2-node.jit.su/h-resume.html",
|
"http://microformat2-node.jit.su/h-recipe.html",
|
||||||
"http://microformat2-node.jit.su/h-review-aggregate.html",
|
"http://microformat2-node.jit.su/h-resume.html",
|
||||||
"http://microformat2-node.jit.su/h-review.html",
|
"http://microformat2-node.jit.su/h-review-aggregate.html",
|
||||||
"http://microformat2-node.jit.su/rel.html",
|
"http://microformat2-node.jit.su/h-review.html",
|
||||||
"http://microformat2-node.jit.su/includes.html",
|
"http://microformat2-node.jit.su/rel.html",
|
||||||
],
|
"http://microformat2-node.jit.su/includes.html",
|
||||||
html_selector: ".e-x-microformat",
|
],
|
||||||
json_selector: ".language-json",
|
html_selector: ".e-x-microformat",
|
||||||
html_method: "inner_html"
|
json_selector: ".language-json",
|
||||||
}
|
html_method: "inner_html"
|
||||||
]
|
}
|
||||||
|
]
|
||||||
|
|
||||||
sources.each do |source|
|
sources.each do |source|
|
||||||
source[:urls].each do |url|
|
source[:urls].each do |url|
|
||||||
document = Nokogiri::HTML(open(url).read)
|
document = Nokogiri::HTML(open(url).read)
|
||||||
html = document.css(source[:html_selector]).map { |e| e.send(source[:html_method]) }
|
html = document.css(source[:html_selector]).map { |e| e.send(source[:html_method]) }
|
||||||
json = document.css(source[:json_selector]).map { |e| e.inner_text }
|
json = document.css(source[:json_selector]).map { |e| e.inner_text }
|
||||||
|
|
||||||
filename = url.split("/").last.gsub(/[.]\w+/, "")
|
filename = url.split("/").last.gsub(/[.]\w+/, "")
|
||||||
filepath = "spec/support/cases/"
|
filepath = "spec/support/cases/"
|
||||||
|
|
||||||
([html.length, json.length].min).times do |index|
|
([html.length, json.length].min).times do |index|
|
||||||
|
|
||||||
File.open("#{filepath}#{filename}-#{index}.html", "w") do |f|
|
File.open("#{filepath}#{filename}-#{index}.html", "w") do |f|
|
||||||
f.write "<!-- #{url} -->\n"
|
f.write "<!-- #{url} -->\n"
|
||||||
f.write html[index]
|
f.write html[index]
|
||||||
|
end
|
||||||
|
|
||||||
|
File.open("#{filepath}#{filename}-#{index}.js", "w") do |f|
|
||||||
|
f.write "// #{url}\n"
|
||||||
|
f.write json[index]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
File.open("#{filepath}#{filename}-#{index}.js", "w") do |f|
|
|
||||||
f.write "// #{url}\n"
|
|
||||||
f.write json[index]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue