lzell-mapricot 0.0.1 → 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.
@@ -0,0 +1,97 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.expand_path(File.dirname(__FILE__) + "/../../lib/mapricot")
4
+
5
+ include Mapricot
6
+
7
+ class FeedWithNesting < Mapricot::Base
8
+ has_one :user, :xml
9
+ end
10
+
11
+ class User < Mapricot::Base
12
+ has_one :name
13
+ end
14
+
15
+ share_as :HasOneNested do
16
+
17
+ before(:all) do
18
+ @feed = FeedWithNesting.new(:xml => %(
19
+ <user>
20
+ <name>bob</name>
21
+ </user>
22
+ ))
23
+ end
24
+
25
+
26
+ describe "Interface" do
27
+
28
+ it "should have a user with the name bob" do
29
+ @feed.user.name.should == "bob"
30
+ end
31
+
32
+ describe "Internals" do
33
+
34
+ it "should have a class instance variable @association_list, an array of HasMany and HasOne *instances*" do
35
+ ass_template = @feed.class.association_list.first
36
+ ass_template.should be_a(HasOneAssociation)
37
+ ass_template.name.should == :user
38
+ ass_template.type.should == :xml
39
+ ass_template.namespace.should be_nil
40
+ ass_template.value.should be_nil
41
+ end
42
+
43
+ it "should have an instance variable @associations, duplicated from class ivar @association_list, with value now set" do
44
+ ass = @feed.instance_variable_get(:@associations).first
45
+ ass.name.should == :user
46
+ ass.type.should == :xml
47
+ ass.namespace.should be_nil
48
+ ass.value.should_not be_nil # should not
49
+ end
50
+
51
+ describe "its user" do
52
+
53
+ before(:all) do
54
+ @user = @feed.user
55
+ end
56
+
57
+ it "should be a User, a subclass of Mapricot::Base" do
58
+ @user.should be_a(User)
59
+ @user.should be_a(Mapricot::Base)
60
+ end
61
+
62
+ it "should have a class instance variable @association_list, an array of HasMany and HasOne *instances*" do
63
+ ass_template = @user.class.association_list.first
64
+ ass_template.should be_a(HasOneAssociation)
65
+ ass_template.name.should == :name
66
+ ass_template.type.should == :string
67
+ ass_template.namespace.should be_nil
68
+ ass_template.value.should be_nil
69
+ end
70
+
71
+ it "should have an instance variable @associations, duplicated from class ivar @association_list, with value now set" do
72
+ ass = @user.instance_variable_get(:@associations).first
73
+ ass.name.should == :name
74
+ ass.type.should == :string
75
+ ass.namespace.should be_nil
76
+ ass.value.should_not be_nil # should not
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+
84
+ describe "has one nested, using hpricot" do
85
+ before(:all) { Mapricot.parser = :hpricot }
86
+ it_should_behave_like HasOneNested
87
+ end
88
+
89
+ describe "nested, using libxml" do
90
+ before(:all) { Mapricot.parser = :libxml }
91
+ it_should_behave_like HasOneNested
92
+ end
93
+
94
+ describe "nested, using libxml" do
95
+ before(:all) { Mapricot.parser = :nokogiri }
96
+ it_should_behave_like HasOneNested
97
+ end
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.expand_path(File.dirname(__FILE__) + "/../../lib/mapricot")
4
+
5
+ include Mapricot
6
+
7
+ class FeedWithOneUser < Mapricot::Base
8
+ has_one :user
9
+ end
10
+
11
+
12
+ share_as :HasOneUser do
13
+
14
+ before(:all) do
15
+ @feed = FeedWithOneUser.new(:xml => "<user>bob</user>")
16
+ end
17
+
18
+ describe "Interface" do
19
+
20
+ it "should have a user 'bob'" do
21
+ @feed.user.should == "bob"
22
+ end
23
+ end
24
+
25
+ describe "Internals" do
26
+
27
+ it "should have an accessor on user" do
28
+ @feed.should respond_to(:user)
29
+ end
30
+
31
+ it "should have a class instance variable @association_list, an array of HasMany and HasOne *instances*" do
32
+ @feed.class.association_list.should be_a(Array)
33
+ ass_template = @feed.class.association_list.first
34
+ ass_template.should be_a(HasOneAssociation)
35
+ ass_template.name.should == :user
36
+ ass_template.type.should == :string
37
+ ass_template.namespace.should be_nil
38
+ ass_template.value.should be_nil
39
+ end
40
+
41
+ it "should have an instance variable @associations, duplicated from class ivar @association_list, with value now set" do
42
+ @feed.instance_variable_get(:@associations).should be_a(Array)
43
+ ass = @feed.instance_variable_get(:@associations).first
44
+ ass.should be_a(HasOneAssociation)
45
+ ass.name.should == :user
46
+ ass.type.should == :string
47
+ ass.namespace.should be_nil
48
+ ass.value.should == "bob"
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+ describe "has one user, parsing with hpricot" do
55
+ before(:all) { Mapricot.parser = :hpricot }
56
+ it_should_behave_like HasOneUser
57
+ end
58
+
59
+ describe "has one user, parsing with libxml" do
60
+ before(:all) { Mapricot.parser = :libxml }
61
+ it_should_behave_like HasOneUser
62
+ end
63
+
64
+ describe "has one user, parsing with libxml" do
65
+ before(:all) { Mapricot.parser = :nokogiri }
66
+ it_should_behave_like HasOneUser
67
+ end
data/test/suite.rb ADDED
@@ -0,0 +1,8 @@
1
+ path = File.expand_path(File.dirname(__FILE__))
2
+
3
+ spec_glob = File.join(path, "**", "*_spec.rb")
4
+ test_glob = File.join(path, "**", "test_*.rb")
5
+
6
+ tests = Dir.glob(spec_glob) + Dir.glob(test_glob)
7
+
8
+ tests.each {|test| system("ruby #{test}")}
@@ -0,0 +1,86 @@
1
+ require 'test/unit'
2
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/mapricot")
3
+
4
+
5
+ class FeedA < Mapricot::Base
6
+ has_one :bar
7
+ end
8
+
9
+ class TestFeedA < Test::Unit::TestCase
10
+
11
+ def test_no_bar
12
+ feeda = FeedA.new(:xml => "<no></no>")
13
+ assert feeda.bar.nil?
14
+ end
15
+
16
+ def test_empty_bar
17
+ feeda = FeedA.new(:xml => "<bar></bar>")
18
+ assert feeda.bar.empty?
19
+ end
20
+
21
+ def test_full_bar
22
+ @feed = FeedA.new(:xml => "<bar>is full</bar>")
23
+ assert_equal "is full", @feed.bar
24
+ end
25
+ end
26
+
27
+
28
+
29
+
30
+ class FeedB < Mapricot::Base
31
+ has_many :bars
32
+ end
33
+
34
+ class TestFeedB < Test::Unit::TestCase
35
+ def test_many_empty_bars
36
+ feedb = FeedB.new(:xml => "<notag></notag>")
37
+ assert feedb.bars.is_a?(Array)
38
+ assert feedb.bars.empty?
39
+ end
40
+
41
+ def test_full_bars
42
+ feedb = FeedB.new(:xml => %(
43
+ <response>
44
+ <bar>wet</bar>
45
+ <bar>full</bar>
46
+ </response>
47
+ ))
48
+
49
+ assert_equal "wet", feedb.bars.first
50
+ assert_equal "full", feedb.bars.last
51
+ end
52
+ end
53
+
54
+
55
+
56
+ class FeedC < Mapricot::Base
57
+ has_many :bars, :xml
58
+ end
59
+
60
+ class Bar < Mapricot::Base
61
+ has_one :name
62
+ has_many :patrons
63
+ end
64
+
65
+ class TestFeedC < Test::Unit::TestCase
66
+ def test_many_empty_bars
67
+ feedc = FeedC.new(:xml => "<no></no>")
68
+ assert feedc.bars.empty?
69
+ end
70
+
71
+ def test_many_bars
72
+ feedc = FeedC.new(:xml => %(
73
+ <response>
74
+ <bar>
75
+ <name>maroon saloon</name>
76
+ <patron>brett</patron>
77
+ <patron>chris</patron>
78
+ <patron>garon</patron>
79
+ <patron>mitch</patron>
80
+ </bar>
81
+ </response>
82
+ ))
83
+ assert_equal "maroon saloon", feedc.bars.first.name
84
+ assert_equal ['brett', 'chris', 'garon', 'mitch'], feedc.bars.first.patrons
85
+ end
86
+ end
@@ -1,11 +1,11 @@
1
- require '../lib/mapricot'
2
1
  require 'test/unit'
