Permalink
Browse files

Updated to support new release of Nokogiri.

  • Loading branch information...
1 parent 7e91da2 commit 87e4c77059513eb86e9d627b8c5b3896fdfbfe5b Darrick Wiebe committed Mar 2, 2009
Showing with 46 additions and 21 deletions.
  1. +2 −0 .gitignore
  2. +10 −1 Rakefile
  3. +2 −2 lib/objectify_xml.rb
  4. +29 −18 spec/objectify_xml_spec.rb
  5. +2 −0 spec/spec.opts
  6. +1 −0 spec/spec_helper.rb
View
@@ -1 +1,3 @@
pkg
+tags
+doc
View
@@ -3,13 +3,22 @@
require 'rubygems'
require 'hoe'
require './lib/objectify_xml.rb'
+require 'spec/rake/spectask'
Hoe.new('objectify-xml', Objectify::Xml::VERSION) do |p|
p.rubyforge_name = 'objectify-xml' # if different than lowercase project name
p.developer('pangloss', 'darrick@innatesoftware.com')
p.extra_deps = %w[nokogiri activesupport]
- #p.extra_dev_deps = []
+ p.testlib = 'spec'
+ p.test_globs = 'spec/**/*_spec.rb'
p.url = 'http://github.com/pangloss/objectify_xml'
+ p.remote_rdoc_dir = ''
+end
+
+desc "Run all specifications"
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.libs = ['lib', 'spec']
+ t.spec_opts = ['--colour', '--format', 'specdoc']
end
# vim: syntax=Ruby
View
@@ -8,7 +8,7 @@
module Objectify
class Xml
- VERSION = '0.2.0'
+ VERSION = '0.2.1'
# When child nodes are created, they are given the name of the node
# that created them which is available here.
@@ -31,7 +31,7 @@ def self.first_element(xml)
end
# skip the <?xml?> tag
xml = xml.child if xml.class == Nokogiri::XML::Document
- while xml.class == Nokogiri::XML::Node
+ while xml and xml.class != Nokogiri::XML::Element
# skips past things like xml-stylesheet declarations.
xml = xml.next
end
View
@@ -9,7 +9,35 @@ def initialize(*args)
public :xml_text_to_value
end
+ describe 'first_element' do
+ it 'should return the first element, skipping processing instructions' do
+ xml_string = <<-exml
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="http://en.wikipedia.org/skins-1.5/common/feed.css?206xx"?>
+<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"></feed>
+ exml
+ Xml.first_element(xml_string).name.should == 'feed'
+ end
+
+ it 'should handle nil xml' do
+ Xml.first_element(nil).should be_nil
+ end
+
+ it 'should handle blank xml' do
+ Xml.first_element('').should be_nil
+ end
+
+ it 'should return the first element of simple xml data' do
+ Xml.first_element('<foo><bar>no</bar></foo>').name.should == 'foo'
+ end
+ end
+
describe 'initialize' do
+ it 'should call first_element' do
+ Xml.expects(:first_element).with('the xml').returns(nil)
+ Xml.new('the xml')
+ end
+
describe 'with nil' do
it 'should handle nil string' do
Xml.new(nil) do |x|
@@ -26,31 +54,14 @@ def initialize(*args)
end
end
- describe 'with multiple nodes before the first element' do
- it 'should call parse_xml with the first element' do
- xml_string = <<-exml
-<?xml version="1.0"?>
-<?xml-stylesheet type="text/css" href="http://en.wikipedia.org/skins-1.5/common/feed.css?206xx"?>
-<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"></feed>
- exml
- xml = Nokogiri::XML(xml_string).child.next
- x = Xml.new(xml_string) do |x|
- def x.primary_xml_element(xml)
- xml.name.should == 'feed'
- @parent = :called
- end
- end
- x.parent.should == :called
- end
- end
-
describe 'with ""' do
it 'should not call primary_xml_element' do
Xml.new('') do |x|
x.expects(:primary_xml_element).never
end
end
end
+
describe 'with valid xml' do
it 'should call primary_xml_element with a Nokogiri XML object' do
Xml.new('<foo><bar>no</bar></foo>') do |x|
View
@@ -0,0 +1,2 @@
+--colour
+--format specdoc
View
@@ -3,6 +3,7 @@
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/objectify_xml/atom'))
require 'spec'
require 'mocha'
+require 'pp'
def sample_feed(name)
open(File.join(File.dirname(__FILE__), File.join('sample', name)))

0 comments on commit 87e4c77

Please sign in to comment.