reorganizes spec cases and fixes a couple few
This commit is contained in:
parent
67465879fa
commit
72ce8e3cd6
158 changed files with 46 additions and 42 deletions
16
Rakefile
16
Rakefile
|
@ -10,12 +10,14 @@ task :default => [:spec]
|
|||
namespace :specs do
|
||||
task :update do
|
||||
sources = [
|
||||
{ urls: ["http://microformats.org/wiki/microformats-2"],
|
||||
{ dir: "microformats.org",
|
||||
urls: ["http://microformats.org/wiki/microformats-2"],
|
||||
html_selector: ".source-html4strict",
|
||||
json_selector: ".source-javascript",
|
||||
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-card.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]) }
|
||||
json = document.css(source[:json_selector]).map { |e| e.inner_text }
|
||||
|
||||
filename = url.split("/").last.gsub(/[.]\w+/, "")
|
||||
filepath = "spec/support/cases/"
|
||||
name = url.split("/").last.gsub(/[.]\w+/, "")
|
||||
path = File.join "spec/support/cases", source[:dir], name
|
||||
|
||||
FileUtils.mkdir_p(path)
|
||||
|
||||
([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 html[index]
|
||||
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 json[index]
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ module Microformats2
|
|||
|
||||
def read_html(html)
|
||||
open(html).read
|
||||
rescue Errno::ENOENT => e
|
||||
rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
|
||||
html
|
||||
end
|
||||
end # class << self
|
||||
|
|
|
@ -32,15 +32,15 @@ module Microformats2
|
|||
|
||||
class Url < Property::Parser
|
||||
def parse_flat_element(element)
|
||||
(element.attribute("href") || property.text).to_s
|
||||
(element.attribute("href") || element.attribute("src") || element.text).to_s
|
||||
end
|
||||
end
|
||||
|
||||
class DateTime < Property::Parser
|
||||
def parse_flat_element(element)
|
||||
::DateTime.parse(element.attribute("datetime") || property.text)
|
||||
::DateTime.parse(element.attribute("datetime") || element.text)
|
||||
rescue ArgumentError => e
|
||||
element.attribute("datetime") || property.text
|
||||
(element.attribute("datetime") || element.text).to_s
|
||||
end
|
||||
def hash_safe_value
|
||||
@value.to_s
|
||||
|
@ -49,7 +49,7 @@ module Microformats2
|
|||
|
||||
class Embedded < Property::Parser
|
||||
def parse_flat_element(element)
|
||||
element.text.gsub(/\n+/, " ").gsub(/\s+/, " ").strip
|
||||
element.inner_html.strip
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ describe Microformats2 do
|
|||
end
|
||||
|
||||
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.each do |html_file|
|
||||
|
|
|
@ -6,6 +6,6 @@ require 'rspec'
|
|||
require 'rspec/autorun'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.order = "random"
|
||||
# config.order = "random"
|
||||
config.color = true
|
||||
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