xml_fixtures 0.0.4 → 0.1.0

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/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the xml_fixtures plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
16
+
17
+ desc 'Generate documentation for the xml_fixtures plugin.'
18
+ Rake::RDocTask.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'XmlFixtures'
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
@@ -0,0 +1,3 @@
1
+ <test>
2
+ <%= 'example' %>
3
+ </test>
@@ -0,0 +1,210 @@
1
+ require 'test_helper'
2
+
3
+ class RexmlOverridesTest < ActiveSupport::TestCase
4
+ context 'get_child_list' do
5
+ should "be empty" do
6
+ root = REXML::Document.new('<root></root>').elements.first
7
+ assert_equal([], root.send(:get_child_list, root) )
8
+ end
9
+
10
+ should "get simple set" do
11
+ root = REXML::Document.new('<root><child1>child 1 content</child1><child2>child 2 content</child2></root>').elements.first
12
+ set = root.send(:get_child_list, root)
13
+ assert_equal 2, set.size
14
+ assert set.any? {|element| element.name = 'child1' }
15
+ assert set.any? {|element| element.name = 'child2' }
16
+ end
17
+ end
18
+
19
+ context 'set_children_equal?' do
20
+ should 'return true with no children' do
21
+ xml1 = REXML::Document.new('<root></root>').root
22
+ xml2 = REXML::Document.new('<root></root>').root
23
+ assert xml1.send(:set_children_equal?, xml2)
24
+ end
25
+
26
+ should 'return false if one has a child element and the other none' do
27
+ xml1 = REXML::Document.new('<root><cool>test</cool></root>').root
28
+ xml2 = REXML::Document.new('<root></root>').root
29
+ assert !xml1.send(:set_children_equal?, xml2)
30
+ end
31
+
32
+ should 'return true if both have equal child element' do
33
+ xml1 = REXML::Document.new('<root><cool>test</cool></root>').root
34
+ xml2 = REXML::Document.new('<root><cool>test</cool></root>').root
35
+ assert xml1.send(:set_children_equal?, xml2)
36
+ end
37
+
38
+ should 'return false when they have an equal elemnt and an element with a different name' do
39
+ xml1 = REXML::Document.new('<root><cool>test</cool><neat>oh</neat></root>').root
40
+ xml2 = REXML::Document.new('<root><cool>test</cool><wow>oh</wow></root>').root
41
+ assert !xml1.send(:set_children_equal?, xml2)
42
+ end
43
+
44
+ should 'return true when equal nested tags but with whitespace' do
45
+ xml1 = REXML::Document.new('<root><cool><test>awesome</test></cool><neat>oh</neat></root>').root
46
+ xml2 = REXML::Document.new("<root>\n\n\t \t\n<cool><test>awesome</test></cool><neat>oh</neat></root>").root
47
+ assert xml1.send(:set_children_equal?, xml2)
48
+ end
49
+
50
+ should 'return true when equal elements but out of order' do
51
+ xml1 = REXML::Document.new('<root><cool><test>awesome</test></cool><neat>oh</neat></root>').root
52
+ xml2 = REXML::Document.new('<root><neat>oh</neat><cool><test>awesome</test></cool></root>').root
53
+ assert xml1.send(:set_children_equal?, xml2)
54
+ end
55
+ end
56
+
57
+ context 'children_look_like_an_array?' do
58
+ should 'return true if only one element' do
59
+ xml = REXML::Document.new('<root><test>cool</test></root>').root
60
+ assert xml.send(:children_look_like_an_array?)
61
+ end
62
+
63
+ should 'return true if all elements have the same name' do
64
+ xml = REXML::Document.new('<root><test>cool</test><test>again</test></root>').root
65
+ assert xml.send(:children_look_like_an_array?)
66
+ end
67
+
68
+ should 'return false if any element has a different name' do
69
+ xml = REXML::Document.new('<root><test>cool</test><wow>uh oh</wow><test>again</test></root>').root
70
+ assert !xml.send(:children_look_like_an_array?)
71
+ end
72
+ end
73
+
74
+ context 'array_children_equal?' do
75
+ should 'return true for single equal elements' do
76
+ xml1 = REXML::Document.new('<root><test>cool</test></root>').root
77
+ xml2 = REXML::Document.new("<root>\n\t<test>cool</test>\n</root> ").root
78
+ assert xml1.send(:array_children_equal?, xml2)
79
+ end
80
+
81
+ should 'return false for single different elements' do
82
+ xml1 = REXML::Document.new('<root><test>cool</test></root>').root
83
+ xml2 = REXML::Document.new("<root><test>cooler</test>\n</root> ").root
84
+ assert !xml1.send(:array_children_equal?, xml2)
85
+ end
86
+
87
+ should 'return true for equal elements and in order' do
88
+ xml1 = REXML::Document.new('<root><test>cool</test><another>yeah</another></root>').root
89
+ xml2 = REXML::Document.new('<root><test>cool</test><another>yeah</another></root> ').root
90
+ assert xml1.send(:array_children_equal?, xml2)
91
+ end
92
+
93
+ should 'return false for equal elements but out of order' do
94
+ xml1 = REXML::Document.new('<root><test>cool</test><another>yeah</another></root>').root
95
+ xml2 = REXML::Document.new('<root><another>yeah</another><test>cool</test></root> ').root
96
+ assert !xml1.send(:array_children_equal?, xml2)
97
+ end
98
+ end
99
+
100
+ context 'child_elements_equal?' do
101
+ should "return false when element count is different" do
102
+ xml1 = REXML::Document.new('<root><another>yeah</another></root>').root
103
+ xml2 = REXML::Document.new('<root><test>cool</test><another>yeah</another></root>').root
104
+ assert !xml1.send(:child_elements_equal?, xml2)
105
+ end
106
+
107
+ should 'return true if there are no elements' do
108
+ xml1 = REXML::Document.new('<root></root>').root
109
+ xml2 = REXML::Document.new('<root></root>').root
110
+ assert xml1.send(:child_elements_equal?, xml2)
111
+ end
112
+
113
+ should 'return true for simple array' do
114
+ xml1 = REXML::Document.new('<root><test>cool</test><test>yeah</test></root>').root
115
+ xml2 = REXML::Document.new('<root><test>cool</test><test>yeah</test></root>').root
116
+ assert xml1.send(:child_elements_equal?, xml2)
117
+ end
118
+
119
+ should 'return false for simple array' do
120
+ xml1 = REXML::Document.new('<root><test>cool</test><test>yeah</test></root>').root
121
+ xml2 = REXML::Document.new('<root><test>cool</test><test>no</test></root>').root
122
+ assert !xml1.send(:child_elements_equal?, xml2)
123
+ end
124
+
125
+ should 'return true for simple set' do
126
+ xml1 = REXML::Document.new('<root><another>yeah</another><test>cool</test></root>').root
127
+ xml2 = REXML::Document.new('<root><test>cool</test><another>yeah</another></root>').root
128
+ assert xml1.send(:child_elements_equal?, xml2)
129
+ end
130
+
131
+ should 'return false for simple set' do
132
+ xml1 = REXML::Document.new('<root><another>yeah</another><test>cool</test></root>').root
133
+ xml2 = REXML::Document.new('<root><test>cool</test><another>no</another></root>').root
134
+ assert !xml1.send(:child_elements_equal?, xml2)
135
+ end
136
+ end
137
+
138
+ context 'element ==' do
139
+ should 'be false when not comparing with an element' do
140
+ xml = REXML::Document.new('<root></root>').root
141
+ assert_not_equal xml, 'test'
142
+ end
143
+
144
+ should 'be false when names of tags not the same' do
145
+ xml1 = REXML::Document.new('<root></root>').root
146
+ xml2 = REXML::Document.new('<test></test>').root
147
+ assert_not_equal xml1, xml2
148
+ end
149
+
150
+ should 'be false when text is not equal' do
151
+ xml1 = REXML::Document.new('<root>yeah</root>').root
152
+ xml2 = REXML::Document.new('<root>no</root>').root
153
+ assert_not_equal xml1, xml2
154
+ end
155
+
156
+ should 'be false when attributes are not equal at all' do
157
+ xml1 = REXML::Document.new('<root neat="foo">yeah</root>').root
158
+ xml2 = REXML::Document.new('<root wow="bar">yeah</root>').root
159
+ assert_not_equal xml1, xml2
160
+ end
161
+
162
+ should 'be false when attributes are not equal but have same names' do
163
+ xml1 = REXML::Document.new('<root neat="foo">yeah</root>').root
164
+ xml2 = REXML::Document.new('<root neat="bar">yeah</root>').root
165
+ assert_not_equal xml1, xml2
166
+ end
167
+
168
+ should 'be false when attributes are not equal but have same values' do
169
+ xml1 = REXML::Document.new('<root neat="bar">yeah</root>').root
170
+ xml2 = REXML::Document.new('<root cool="bar">yeah</root>').root
171
+ assert_not_equal xml1, xml2
172
+ end
173
+
174
+ should 'be true when equal' do
175
+ xml1 = REXML::Document.new('<root neat="bar">yeah</root>').root
176
+ xml2 = REXML::Document.new('<root neat="bar">yeah</root>').root
177
+ assert_equal xml1, xml2
178
+ end
179
+
180
+ should 'be true when equal except whitespace' do
181
+ xml1 = REXML::Document.new('<root neat="bar">yeah</root>').root
182
+ xml2 = REXML::Document.new("<root neat=\"bar\" >\nyeah</root>\n \t\n").root
183
+ assert_equal xml1, xml2
184
+ end
185
+
186
+ should 'be true when equal except attribute ordering' do
187
+ xml1 = REXML::Document.new('<root neat="bar" cool="other">yeah</root>').root
188
+ xml2 = REXML::Document.new('<root cool="other" neat="bar">yeah</root>').root
189
+ assert_equal xml1, xml2
190
+ end
191
+
192
+ should 'be false when child elements are not equal' do
193
+ xml1 = REXML::Document.new('<root neat="bar"><nested>yeah</nested></root>').root
194
+ xml2 = REXML::Document.new('<root neat="bar"><nested>no</nested></root>').root
195
+ assert_not_equal xml1, xml2
196
+ end
197
+
198
+ should 'be true when child elements equal but whitespace' do
199
+ xml1 = REXML::Document.new("<root><nested>wow</nested><nested></nested></root>").root
200
+ xml2 = REXML::Document.new("<root><nested>wow</nested> \n\t<nested></nested></root>").root
201
+ assert_equal xml1, xml2
202
+ end
203
+
204
+ should 'be true when child elements equal but order' do
205
+ xml1 = REXML::Document.new("<root><nested>wow</nested><other></other></root>").root
206
+ xml2 = REXML::Document.new("<root><other></other><nested>wow</nested></root>").root
207
+ assert_equal xml1, xml2
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
4
+ require 'active_support/test_case'
5
+ require 'shoulda'
6
+ require 'action_controller'
7
+ require 'xml_fixtures'
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class XmlFixturesTest < ActiveSupport::TestCase
4
+ context 'get_xml_fixture' do
5
+ should 'raise when nonsense filename' do
6
+ assert_raise( Errno::ENOENT ) {
7
+ get_xml_fixture('blahblahnonsense')
8
+ }
9
+ end
10
+
11
+ should 'load file and run through erb' do
12
+ assert_equal "<test>\n example\n</test>\n", get_xml_fixture('xml_with_erb.xml')
13
+ end
14
+ end
15
+
16
+ context "assert_xml_equal" do
17
+ should 'fail if not equal' do
18
+ assert_raise( Test::Unit::AssertionFailedError ) {
19
+ assert_xml_equal :xml_with_erb, '<something>very different</something>'
20
+ }
21
+ end
22
+
23
+ should 'have nice message on fail' do
24
+ begin
25
+ assert_xml_equal :xml_with_erb, '<something>very different</something>'
26
+ rescue Exception => e
27
+ assert_equal "<test>\n example\n</test>\n expected but was\n<something>very different</something>", e.message
28
+ end
29
+ end
30
+
31
+ should 'pass if equal' do
32
+ assert_nothing_raised {
33
+ assert_xml_equal :xml_with_erb, '<test>example</test>'
34
+ }
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ def xml_fixture_path
41
+ File.join( File.dirname(__FILE__), 'fixtures' )
42
+ end
43
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml_fixtures
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 4
10
- version: 0.0.4
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - QualitySmith Inc.
@@ -19,7 +19,7 @@ date: 2010-07-29 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: Extends Rails to support simple xml fixtures for testing and asserts for working with them.
22
+ description: This gem provides your tests with the ability to load XML from fixture files and compare two XML documents using REXML.
23
23
  email: info@QualitySmith.com
24
24
  executables: []
25
25
 
@@ -32,15 +32,20 @@ files:
32
32
  - lib/try.rb
33
33
  - lib/xml_fixture_helper.rb
34
34
  - lib/xml_fixtures.rb
35
- - README
35
+ - test/fixtures/xml_with_erb.xml
36
+ - test/rexml_overrides_test.rb
37
+ - test/test_helper.rb
38
+ - test/xml_fixtures_test.rb
36
39
  - MIT-LICENSE
40
+ - Rakefile
41
+ - README
37
42
  has_rdoc: true
38
- homepage: http://www.qualitysmith.com
43
+ homepage: http://www.github.com/qualitysmith/xml_fixtures
39
44
  licenses: []
40
45
 
41
46
  post_install_message:
42
- rdoc_options: []
43
-
47
+ rdoc_options:
48
+ - --charset=UTF-8
44
49
  require_paths:
45
50
  - lib
46
51
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -65,10 +70,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
70
  version: 1.3.6
66
71
  requirements: []
67
72
 
68
- rubyforge_project:
73
+ rubyforge_project: none
69
74
  rubygems_version: 1.3.7
70
75
  signing_key:
71
76
  specification_version: 3
72
- summary: Extends Rails to support simple xml fixtures for testing and asserts for working with them.
73
- test_files: []
74
-
77
+ summary: Adds support for XML fixtures in tests.
78
+ test_files:
79
+ - test/fixtures/xml_with_erb.xml
80
+ - test/rexml_overrides_test.rb
81
+ - test/test_helper.rb
82
+ - test/xml_fixtures_test.rb