File: test_assertions.rb

package info (click to toggle)
ruby-test-xml 0.1.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: ruby: 781; makefile: 4
file content (263 lines) | stat: -rw-r--r-- 4,887 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
require 'test_helper'

class TestAssertions < Test::Unit::TestCase
  def test_assert_xml_contain_message_if_fails
    begin
      assert_xml_contain("<root><one>1</one><one>2</one></root>", "<root><one>3</one></root>")
    rescue Exception => e
      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
    end
  end

  def test_assert_xml_not_contain_message_if_fails
    begin
      assert_not_xml_contain("<root><one>1</one><one>2</one></root>", "<root><one>1</one><one>2</one></root>")
    rescue Exception => e
      assert_match %r{the xml:\n<root><one>1</one><one>2</one></root>\nshould not contain xml:\n<root><one>1</one><one>2</one></root> but it does}, e.message
    end
  end

  def test_assert_xml_contain
    expected = <<-XML
      <root>
        <one id="first">1</one>
        <two>2</two>
      </root>
    XML

    actual = <<-XML
      <root>
        <one id="first">1</one>
      </root>
    XML

    assert_xml_contain expected, actual
  end

  def test_assert_not_xml_contain
    expected = <<-XML
      <root>
        <one>1</one>
      </root>
    XML

    actual = <<-XML
      <root>
        <one>2</one>
      </root>
    XML

    assert_not_xml_contain expected, actual
  end

  def test_assert_xml_structure_contain
    expected = <<-XML
      <root>
        <one>1</one>
        <two>
          <three>3</three>
        </two>
      </root>
    XML

    actual = <<-XML
      <root>
        <one>2</one>
        <two>
          <three>4</three>
        </two>
      </root>
    XML

    assert_xml_structure_contain expected, actual
  end

  def test_assert_not_xml_structure_contain
    expected = <<-XML
      <root>
        <one>1</one>
        <two>
          <three>3</three>
        </two>
      </root>
    XML

    actual = <<-XML
      <root>
        <one>2</one>
        <two>
          <four/>
        </two>
      </root>
    XML

    assert_not_xml_structure_contain expected, actual
  end

  def test_assert_xml_equal
    expected = <<-XML
      <root>
        <one>1</one>
        <two>2</two>
      </root>
    XML

    actual = <<-XML
      <root>
        <one>1</one>
        <two>2</two>
      </root>
    XML

    assert_xml_equal expected, actual
  end

  def test_assert_xml_equal_with_attributes
    expected = <<-XML
      <root>
        <one b="second" a="first">1</one>
        <two b="second" a="first" />
      </root>
    XML

    actual = <<-XML
      <root>
        <one a="first" b="second">1</one>
        <two b="second" a="first" />
      </root>
    XML

    assert_xml_equal expected, actual
  end

  def test_assert_xml_equal_with_attributes_in_branch_element
    expected = <<-XML
      <root type="test">
        <one>1</one>
        <two/>
      </root>
    XML

    actual = <<-XML
      <root type="test">
        <one>1</one>
        <two/>
      </root>
    XML

    assert_xml_equal expected, actual
  end

  def test_assert_not_xml_equal_with_attributes
    expected = <<-XML
      <root>
        <one b="second" a="first">1</one>
      </root>
    XML

    actual = <<-XML
      <root>
        <one a="whoops, wrong" b="second">1</one>
      </root>
    XML

    assert_not_xml_equal expected, actual
  end


  def test_assert_not_xml_equal_with_attributes_and_no_text
    expected = <<-XML
      <root>
        <one b="second" a="first" />
      </root>
    XML

    actual = <<-XML
      <root>
        <one a="whoops, wrong" b="second" />
      </root>
    XML

    assert_not_xml_equal expected, actual
  end

  def test_assert_not_xml_equal_with_attributes_in_branch_element
    expected = <<-XML
      <root type="test">
        <one>1</one>
        <two/>
      </root>
    XML

    actual = <<-XML
      <root>
        <one>1</one>
        <two/>
      </root>
    XML

    assert_not_xml_equal expected, actual
  end

  def test_assert_not_xml_equal
    expected = <<-XML
      <root>
        <one>1</one>
        <two>2</two>
      </root>
    XML

    actual = <<-XML
      <root>
        <one>1</one>
      </root>
    XML

    assert_not_xml_equal expected, actual
  end

  def test_assert_xml_structure_equal
    expected = <<-XML
      <root>
        <one>1</one>
        <two>
          <three>3</three>
        </two>
      </root>
    XML

    actual = <<-XML
      <root>
        <one>2</one>
        <two>
          <three>4</three>
        </two>
      </root>
    XML

    assert_xml_structure_equal expected, actual
  end

  def test_assert_not_xml_structure_equal
    expected = <<-XML
      <root>
        <one>1</one>
        <two>
          <three>3</three>
        </two>
      </root>
    XML

    actual = <<-XML
      <root>
        <one>2</one>
        <two>
          <three>3</three>
          <four/>
        </two>
      </root>
    XML

    assert_not_xml_structure_equal expected, actual
  end
end