Sha256: 5f7cf79fb5d8daf12e8d0f939263d886da71b0d54bde55bcd078fa389ecb1006
Contents?: true
Size: 1.91 KB
Versions: 1
Compression:
Stored size: 1.91 KB
Contents
require "test/unit" require File.dirname(__FILE__) + "/../lib/parsley" class TestParsley < Test::Unit::TestCase def setup @page = File.expand_path(File.dirname(__FILE__) + "/yelp.html") @home = File.expand_path(File.dirname(__FILE__) + "/yelp-home.html") @let = File.expand_path(File.dirname(__FILE__) + "/yelp-home.let") end def test_yelp @parsley = Parsley.new(File.read(@let)) out = @parsley.parse(:file => @home) assert_equal "/c/sf/shopping", out["categories"][0]["href"] end def test_yelp_xml @parsley = Parsley.new(File.read(@let)) out = @parsley.parse(:file => @home, :output => :xml) end def test_simple @parsley = Parsley.new("hi" => "h1") assert_equal({"hi" => "Nick's Crispy Tacos"}, @parsley.parse(:file => @page)) end def test_simple_string @parsley = Parsley.new("hi" => "h1") assert_equal({"hi" => "Nick's Crispy Tacos"}, @parsley.parse(:string => "<html><body><h1>Nick's Crispy Tacos</h1></body></html>")) end def test_xml @parsley = Parsley.new("hi" => "h1") xml = "<?xml version=\"1.0\"?>\n<parsley:root xmlns:parsley=\"http://parslets.com/json\"><hi>Nick's Crispy Tacos</hi></parsley:root>\n" assert_equal(xml, @parsley.parse(:file => @page, :output => :xml)) end def test_json @parsley = Parsley.new("hi" => "h1") assert_equal('{ "hi": "Nick\'s Crispy Tacos" }', @parsley.parse(:file => @page, :output => :json)) end def test_rescuable_file_error @parsley = Parsley.new("hi" => "h1") @nonexistant_file = File.dirname(__FILE__) + "/../fixtures/yelp.html" assert_equal({"hi" => "Nick's Crispy Tacos"}, @parsley.parse(:file => @nonexistant_file)) rescue nil end def test_array_string @parsley = Parsley.new({"foo" => ["li"]}) out = @parsley.parse(:file => @page) assert_kind_of Hash, out assert_kind_of Array, out["foo"], out.inspect assert out["foo"].length > 1 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fizx-parsley-ruby-0.1.2 | test/test_parsley.rb |