removed redundant tests, added test for parsing from a file
This commit is contained in:
parent
f6fc30c489
commit
f108aac104
2 changed files with 20 additions and 15 deletions
|
@ -5,8 +5,11 @@ require 'date'
|
|||
module Microformats2
|
||||
VERSION = "1.0.0"
|
||||
|
||||
class LoadError < StandardError; end
|
||||
|
||||
def self.parse(html)
|
||||
raise LoadError unless [String, File].include?(html.class)
|
||||
raise LoadError, "argument must be a String or File" unless [String, File].include?(html.class)
|
||||
|
||||
doc = Nokogiri::HTML(html)
|
||||
microformats = Hash.new{|hash, key| hash[key] = Array.new}
|
||||
doc.css("*[class^=h-]").each do |microformat|
|
||||
|
@ -132,8 +135,6 @@ module Microformats2
|
|||
end
|
||||
end
|
||||
|
||||
class LoadError < StandardError; end
|
||||
|
||||
# Thank you Rails Developers for your unitentional contribution to this project
|
||||
# File activesupport/lib/active_support/inflector/inflections.rb, line 206
|
||||
def self.classify(str)
|
||||
|
|
|
@ -2,18 +2,6 @@ require "test/unit"
|
|||
require "microformats2"
|
||||
|
||||
class TestMicroformats2 < Test::Unit::TestCase
|
||||
def test_acceptence_of_string
|
||||
assert_nothing_raised Microformats2::LoadError do
|
||||
Microformats2.parse("A String")
|
||||
end
|
||||
end
|
||||
|
||||
def test_acceptence_of_file
|
||||
assert_nothing_raised Microformats2::LoadError do
|
||||
Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "hcard.html")))
|
||||
end
|
||||
end
|
||||
|
||||
def test_throw_exception_on_non_string_params
|
||||
assert_raise Microformats2::LoadError do
|
||||
Microformats2.parse(nil)
|
||||
|
@ -30,6 +18,22 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|||
assert_equal 0, result.size
|
||||
end
|
||||
|
||||
def test_extracts_hcard_from_an_html_file
|
||||
hcard = <<-END
|
||||
<html>
|
||||
<head>
|
||||
<title>Simple hCard</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1 class="h-card">Chris</h1>
|
||||
</body>
|
||||
</html>
|
||||
END
|
||||
result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "hcard.html")))
|
||||
assert_equal HCard, result[:hcard].first.class
|
||||
end
|
||||
|
||||
def test_extracts_hcard_from_html
|
||||
hcard = <<-END
|
||||
<html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue