test_assistant 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,430 +0,0 @@
1
- require './lib/test_assistant/json/helpers'
2
-
3
- RSpec.describe "eql_json" do
4
- include TestAssistant::Json::Helpers
5
-
6
- context "when comparing strings" do
7
- let(:expected) { 'a' }
8
- let(:actual) { 'b' }
9
-
10
- it "then correctly reports any differences" do
11
-
12
- expect(actual).to eql_json(actual)
13
-
14
- expect(actual).to_not eql(expected)
15
-
16
- expect {
17
- expect(actual).to eql_json(expected)
18
- }.to raise_error.with_message(error_message(expected, actual, {
19
- '' => {
20
- expected: "'#{expected}'",
21
- actual: "'#{actual}'"
22
- }
23
- }))
24
- end
25
- end
26
-
27
- context "when comparing integers" do
28
- let(:expected) { 2 }
29
- let(:actual) { 1 }
30
-
31
- it "then correctly reports any differences" do
32
-
33
- expect(actual).to eql_json(actual)
34
-
35
- expect(actual).to_not eql(expected)
36
-
37
- expect {
38
- expect(actual).to eql_json(expected)
39
- }.to raise_error.with_message(error_message(expected, actual, {
40
- '' => {
41
- expected: expected,
42
- actual: actual
43
- }
44
- }))
45
- end
46
- end
47
-
48
- context "when comparing nil" do
49
- let(:expected) { 2 }
50
- let(:actual) { nil }
51
-
52
- it "then correctly reports any differences" do
53
- expect(actual).to eql_json(actual)
54
-
55
- expect(actual).to_not eql(expected)
56
-
57
- expect {
58
- expect(actual).to eql_json(expected)
59
- }.to raise_error.with_message(error_message(expected, actual, {
60
- '' => {
61
- expected: expected,
62
- actual: actual
63
- }
64
- }))
65
-
66
- end
67
-
68
- end
69
-
70
- context "when comparing arrays" do
71
- let(:expected) { [ 1, 3, 4, 5 ] }
72
- let(:actual) { [ 1, 2, 3 ] }
73
-
74
- it "then correctly reports the elements that have changed" do
75
-
76
- expect(actual).to eql(actual)
77
-
78
- expect(actual).to_not eql(expected)
79
-
80
- begin
81
- expect(actual).to eql_json(expected)
82
- rescue RSpec::Expectations::ExpectationNotMetError => e
83
-
84
- expect(e.message).to eql(error_message(expected, actual, {
85
-
86
- '[1]' => {
87
- expected: 3,
88
- actual: 2
89
- },
90
- '[2]' => {
91
- expected: 4,
92
- actual: 3
93
- },
94
- '[3]' => {
95
- expected: 5,
96
- actual: ''
97
- }
98
-
99
- }))
100
-
101
- end
102
-
103
- end
104
-
105
- end
106
-
107
- context "when comparing arrays of objects" do
108
- let(:expected) {
109
- {
110
- 'alpha' => 'alpha',
111
- 'beta' => [ 1, 2, 3],
112
- 'gamma' => [
113
- { 'i' => 'a', 'j' => 'b' },
114
- { 'i' => 'c', 'j' => 'd' },
115
- { 'i' => 'e', 'j' => 'f' },
116
- ]
117
- }
118
- }
119
-
120
- let(:actual) {
121
- {
122
- 'alpha' => 'alpha',
123
- 'beta' => [ 1, 2, 3],
124
- 'gamma' => [
125
- { 'j' => 'b' },
126
- { 'i' => 'c', 'j' => 'D' },
127
- { 'i' => 'e', 'j' => 'f', 'k' => 'k' },
128
- ]
129
- }
130
- }
131
-
132
- it "then correctly reports the elements that have changed" do
133
-
134
- expect(actual).to eql(actual)
135
-
136
- expect(actual).to_not eql(expected)
137
-
138
- begin
139
- expect(actual).to eql_json(expected)
140
- rescue RSpec::Expectations::ExpectationNotMetError => e
141
-
142
- expect(e.message).to eql(error_message(expected, actual, {
143
-
144
- 'gamma[0].i' => {
145
- expected: "'a'",
146
- actual: ''
147
- },
148
- 'gamma[1].j' => {
149
- expected: "'d'",
150
- actual: "'D'"
151
- },
152
- 'gamma[2].k' => {
153
- expected: '',
154
- actual: "'k'"
155
- }
156
-
157
- }))
158
-
159
- end
160
-
161
- end
162
-
163
- end
164
-
165
- context "when comparing objects" do
166
- let(:expected) { {
167
- 'a' => 'a',
168
- 'c' => 'd',
169
- 'e' => 'e'
170
- } }
171
-
172
- let(:actual) { {
173
- 'a' => 'a',
174
- 'b' => 'b',
175
- 'c' => 'c'
176
- } }
177
-
178
- it "then correctly reports the elements that have changed" do
179
-
180
- expect(actual).to eql(actual)
181
-
182
- expect(actual).to_not eql(expected)
183
-
184
- begin
185
- expect(actual).to eql_json(expected)
186
- rescue RSpec::Expectations::ExpectationNotMetError => e
187
-
188
- expect(e.message).to eql(error_message(expected, actual, {
189
-
190
- 'b' => {
191
- expected: '',
192
- actual: "'b'"
193
- },
194
- 'c' => {
195
- expected: "'d'",
196
- actual: "'c'"
197
- },
198
- 'e' => {
199
- expected: "'e'",
200
- actual: ''
201
- }
202
-
203
- }))
204
-
205
- end
206
-
207
- end
208
-
209
- end
210
-
211
- context "when comparing nested objects" do
212
- let(:actual) { {
213
- 'a' => 'a',
214
- 'b' => {
215
- 'b' => 'b'
216
- },
217
- 'c' => {
218
- 'd' => 'd',
219
- 'e' => 'e',
220
- 'f' => {
221
- 'g' => 'g'
222
- },
223
- 'h' => [1,2,3]
224
- },
225
- 'i' => {
226
- 'j' => 'j',
227
- 'k' => 'k'
228
- }
229
- } }
230
-
231
- let(:expected ) { {
232
- 'a' => 'a',
233
- 'c' => {
234
- 'e' => 'e2',
235
- 'f' => {
236
- 'g2' => 'g2'
237
- },
238
- 'h' => [1,2,4]
239
- },
240
- 'i' => {
241
- 'j' => 'j',
242
- }
243
- } }
244
-
245
- it "then correctly reports the elements that have changed" do
246
-
247
- expect(actual).to eql(actual)
248
-
249
- expect(actual).to_not eql(expected)
250
-
251
- begin
252
- expect(actual).to eql_json(expected)
253
- rescue RSpec::Expectations::ExpectationNotMetError => e
254
-
255
- expect(e.message).to eql(error_message(expected, actual, {
256
-
257
- 'b' => {
258
- expected: '',
259
- actual: '{"b"=>"b"}'
260
- },
261
- 'c.d' => {
262
- expected: '',
263
- actual: "'d'"
264
- },
265
- 'c.e' => {
266
- expected: "'e2'",
267
- actual: "'e'"
268
- },
269
- 'c.f.g' => {
270
- expected: '',
271
- actual: "'g'"
272
- },
273
- 'c.f.g2' => {
274
- expected: "'g2'",
275
- actual: ''
276
- },
277
- 'c.h[2]' => {
278
- expected: '4',
279
- actual: '3'
280
- },
281
- 'i.k' => {
282
- expected: '',
283
- actual: "'k'"
284
- },
285
-
286
-
287
- }))
288
-
289
- end
290
-
291
- end
292
- end
293
-
294
- context "when comparing complicated objects" do
295
-
296
- let(:expected ) { {
297
- "a" => "aa",
298
- "b" => "bb",
299
- "c" => {
300
- "d" => 2,
301
- "e" => "ee",
302
- "f" => [{
303
- "g" => "gg",
304
- "h" => "hh",
305
- },
306
- {
307
- "g" => "g1",
308
- "h" => "h1",
309
- }
310
- ],
311
- "i" => {
312
- "j" => "jj",
313
- "k" => "kk",
314
- "l" => [],
315
- "m" => {
316
- "n" => 1,
317
- "o" => "oo",
318
- "p" => {
319
- "q" => "qq"
320
- },
321
- "r" => [],
322
- },
323
- },
324
- "s" => [
325
- {
326
- "t" => 179,
327
- "u" => "UU"
328
- }
329
- ]
330
- }
331
- } }
332
-
333
- let(:actual) { {
334
- "a" => "aa",
335
- "b" => "bb",
336
- "c" => {
337
- "d" => 3,
338
- "e" => "ee",
339
- "f" => [{
340
- "g" => "g1",
341
- "h" => "hh",
342
- },
343
- {
344
- "g" => "g1",
345
- "h" => "h1",
346
- "h2" => "h2"
347
- }
348
- ],
349
- "i" => {
350
- "j" => "j2",
351
- "k" => "kk",
352
- "l" => [2],
353
- "m" => {
354
- "o" => "oo",
355
- "p" => {
356
- "q" => "qq"
357
- },
358
- "r" => [],
359
- },
360
- },
361
- "s" => [
362
- {
363
- "t" => 179,
364
- "u" => "UU"
365
- }
366
- ]
367
- }
368
- } }
369
-
370
- it "then correctly reports the elements that have changed" do
371
-
372
- expect(actual).to eql(actual)
373
-
374
- expect(actual).to_not eql(expected)
375
-
376
- begin
377
- expect(actual).to eql_json(expected)
378
- rescue RSpec::Expectations::ExpectationNotMetError => e
379
-
380
- expect(e.message).to eql(error_message(expected, actual, {
381
- 'c.d' => {
382
- expected: 2,
383
- actual: 3
384
- },
385
- 'c.f[0].g' => {
386
- expected: "'gg'",
387
- actual: "'g1'"
388
- },
389
- 'c.f[1].h2' => {
390
- expected: nil,
391
- actual: "'h2'"
392
- },
393
- 'c.i.j' => {
394
- expected: "'jj'",
395
- actual: "'j2'"
396
- },
397
- 'c.i.l[0]' => {
398
- expected: nil,
399
- actual: 2
400
- },
401
- 'c.i.m.n' => {
402
- expected: 1,
403
- actual: nil
404
- }
405
- }))
406
-
407
- end
408
-
409
- end
410
-
411
- end
412
-
413
- private
414
-
415
- def error_message(expected, actual, differences)
416
- message_lines = [
417
- "Expected: #{expected}\n\n",
418
- "Actual: #{actual}\n\n",
419
- "Differences\n\n"
420
- ]
421
-
422
- differences.each do |attribute_name, difference|
423
- message_lines.push("#{attribute_name}\n")
424
- message_lines.push("Expected: #{difference[:expected]}\n")
425
- message_lines.push("Actual: #{difference[:actual]}\n\n")
426
- end
427
-
428
- message_lines.join
429
- end
430
- end
@@ -1,35 +0,0 @@
1
- class EmailMock
2
- attr_reader :subject, :text, :body
3
-
4
- def initialize(to: 'receiver@email.com', from: 'sender@email.com', subject: 'Subject', text: 'Test Email', body: "<body><h1>Test Email</h1><a href='www.test.com' /><img src='www.test.com' /></body>")
5
- @to, @from, @subject, @text, @body = to, from, subject, text, body
6
- end
7
-
8
- def parts
9
- [
10
- EmailBodyMock.new(@body)
11
- ]
12
- end
13
-
14
- def to
15
- [ @to ]
16
- end
17
-
18
- def from
19
- [ @from ]
20
- end
21
- end
22
-
23
- class EmailBodyMock
24
- def initialize(text)
25
- @text = text
26
- end
27
-
28
- def body
29
- self
30
- end
31
-
32
- def decoded
33
- @text
34
- end
35
- end