objectify-xml 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.2.1 / 2009-03-02
2
+
3
+ * Minor update to support the latest version of Nokogiri (1.2.1)
4
+
1
5
  === 0.2.0 / 2009-02-24
2
6
 
3
7
  * Initial public release.
data/Rakefile CHANGED
@@ -3,13 +3,25 @@
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
5
  require './lib/objectify_xml.rb'
6
+ require 'spec/rake/spectask'
6
7
 
7
8
  Hoe.new('objectify-xml', Objectify::Xml::VERSION) do |p|
8
9
  p.rubyforge_name = 'objectify-xml' # if different than lowercase project name
9
10
  p.developer('pangloss', 'darrick@innatesoftware.com')
10
11
  p.extra_deps = %w[nokogiri activesupport]
11
- #p.extra_dev_deps = []
12
+ p.testlib = 'spec'
13
+ p.test_globs = 'spec/**/*_spec.rb'
12
14
  p.url = 'http://github.com/pangloss/objectify_xml'
15
+ p.remote_rdoc_dir = ''
13
16
  end
14
17
 
18
+ desc "Run all specifications"
19
+ Spec::Rake::SpecTask.new(:spec) do |t|
20
+ t.libs = ['lib', 'spec']
21
+ t.spec_opts = ['--colour', '--format', 'specdoc']
22
+ end
23
+
24
+ Rake::Task[:default].clear
25
+ task :default => [:spec]
26
+
15
27
  # vim: syntax=Ruby
data/lib/objectify_xml.rb CHANGED
@@ -8,7 +8,7 @@ require File.join(File.dirname(__FILE__), 'objectify_xml/element_parser')
8
8
 
9
9
  module Objectify
10
10
  class Xml
11
- VERSION = '0.2.0'
11
+ VERSION = '0.2.1'
12
12
 
13
13
  # When child nodes are created, they are given the name of the node
14
14
  # that created them which is available here.
@@ -31,7 +31,7 @@ module Objectify
31
31
  end
32
32
  # skip the <?xml?> tag
33
33
  xml = xml.child if xml.class == Nokogiri::XML::Document
34
- while xml.class == Nokogiri::XML::Node
34
+ while xml and xml.class != Nokogiri::XML::Element
35
35
  # skips past things like xml-stylesheet declarations.
36
36
  xml = xml.next
37
37
  end
@@ -9,7 +9,35 @@ describe Objectify::Xml do
9
9
  public :xml_text_to_value
10
10
  end
11
11
 
12
+ describe 'first_element' do
13
+ it 'should return the first element, skipping processing instructions' do
14
+ xml_string = <<-exml
15
+ <?xml version="1.0"?>
16
+ <?xml-stylesheet type="text/css" href="http://en.wikipedia.org/skins-1.5/common/feed.css?206xx"?>
17
+ <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"></feed>
18
+ exml
19
+ Xml.first_element(xml_string).name.should == 'feed'
20
+ end
21
+
22
+ it 'should handle nil xml' do
23
+ Xml.first_element(nil).should be_nil
24
+ end
25
+
26
+ it 'should handle blank xml' do
27
+ Xml.first_element('').should be_nil
28
+ end
29
+
30
+ it 'should return the first element of simple xml data' do
31
+ Xml.first_element('<foo><bar>no</bar></foo>').name.should == 'foo'
32
+ end
33
+ end
34
+
12
35
  describe 'initialize' do
36
+ it 'should call first_element' do
37
+ Xml.expects(:first_element).with('the xml').returns(nil)
38
+ Xml.new('the xml')
39
+ end
40
+
13
41
  describe 'with nil' do
14
42
  it 'should handle nil string' do
15
43
  Xml.new(nil) do |x|
@@ -26,24 +54,6 @@ describe Objectify::Xml do
26
54
  end
27
55
  end
28
56
 
29
- describe 'with multiple nodes before the first element' do
30
- it 'should call parse_xml with the first element' do
31
- xml_string = <<-exml
32
- <?xml version="1.0"?>
33
- <?xml-stylesheet type="text/css" href="http://en.wikipedia.org/skins-1.5/common/feed.css?206xx"?>
34
- <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"></feed>
35
- exml
36
- xml = Nokogiri::XML(xml_string).child.next
37
- x = Xml.new(xml_string) do |x|
38
- def x.primary_xml_element(xml)
39
- xml.name.should == 'feed'
40
- @parent = :called
41
- end
42
- end
43
- x.parent.should == :called
44
- end
45
- end
46
-
47
57
  describe 'with ""' do
48
58
  it 'should not call primary_xml_element' do
49
59
  Xml.new('') do |x|
@@ -51,6 +61,7 @@ describe Objectify::Xml do
51
61
  end
52
62
  end
53
63
  end
64
+
54
65
  describe 'with valid xml' do
55
66
  it 'should call primary_xml_element with a Nokogiri XML object' do
56
67
  Xml.new('<foo><bar>no</bar></foo>') do |x|
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/objectify_xml
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), '../lib/objectify_xml/atom'))
4
4
  require 'spec'
5
5
  require 'mocha'
6
+ require 'pp'
6
7
 
7
8
  def sample_feed(name)
8
9
  open(File.join(File.dirname(__FILE__), File.join('sample', name)))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: objectify-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pangloss
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-26 00:00:00 -05:00
12
+ date: 2009-03-02 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 1.8.3
43
+ version: 1.9.0
44
44
  version:
45
45
  description: Provides an easy to use DSL resembling ActiveRecord for defining objects representing any XML document, including deeply nested ones. This project was extracted from my ruby-picasa gem. You can find ruby-picasa at http://github.com/pangloss/ruby_picasa or available as a gem. The project also has significant (if not complete) Atom support.
46
46
  email:
@@ -97,5 +97,9 @@ rubygems_version: 1.3.1
97
97
  signing_key:
98
98
  specification_version: 2
99
99
  summary: Provides an easy to use DSL resembling ActiveRecord for defining objects representing any XML document, including deeply nested ones
100
- test_files: []
101
-
100
+ test_files:
101
+ - spec/atom_spec.rb
102
+ - spec/document_parser_spec.rb
103
+ - spec/dsl_spec.rb
104
+ - spec/element_parser_spec.rb
105
+ - spec/objectify_xml_spec.rb