2
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/mapricot")
3
3
 
4
4
 
5
5
  # -------------------------- Test Example 1 of README.txt ------------------ #
6
6
  SIMPLE_USER_XML = %(
7
7
  <user>
8
- <id>1</name>
8
+ <id>1</id>
9
9
  <name>Bob</name>
10
10
  <pet>cat</pet>
11
11
  <pet>dog</pet>
@@ -25,9 +25,9 @@ class TestSimpleUser < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  def test_everything
28
- assert_equal @simple_user.id, 1
29
- assert_equal @simple_user.name, "Bob"
30
- assert_equal @simple_user.pets, ["cat", "dog"]
28
+ assert_equal 1, @simple_user.id
29
+ assert_equal "Bob", @simple_user.name
30
+ assert_equal ["cat", "dog"], @simple_user.pets
31
31
  end
32
32
  end
33
33
  # -------------------------------------------------------------------------- #
@@ -39,7 +39,7 @@ end
39
39
  # -------------------------- Test Example 2 of README.txt ------------------ #
40
40
  USER_XML = %(
41
41
  <user>
42
- <id>2</name>
42
+ <id>2</id>
43
43
  <name>Sally</name>
44
44
  <location code="ny123">
45
45
  <city>New York</city>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lzell-mapricot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lou Zell
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-06 00:00:00 -08:00
12
+ date: 2009-03-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,26 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: libxml-ruby
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
25
45
  description: Makes working with XML stupid easy. XML to object mapper with an interface similar to ActiveRecord associations.
26
46
  email: lzell11@gmail.com
27
47
  executables: []
@@ -37,11 +57,23 @@ files:
37
57
  - mapricot.gemspec
38
58
  - examples/lastfm_api.rb
39
59
  - examples/lastfm_api_no_request.rb
60
+ - examples/facebook_api.rb
40
61
  - examples/natural_inputs.rb
41
62
  - examples/readme_examples.rb
42
- - test/mapricot_tests.rb
43
- - test/mapricot_spec.rb
63
+ - examples/xml_with_attributes.rb
64
+ - test/suite.rb
65
+ - test/abstract_doc_spec.rb
66
+ - test/test_mapricot.rb
67
+ - test/test_mapricot_readme.rb
68
+ - test/has_attribute/has_attribute_spec.rb
69
+ - test/has_many/has_many_ids_spec.rb
70
+ - test/has_many/has_many_nested_spec.rb
71
+ - test/has_one/has_one_id_spec.rb
72
+ - test/has_one/has_one_user_spec.rb
73
+ - test/has_one/has_one_nested_spec.rb
44
74
  - lib/mapricot.rb
75
+ - lib/abstract_doc.rb
76
+ - benchmark/benchmarks.rb
45
77
  has_rdoc: true
46
78
  homepage: ""
47
79
  post_install_message: