jordi-xml_struct 0.2.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/README.rdoc +152 -0
  2. data/WHATSNEW +10 -0
  3. data/lib/xml_struct/adapters/hpricot.rb +47 -0
  4. data/lib/xml_struct/adapters/rexml.rb +34 -0
  5. data/lib/xml_struct/array_notation.rb +44 -0
  6. data/lib/xml_struct/blankish_slate.rb +1 -1
  7. data/lib/xml_struct/collection_proxy.rb +7 -3
  8. data/lib/xml_struct/default_adapter.rb +15 -0
  9. data/lib/xml_struct/method_missing_dispatchers.rb +43 -0
  10. data/lib/xml_struct/string.rb +6 -2
  11. data/lib/xml_struct.rb +31 -52
  12. data/xml_struct.gemspec +38 -0
  13. metadata +17 -49
  14. data/README.markdown +0 -151
  15. data/Rakefile +0 -36
  16. data/lib/xml_struct/common_behaviours.rb +0 -53
  17. data/test/samples/lorem.xml +0 -63
  18. data/test/samples/recipe.xml +0 -16
  19. data/test/samples/weird_characters.xml +0 -2
  20. data/test/test_helper.rb +0 -39
  21. data/test/vendor/test-spec/README +0 -378
  22. data/test/vendor/test-spec/ROADMAP +0 -1
  23. data/test/vendor/test-spec/Rakefile +0 -146
  24. data/test/vendor/test-spec/SPECS +0 -161
  25. data/test/vendor/test-spec/TODO +0 -2
  26. data/test/vendor/test-spec/bin/specrb +0 -107
  27. data/test/vendor/test-spec/examples/stack.rb +0 -38
  28. data/test/vendor/test-spec/examples/stack_spec.rb +0 -119
  29. data/test/vendor/test-spec/lib/test/spec/dox.rb +0 -148
  30. data/test/vendor/test-spec/lib/test/spec/rdox.rb +0 -25
  31. data/test/vendor/test-spec/lib/test/spec/should-output.rb +0 -49
  32. data/test/vendor/test-spec/lib/test/spec/version.rb +0 -8
  33. data/test/vendor/test-spec/lib/test/spec.rb +0 -660
  34. data/test/vendor/test-spec/test/spec_dox.rb +0 -39
  35. data/test/vendor/test-spec/test/spec_flexmock.rb +0 -209
  36. data/test/vendor/test-spec/test/spec_mocha.rb +0 -104
  37. data/test/vendor/test-spec/test/spec_nestedcontexts.rb +0 -26
  38. data/test/vendor/test-spec/test/spec_new_style.rb +0 -80
  39. data/test/vendor/test-spec/test/spec_should-output.rb +0 -26
  40. data/test/vendor/test-spec/test/spec_testspec.rb +0 -699
  41. data/test/vendor/test-spec/test/spec_testspec_order.rb +0 -26
  42. data/test/vendor/test-spec/test/test_testunit.rb +0 -22
  43. data/test/xml_struct_test.rb +0 -185
@@ -1,26 +0,0 @@
1
- require 'test/spec'
2
-
3
- $foo = 0
4
-
5
- context "Context First" do
6
- specify "runs before Second" do
7
- $foo.should.equal 0
8
- $foo += 1
9
- end
10
- end
11
-
12
- context "Context Second" do
13
- specify "runs before Last" do
14
- $foo.should.equal 1
15
- $foo += 1
16
- end
17
- end
18
-
19
- context "Context Last" do
20
- specify "runs last" do
21
- $foo.should.equal 2
22
- $foo += 1
23
- end
24
- end
25
-
26
-
@@ -1,22 +0,0 @@
1
- require 'test/spec'
2
-
3
- class TestTestUnit < Test::Unit::TestCase
4
- def test_still_works_on_its_own
5
- assert_equal 1, 1
6
- assert_raise(RuntimeError) { raise "Error" }
7
- end
8
-
9
- def test_supports_should_good_enough
10
- (2 + 3).should.be 5
11
- lambda { raise "Error" }.should.raise
12
- assert true
13
- end
14
- end
15
-
16
- context "TestUnit" do
17
- specify "works inside test/spec" do
18
- assert_equal 1, 1
19
- assert_raise(RuntimeError) { raise "Error" }
20
- end
21
- end
22
-
@@ -1,185 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
2
-
3
- describe 'An XML file with weird characters' do
4
-
5
- it 'should not raise exceptions' do
6
- should.not.raise(Exception) do
7
- @xml = XMLStruct.new xml_file(:weird_characters)
8
- end
9
- end
10
-
11
- it 'should allow access to attributes with dashes in the name' do
12
- XMLStruct.new(
13
- xml_file(:weird_characters))['attr-with-dashes'].should == 'lame'
14
- end
15
- end
16
-
17
- describe 'The XML Struct module' do
18
-
19
- def setup
20
- @filename = File.join(File.dirname(__FILE__), 'samples', 'recipe.xml')
21
- @file = File.open @filename
22
- @recipe = XMLStruct.new xml_file(:recipe)
23
- end
24
-
25
- it 'should know how to run "new" with a filename given' do
26
- XMLStruct.new(@filename).name.should == @recipe.name
27
- end
28
-
29
- it 'should know how to run "new" with a file given' do
30
- XMLStruct.new(@file).name.should == @recipe.name
31
- end
32
-
33
- it 'should raise an exception when given something else to "new"' do
34
- should.raise(RuntimeError) { XMLStruct.new(8) }
35
- end
36
- end
37
-
38
- describe 'README Recipe' do
39
-
40
- def setup
41
- @recipe = XMLStruct.new xml_file(:recipe)
42
- end
43
-
44
- it 'should have name and title as "bread" and "Basic bread"' do
45
- @recipe.name.should == "bread"
46
- @recipe.title.should == "Basic bread"
47
- end
48
-
49
- it 'should treat "recipe.ingredients" as an Array' do
50
- @recipe.ingredients.is_a?(Array).should.be true
51
- @recipe.ingredients.first.amount.to_i.should == 8
52
- end
53
-
54
- it 'should have 7 easy instructions' do
55
- @recipe.instructions.easy?.should.be true
56
- @recipe.instructions.steps.size.should == 7
57
- @recipe.instructions.first.upcase.should ==
58
- "MIX ALL INGREDIENTS TOGETHER."
59
- end
60
- end
61
-
62
- describe 'XML Struct' do
63
-
64
- include RubyProf::Test if defined? RubyProf::Test
65
-
66
- def setup
67
- @lorem = XMLStruct.new xml_file(:lorem)
68
- end
69
-
70
- it 'should be an instance of XMLStruct::String' do
71
- @lorem.should.be.an.instance_of ::String
72
- end
73
-
74
- it 'be blank if devoid of children, attributes and value' do
75
- @lorem.ipsum.should.be.blank
76
- end
77
-
78
- it 'not be blank when value, children, or attributes are present' do
79
- [ @lorem.dolor, @lorem.sit, @lorem.ut ].each do |xr|
80
- xr.should.not.be.blank
81
- end
82
- end
83
-
84
- it 'should allow access to attributes named like invalid methods' do
85
- @lorem['_tempor'].should == 'incididunt'
86
- end
87
-
88
- it 'should allow access to elements named like invalid methods' do
89
- @lorem['_minim'].should == 'veniam'
90
- end
91
-
92
- it 'should provide unambiguous access to elements named like attributes' do
93
- @lorem.sed[:element => 'do'].should == 'eiusmod elementus'
94
- end
95
-
96
- it 'should provide unambiguous access to attributes named like elements' do
97
- @lorem.sed[:attribute => 'do'].should == 'eiusmod attributus'
98
- end
99
-
100
- it 'should return elements first when using dot notation' do
101
- @lorem.sed.do.should == @lorem.sed[:element => 'do']
102
- end
103
-
104
- it 'should return elements first when using [] with string key' do
105
- @lorem.sed['do'].should == @lorem.sed[:element => 'do']
106
- end
107
-
108
- it 'should return elements first when using [] with symbol key' do
109
- @lorem.sed[:do].should == @lorem.sed[:element => 'do']
110
- end
111
-
112
- it 'should raise exception when unkown keys are used in [{}] mode' do
113
- should.raise(RuntimeError) { @lorem[:foo => 'bar'] }
114
- end
115
-
116
- it 'should group multiple parallel namesake elements in arrays' do
117
- @lorem.consectetur.is_a?(Array).should.be true
118
- end
119
-
120
- it 'should make auto-grouped arrays accessible by their plural form' do
121
- @lorem.consecteturs.should.be @lorem.consectetur
122
- end
123
-
124
- it 'should allow explicit access to elements named like plural arrays' do
125
- @lorem.consecteturs.should.not.be @lorem[:element => 'consecteturs']
126
- end
127
-
128
- it 'should convert integer-looking attribute strings to integers' do
129
- @lorem.consecteturs.each do |c|
130
- c['id'].rb.is_a?(Numeric).should.be true
131
- end
132
- end
133
-
134
- it 'should convert float-looking attribute strings to floats' do
135
- @lorem.consecteturs.each do |c|
136
- c.capacity.rb.is_a?(Float).should.be true
137
- end
138
- end
139
-
140
- it 'should not convert strings with more than numbers to Fixnum' do
141
- @lorem.sed.do.price.rb.should == @lorem.sed.do.price
142
- @lorem.sed.do.price.rb.should.not == 8
143
- end
144
-
145
- it 'should convert bool-looking attribute strings to bools when asked' do
146
- @lorem.consecteturs.each { |c| c.enabled?.should == !!(c.enabled?) }
147
- end
148
-
149
- it 'should convert to bool correctly when asked' do
150
- @lorem.consecteturs.first.enabled?.should.be true
151
- @lorem.consecteturs.last.enabled?.should.be false
152
- end
153
-
154
- it 'should pass forth methods to single array child when empty valued' do
155
- @lorem.cupidatats[0].should == @lorem.cupidatats.cupidatat[0]
156
- end
157
-
158
- it 'should not pass methods to single array child if not empty valued' do
159
- should.raise(RuntimeError) { @lorem.voluptate[0] }
160
- end
161
-
162
- it 'should be valued as its text when text first and CDATA exist' do
163
- @lorem.ullamco.should == 'Laboris'
164
- end
165
-
166
- it 'should have the value of its first CDATA when multiple exist' do
167
- @lorem.deserunt.should == 'mollit'
168
- end
169
-
170
- it 'should squish whitespace in string attribute values' do
171
- @lorem.irure.metadata.should == 'dolor'
172
- end
173
-
174
- it 'should not squish whitespace in string element values' do
175
- @lorem.irure.should == " \n\t\t\treprehenderit "
176
- end
177
-
178
- it 'should not squish whitespace in CDATA values' do
179
- @lorem.should == "\t foo\n"
180
- end
181
-
182
- it 'should have a working inspect function' do
183
- should.not.raise { @lorem.inspect.is_a?(String) }
184
- end
185
- end