reorganizes spec cases and fixes a couple few
This commit is contained in:
parent
ed58788884
commit
c74ecef194
158 changed files with 46 additions and 42 deletions
16
Rakefile
16
Rakefile
|
@ -10,12 +10,14 @@ task :default => [:spec]
|
||||||
namespace :specs do
|
namespace :specs do
|
||||||
task :update do
|
task :update do
|
||||||
sources = [
|
sources = [
|
||||||
{ urls: ["http://microformats.org/wiki/microformats-2"],
|
{ dir: "microformats.org",
|
||||||
|
urls: ["http://microformats.org/wiki/microformats-2"],
|
||||||
html_selector: ".source-html4strict",
|
html_selector: ".source-html4strict",
|
||||||
json_selector: ".source-javascript",
|
json_selector: ".source-javascript",
|
||||||
html_method: "inner_text"
|
html_method: "inner_text"
|
||||||
},
|
},
|
||||||
{ urls: [
|
{ dir: "microformat2-node.jit.su",
|
||||||
|
urls: [
|
||||||
"http://microformat2-node.jit.su/h-adr.html",
|
"http://microformat2-node.jit.su/h-adr.html",
|
||||||
"http://microformat2-node.jit.su/h-card.html",
|
"http://microformat2-node.jit.su/h-card.html",
|
||||||
"http://microformat2-node.jit.su/h-entry.html",
|
"http://microformat2-node.jit.su/h-entry.html",
|
||||||
|
@ -43,17 +45,19 @@ namespace :specs do
|
||||||
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+/, "")
|
name = url.split("/").last.gsub(/[.]\w+/, "")
|
||||||
filepath = "spec/support/cases/"
|
path = File.join "spec/support/cases", source[:dir], name
|
||||||
|
|
||||||
|
FileUtils.mkdir_p(path)
|
||||||
|
|
||||||
([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(File.join(path, "#{name}-#{index}.html"), "w") do |f|
|
||||||
f.write "<!-- #{url} -->\n"
|
f.write "<!-- #{url} -->\n"
|
||||||
f.write html[index]
|
f.write html[index]
|
||||||
end
|
end
|
||||||
|
|
||||||
File.open("#{filepath}#{filename}-#{index}.js", "w") do |f|
|
File.open(File.join(path, "#{name}-#{index}.js"), "w") do |f|
|
||||||
f.write "// #{url}\n"
|
f.write "// #{url}\n"
|
||||||
f.write json[index]
|
f.write json[index]
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,7 @@ module Microformats2
|
||||||
|
|
||||||
def read_html(html)
|
def read_html(html)
|
||||||
open(html).read
|
open(html).read
|
||||||
rescue Errno::ENOENT => e
|
rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
|
||||||
html
|
html
|
||||||
end
|
end
|
||||||
end # class << self
|
end # class << self
|
||||||
|
|
|
@ -32,15 +32,15 @@ module Microformats2
|
||||||
|
|
||||||
class Url < Property::Parser
|
class Url < Property::Parser
|
||||||
def parse_flat_element(element)
|
def parse_flat_element(element)
|
||||||
(element.attribute("href") || property.text).to_s
|
(element.attribute("href") || element.attribute("src") || element.text).to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class DateTime < Property::Parser
|
class DateTime < Property::Parser
|
||||||
def parse_flat_element(element)
|
def parse_flat_element(element)
|
||||||
::DateTime.parse(element.attribute("datetime") || property.text)
|
::DateTime.parse(element.attribute("datetime") || element.text)
|
||||||
rescue ArgumentError => e
|
rescue ArgumentError => e
|
||||||
element.attribute("datetime") || property.text
|
(element.attribute("datetime") || element.text).to_s
|
||||||
end
|
end
|
||||||
def hash_safe_value
|
def hash_safe_value
|
||||||
@value.to_s
|
@value.to_s
|
||||||
|
@ -49,7 +49,7 @@ module Microformats2
|
||||||
|
|
||||||
class Embedded < Property::Parser
|
class Embedded < Property::Parser
|
||||||
def parse_flat_element(element)
|
def parse_flat_element(element)
|
||||||
element.text.gsub(/\n+/, " ").gsub(/\s+/, " ").strip
|
element.inner_html.strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ describe Microformats2 do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "programatic case" do
|
describe "programatic case" do
|
||||||
cases_dir = "spec/support/cases"
|
cases_dir = "spec/support/cases/microformats.org/microformats-2"
|
||||||
html_files = Dir.entries(cases_dir).keep_if { |f| f =~ /([.]html$)/ }
|
html_files = Dir.entries(cases_dir).keep_if { |f| f =~ /([.]html$)/ }
|
||||||
|
|
||||||
html_files.each do |html_file|
|
html_files.each do |html_file|
|
||||||
|
|
|
@ -6,6 +6,6 @@ require 'rspec'
|
||||||
require 'rspec/autorun'
|
require 'rspec/autorun'
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.order = "random"
|
# config.order = "random"
|
||||||
config.color = true
|
config.color = true
|
||||||
end
|
end
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue