test_xml 0.1.6 → 0.1.7

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 170f3a3dbcbac8bf470d5502cf240c9c1b24313b
4
+ data.tar.gz: 3532c7033ca564336d94d06e3b1fd5ed5637ee56
5
+ SHA512:
6
+ metadata.gz: 935649d551777890cdfe7406ae93012785768da1746e6d0b2b4da2d8b6445d78b15ec69afffb137d5f28a2c0907ba42080aee04b7522025ce3bb0ef5734fed97
7
+ data.tar.gz: 85bf8823b75aa6701ccc5eabf11c27e37ed8014d667ceb9b34ab594cbe28786338c4406c0a455d5a4190fbc0e55a70622e218057f971659d7e29999ac42c8fc2
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.1.7 (Unreleased)
2
+
3
+ * Add diff output to xml_equal
4
+ * Add support for RSpec 3
5
+ * Fix order of expected result and actual result for RSpec
6
+
1
7
  # 0.1.6
2
8
 
3
9
  * Fix dependencies so that Minitest doesn't rely on Test::Unit anymore. If you having trouble, update to minitest > 4.0.0 :)
@@ -12,4 +18,4 @@
12
18
 
13
19
  # 0.1.3
14
20
 
15
- * Adding support for `MiniTest::Spec` matchers.
21
+ * Adding support for `MiniTest::Spec` matchers.
@@ -1,16 +1,15 @@
1
1
  = TestXml
2
2
 
3
-
4
- == DESCRIPTION:
3
+ == DESCRIPTION
5
4
 
6
5
  TestXml is a small extension for testing XML/HTML. Extending RSpec and TestUnit it makes asserting and comparing XML snippets easy, and is especially helpful for testing RESTful web services and their XML representations.
7
6
 
8
7
 
9
- == FEATURES:
8
+ == FEATURES
10
9
 
11
- * runs with RSpec2, Test::Unit, MiniTest and Cucumber
12
- * Ruby 1.8 and 1.9
13
- * test XML structure and content
10
+ * Runs with RSpec 2 or 3, Test::Unit, MiniTest and Cucumber
11
+ * Ruby >= 1.8
12
+ * Test XML structure and content
14
13
 
15
14
 
16
15
  == INSTALL
@@ -18,7 +17,7 @@ TestXml is a small extension for testing XML/HTML. Extending RSpec and TestUnit
18
17
  gem install test_xml
19
18
 
20
19
 
21
- == EXAMPLES:
20
+ == EXAMPLES
22
21
 
23
22
  === Test::Unit and MiniTest
24
23
 
@@ -101,6 +100,41 @@ In your steps file e.g. features/step_definitions/xml_steps.rb add this step:
101
100
  response.body.should equal_xml(xml)
102
101
  end
103
102
 
103
+ == ASSERTIONS
104
+
105
+ === XML is Equal
106
+
107
+ Elements, attributes and text nodes are all the same
108
+
109
+ === XML Contains
110
+
111
+ The XML contains the given structure. Checks ancestral relationships, elements, attributes and text nodes <b>starting from and including the root node</b>.
112
+
113
+ For example, given this XML:
114
+
115
+ <a>
116
+ <b><c>Cee</c></b>
117
+ <d>Dee</b>
118
+ </a>
119
+
120
+ This will fail:
121
+
122
+ <b><c>Cee</c></b>
123
+
124
+ as +b+ is not the root node. The check must be written as:
125
+
126
+ <a>
127
+ <b><c>Cee</c></b>
128
+ </a>
129
+
130
+ === XML Structure is Equal
131
+
132
+ Like XML is equal, but ignores attributes and text nodes
133
+
134
+ === XML Structure Contains
135
+
136
+ Like XML contains, but ignores attributes and text nodes
137
+
104
138
  == REQUIREMENTS
105
139
 
106
140
  * nokogiri
@@ -1,4 +1,5 @@
1
1
  require 'ostruct'
2
+ require 'diffy'
2
3
 
3
4
  module TestXml
4
5
  class AssertionConfig < OpenStruct
@@ -19,37 +20,48 @@ module TestXml
19
20
  AssertionConfig.new(
20
21
  :name => :xml_contain,
21
22
  :matcher => :contain_xml,
22
- :message_for_should => lambda { |a,b| "the xml:\n#{a}\nshould contain xml:\n#{b}" },
23
- :message_for_should_not => lambda { |a,b| "the xml:\n#{a}\nshould not contain xml:\n#{b} but it does" }
23
+ :message => lambda { |expect, actual| "the xml:\n#{actual}\nshould contain xml:\n#{expect}" },
24
+ :message_when_negated => lambda { |expect, actual| "the xml:\n#{actual}\nshould not contain xml:\n#{expect} but it does" }
24
25
  ),
25
26
  AssertionConfig.new(
26
27
  :name => :xml_structure_contain,
27
28
  :matcher => :contain_xml_structure,
28
- :message_for_should => lambda { |a,b| "the xml:\n#{a}\nshould match xml structure:\n#{b}" },
29
- :message_for_should_not => lambda { |a,b| "the xml:\n#{a}\nshould not match xml structure:\n#{b} but it does" }
29
+ :message => lambda { |expect, actual| "the xml:\n#{actual}\nshould match xml structure:\n#{expect}" },
30
+ :message_when_negated => lambda { |expect, actual| "the xml:\n#{actual}\nshould not match xml structure:\n#{expect} but it does" }
30
31
  ),
31
32
  AssertionConfig.new(
32
33
  :name => :xml_equal,
33
34
  :matcher => :equal_xml,
34
- :message_for_should => lambda { |a,b| "the xml:\n#{a}\nshould exactly match xml:\n#{b}" },
35
- :message_for_should_not => lambda { |a,b| "the xml:\n#{a}\nshould not exactly match xml:\n#{b} but it does" }
35
+ :message => lambda { |expect, actual| sprintf "the xml:\n%s\nshould exactly match xml:\n%s\n\nDiff:\n%s", actual, expect, diff(expect, actual) },
36
+ :message_when_negated => lambda { |expect, actual| "the xml:\n#{actual}\nshould not exactly match xml:\n#{expect} but it does" }
36
37
  ),
37
38
  AssertionConfig.new(
38
39
  :name => :xml_structure_equal,
39
40
  :matcher => :equal_xml_structure,
40
- :message_for_should => lambda { |a,b| "the xml:\n#{a}\nshould exactly match xml structure:\n#{b}" },
41
- :message_for_should_not => lambda { |a,b| "the xml:\n#{a}\nshould not exactly match xml structure:\n#{b} but it does" }
41
+ :message => lambda { |expect, actual| "the xml:\n#{actual}\nshould exactly match xml structure:\n#{expect}" },
42
+ :message_when_negated => lambda { |expect, actual| "the xml:\n#{actual}\nshould not exactly match xml structure:\n#{expect} but it does" }
42
43
  )
43
44
  ]
44
45
 
46
+ def self.diff(expect, actual)
47
+ doc_actual = Nokogiri::XML.parse(actual, &:noblanks)
48
+ doc_expect = Nokogiri::XML.parse(expect, &:noblanks)
49
+
50
+ diff = Diffy::Diff.new(doc_expect.to_xml, doc_actual.to_xml, :context => 3, :include_diff_info => true).to_a
51
+ return "" if diff.empty?
52
+
53
+ # Skip diff headers, they're useless since they refer to tempfiles
54
+ diff[2..-1].join("")
55
+ end
56
+
45
57
  module Assertions
46
58
  ASSERTIONS.each do |cfg|
47
59
  define_method(cfg.assert_name) do |a, b|
48
- correct_assert(MatcherMethods.send(cfg.name, a, b), cfg.message_for_should.call(a, b))
60
+ correct_assert(MatcherMethods.send(cfg.name, a, b), cfg.message.call(a, b))
49
61
  end
50
62
 
51
63
  define_method(cfg.assert_not_name) do |a, b|
52
- correct_assert(! MatcherMethods.send(cfg.name, a, b), cfg.message_for_should_not.call(a, b))
64
+ correct_assert(! MatcherMethods.send(cfg.name, a, b), cfg.message_when_negated.call(a, b))
53
65
  end
54
66
  end
55
67
 
@@ -64,4 +76,4 @@ module TestXml
64
76
  end
65
77
  end
66
78
  end
67
- end
79
+ end
@@ -7,12 +7,15 @@ TestXml::ASSERTIONS.each do |cfg|
7
7
  TestXml::MatcherMethods.send(cfg.name, actual, expected)
8
8
  end
9
9
 
10
- failure_message_for_should do |actual|
11
- cfg.message_for_should.call(expected, actual)
10
+ # RSpec 2 and 3 use different methods
11
+ # to access failure messages.
12
+ if RSpec::Expectations::Version::STRING[0] == "2"
13
+ failure_message_for_should { |actual| cfg.message.call(expected, actual) }
14
+ failure_message_for_should_not { |actual| cfg.message_when_negated.call(expected, actual) }
15
+ else
16
+ failure_message { |actual| cfg.message.call(expected, actual) }
17
+ failure_message_when_negated { |actual| cfg.message_when_negated.call(expected, actual) }
12
18
  end
13
19
 
14
- failure_message_for_should_not do |actual|
15
- cfg.message_for_should_not.call(expected, actual)
16
- end
17
20
  end
18
- end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module TestXml
2
- VERSION = '0.1.6'
2
+ VERSION = "0.1.7"
3
3
  end
@@ -5,7 +5,7 @@ class TestAssertions < Test::Unit::TestCase
5
5
  begin
6
6
  assert_xml_contain("<root><one>1</one><one>2</one></root>", "<root><one>3</one></root>")
7
7
  rescue Exception => e
8
- assert_match %r{the xml:\n<root><one>1</one><one>2</one></root>\nshould contain xml:\n<root><one>3</one></root>}, e.message
8
+ assert_match %r{the xml:\n<root><one>3</one></root>\nshould contain xml:\n<root><one>1</one><one>2</one></root>}, e.message
9
9
  end
10
10
  end
11
11
 
@@ -20,9 +20,10 @@ Gem::Specification.new do |s|
20
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
21
 
22
22
  s.rubygems_version = "1.3.5"
23
+ s.add_dependency("diffy", ["~> 3.0"])
23
24
  s.add_dependency("nokogiri", [">= 1.3.2"])
24
25
 
25
26
  s.add_development_dependency("rake")
26
27
  s.add_development_dependency("rdoc")
27
- s.add_development_dependency("rspec-core", ["~> 2.2"])
28
+ s.add_development_dependency("rspec-core", [">= 2.2"])
28
29
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
5
- prerelease:
4
+ version: 0.1.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Pavel Gabriel
@@ -10,74 +9,80 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-05-14 00:00:00.000000000 Z
12
+ date: 2014-10-23 00:00:00.000000000 Z
14
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: diffy
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.0'
15
28
  - !ruby/object:Gem::Dependency
16
29
  name: nokogiri
17
30
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
31
  requirements:
20
- - - ! '>='
32
+ - - ">="
21
33
  - !ruby/object:Gem::Version
22
34
  version: 1.3.2
23
35
  type: :runtime
24
36
  prerelease: false
25
37
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
38
  requirements:
28
- - - ! '>='
39
+ - - ">="
29
40
  - !ruby/object:Gem::Version
30
41
  version: 1.3.2
31
42
  - !ruby/object:Gem::Dependency
32
43
  name: rake
33
44
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
45
  requirements:
36
- - - ! '>='
46
+ - - ">="
37
47
  - !ruby/object:Gem::Version
38
48
  version: '0'
39
49
  type: :development
40
50
  prerelease: false
41
51
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
52
  requirements:
44
- - - ! '>='
53
+ - - ">="
45
54
  - !ruby/object:Gem::Version
46
55
  version: '0'
47
56
  - !ruby/object:Gem::Dependency
48
57
  name: rdoc
49
58
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
59
  requirements:
52
- - - ! '>='
60
+ - - ">="
53
61
  - !ruby/object:Gem::Version
54
62
  version: '0'
55
63
  type: :development
56
64
  prerelease: false
57
65
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
66
  requirements:
60
- - - ! '>='
67
+ - - ">="
61
68
  - !ruby/object:Gem::Version
62
69
  version: '0'
63
70
  - !ruby/object:Gem::Dependency
64
71
  name: rspec-core
65
72
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
73
  requirements:
68
- - - ~>
74
+ - - ">="
69
75
  - !ruby/object:Gem::Version
70
76
  version: '2.2'
71
77
  type: :development
72
78
  prerelease: false
73
79
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
80
  requirements:
76
- - - ~>
81
+ - - ">="
77
82
  - !ruby/object:Gem::Version
78
83
  version: '2.2'
79
- description: ! 'Test your XML with Test::Unit, MiniTest, RSpec, or Cucumber using
80
- handy assertions like #assert_xml_equal or #assert_xml_structure_contain.'
84
+ description: 'Test your XML with Test::Unit, MiniTest, RSpec, or Cucumber using handy
85
+ assertions like #assert_xml_equal or #assert_xml_structure_contain.'
81
86
  email:
82
87
  - alovak@gmail.com
83
88
  - apotonick@gmail.com
@@ -86,7 +91,7 @@ extensions: []
86
91
  extra_rdoc_files:
87
92
  - README.rdoc
88
93
  files:
89
- - .gitignore
94
+ - ".gitignore"
90
95
  - CHANGES.md
91
96
  - Gemfile
92
97
  - README.rdoc
@@ -111,28 +116,35 @@ files:
111
116
  - test_xml.gemspec
112
117
  homepage: http://github.com/alovak/test_xml
113
118
  licenses: []
119
+ metadata: {}
114
120
  post_install_message:
115
121
  rdoc_options:
116
- - --main
122
+ - "--main"
117
123
  - README.rdoc
118
124
  require_paths:
119
125
  - lib
120
126
  required_ruby_version: !ruby/object:Gem::Requirement
121
- none: false
122
127
  requirements:
123
- - - ! '>='
128
+ - - ">="
124
129
  - !ruby/object:Gem::Version
125
130
  version: '0'
126
131
  required_rubygems_version: !ruby/object:Gem::Requirement
127
- none: false
128
132
  requirements:
129
- - - ! '>='
133
+ - - ">="
130
134
  - !ruby/object:Gem::Version
131
135
  version: '0'
132
136
  requirements: []
133
137
  rubyforge_project:
134
- rubygems_version: 1.8.25
138
+ rubygems_version: 2.2.2
135
139
  signing_key:
136
- specification_version: 3
140
+ specification_version: 4
137
141
  summary: Test your XML with Test::Unit, MiniTest, RSpec, or Cucumber.
138
- test_files: []
142
+ test_files:
143
+ - spec/matchers/contain_xml_spec.rb
144
+ - spec/matchers/contain_xml_structure_spec.rb
145
+ - spec/matchers/equal_xml_spec.rb
146
+ - spec/matchers/equal_xml_structure_spec.rb
147
+ - spec/spec_helper.rb
148
+ - test/nokogiri/test_node.rb
149
+ - test/test_helper.rb
150
+ - test/test_unit/test_assertions.rb