xml_fixtures 0.0.2
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/MIT-LICENSE +20 -0
- data/README +12 -0
- data/lib/rexml_overrides.rb +51 -0
- data/lib/xml_fixture_helper.rb +22 -0
- data/lib/xml_fixtures.rb +5 -0
- metadata +73 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 QualitySmith Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
XmlFixtures
|
2
|
+
===========
|
3
|
+
|
4
|
+
Extends Rails to support simple xml fixtures for testing and asserts for working with them.
|
5
|
+
|
6
|
+
Example
|
7
|
+
=======
|
8
|
+
|
9
|
+
assert_xml_equal :xml_fixture_name, "<some>XML</some>"
|
10
|
+
|
11
|
+
|
12
|
+
Copyright (c) 2009 QualitySmith Inc., released under the MIT license
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class REXML::Element
|
2
|
+
def ==(another_element)
|
3
|
+
return false unless another_element.is_a?(REXML::Element)
|
4
|
+
return false unless self.name == another_element.name
|
5
|
+
return false unless self.text.try(:strip).to_s == another_element.text.try(:strip).to_s
|
6
|
+
return false unless self.attributes == another_element.attributes
|
7
|
+
return child_elements_equal?(another_element)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def child_elements_equal?(another_element)
|
13
|
+
return false unless self.elements.size == another_element.elements.size
|
14
|
+
return true if self.elements.size == 0
|
15
|
+
if children_look_like_an_array?
|
16
|
+
return array_children_equal?( another_element )
|
17
|
+
else
|
18
|
+
return set_children_equal?( another_element )
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def children_look_like_an_array?
|
24
|
+
return true if self.elements.size == 1
|
25
|
+
return self.elements.collect(&:name).uniq.size == 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def array_children_equal?( another_element )
|
29
|
+
pairs = (1..(self.elements.size)).collect {|index| [ self.elements[index], another_element.elements[index] ] }
|
30
|
+
return pairs.all? {|pair| pair.first == pair.last and pair.first.text.try(:strip).to_s == pair.last.text.try(:strip).to_s }
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_children_equal?( another_element )
|
34
|
+
other_set = get_child_list( another_element )
|
35
|
+
return get_child_list( self ).all? {|child| other_set.any? {|another_child| another_child == child } }
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_child_list( element )
|
39
|
+
child_elements = element.elements.to_a
|
40
|
+
element_names = child_elements.collect(&:name)
|
41
|
+
return child_elements
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class REXML::Attributes
|
46
|
+
def ==(another_attributes)
|
47
|
+
return false unless another_attributes.is_a?(REXML::Attributes)
|
48
|
+
return false unless self.size == another_attributes.size
|
49
|
+
return self.keys.all? {|index| self[index] == another_attributes[index] }
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module XmlFixtureHelper
|
2
|
+
def get_xml_fixture(filename)
|
3
|
+
fixture_xml = ''
|
4
|
+
File.open(File.join( xml_fixture_path, filename )) do |f|
|
5
|
+
fixture_xml = f.read
|
6
|
+
end
|
7
|
+
return ERB.new(fixture_xml).result
|
8
|
+
end
|
9
|
+
|
10
|
+
def assert_xml_equal(first, second)
|
11
|
+
first = get_xml_fixture(first.to_s + '.xml') if first.is_a? Symbol
|
12
|
+
assert_block("#{first.to_s} expected but was\n#{second.to_s}") do
|
13
|
+
REXML::Document.new(first) == REXML::Document.new(second)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def xml_fixture_path
|
20
|
+
File.join( 'test', 'fixtures', 'xml' )
|
21
|
+
end
|
22
|
+
end
|
data/lib/xml_fixtures.rb
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xml_fixtures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- QualitySmith Inc.
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-28 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Extends Rails to support simple xml fixtures for testing and asserts for working with them.
|
23
|
+
email: info@QualitySmith.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/rexml_overrides.rb
|
32
|
+
- lib/xml_fixture_helper.rb
|
33
|
+
- lib/xml_fixtures.rb
|
34
|
+
- README
|
35
|
+
- MIT-LICENSE
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://www.qualitysmith.com
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 23
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 3
|
63
|
+
- 6
|
64
|
+
version: 1.3.6
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Extends Rails to support simple xml fixtures for testing and asserts for working with them.
|
72
|
+
test_files: []
|
73
|
+
|