webspicy 0.16.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -5
  3. data/bin/webspicy +6 -1
  4. data/doc/1-black-box-scene.md +109 -0
  5. data/doc/2-black-box-testing.md +27 -0
  6. data/doc/3-specification-importance.md +41 -0
  7. data/doc/4-sequence-diagram.md +82 -0
  8. data/lib/webspicy.rb +15 -4
  9. data/lib/webspicy/configuration.rb +57 -8
  10. data/lib/webspicy/configuration/scope.rb +22 -16
  11. data/lib/webspicy/formaldoc.fio +3 -1
  12. data/lib/webspicy/specification.rb +12 -10
  13. data/lib/webspicy/specification/condition.rb +23 -0
  14. data/lib/webspicy/specification/errcondition.rb +17 -0
  15. data/lib/webspicy/specification/postcondition.rb +1 -0
  16. data/lib/webspicy/specification/precondition.rb +1 -0
  17. data/lib/webspicy/specification/precondition/robust_to_invalid_input.rb +1 -1
  18. data/lib/webspicy/specification/service.rb +38 -25
  19. data/lib/webspicy/specification/test_case.rb +10 -17
  20. data/lib/webspicy/support.rb +22 -0
  21. data/lib/webspicy/support/data_object.rb +25 -0
  22. data/lib/webspicy/support/hooks.rb +65 -0
  23. data/lib/webspicy/support/world.rb +47 -0
  24. data/lib/webspicy/tester.rb +120 -61
  25. data/lib/webspicy/tester/asserter.rb +9 -4
  26. data/lib/webspicy/tester/assertions.rb +8 -9
  27. data/lib/webspicy/tester/client.rb +22 -42
  28. data/lib/webspicy/tester/failure.rb +6 -0
  29. data/lib/webspicy/tester/file_checker.rb +22 -0
  30. data/lib/webspicy/tester/invocation.rb +15 -196
  31. data/lib/webspicy/tester/reporter.rb +85 -0
  32. data/lib/webspicy/tester/reporter/composite.rb +38 -0
  33. data/lib/webspicy/tester/reporter/documentation.rb +67 -0
  34. data/lib/webspicy/tester/reporter/error_count.rb +25 -0
  35. data/lib/webspicy/tester/reporter/exceptions.rb +60 -0
  36. data/lib/webspicy/tester/reporter/file_progress.rb +22 -0
  37. data/lib/webspicy/tester/reporter/file_summary.rb +42 -0
  38. data/lib/webspicy/tester/reporter/progress.rb +28 -0
  39. data/lib/webspicy/tester/reporter/summary.rb +62 -0
  40. data/lib/webspicy/tester/result.rb +139 -0
  41. data/lib/webspicy/tester/result/assert_met.rb +29 -0
  42. data/lib/webspicy/tester/result/check.rb +33 -0
  43. data/lib/webspicy/tester/result/errcondition_met.rb +29 -0
  44. data/lib/webspicy/tester/result/error_schema_met.rb +24 -0
  45. data/lib/webspicy/tester/result/output_schema_met.rb +24 -0
  46. data/lib/webspicy/tester/result/postcondition_met.rb +29 -0
  47. data/lib/webspicy/tester/result/response_header_met.rb +43 -0
  48. data/lib/webspicy/tester/result/response_status_met.rb +25 -0
  49. data/lib/webspicy/version.rb +2 -2
  50. data/lib/webspicy/web.rb +4 -0
  51. data/lib/webspicy/web/client.rb +15 -0
  52. data/lib/webspicy/{tester → web}/client/http_client.rb +34 -14
  53. data/lib/webspicy/{tester → web}/client/rack_test_client.rb +3 -3
  54. data/lib/webspicy/{tester → web}/client/support.rb +2 -2
  55. data/lib/webspicy/web/invocation.rb +65 -0
  56. data/lib/webspicy/web/mocker.rb +90 -0
  57. data/lib/webspicy/web/mocker/config.ru +6 -0
  58. data/lib/webspicy/{openapi.rb → web/openapi.rb} +0 -0
  59. data/lib/webspicy/web/openapi/generator.rb +129 -0
  60. data/spec/unit/configuration/scope/test_each_service.rb +2 -2
  61. data/spec/unit/configuration/scope/test_each_specification.rb +7 -7
  62. data/spec/unit/specification/test_condition.rb +26 -0
  63. data/spec/unit/support/hooks/test_fire_after_each.rb +53 -0
  64. data/spec/unit/{tester/client/test_around.rb → support/hooks/test_fire_around.rb} +15 -10
  65. data/spec/unit/support/hooks/test_fire_before_each.rb +53 -0
  66. data/spec/unit/support/world/fixtures/array.json +8 -0
  67. data/spec/unit/support/world/fixtures/queue.rb +1 -0
  68. data/spec/unit/support/world/fixtures/single.json +11 -0
  69. data/spec/unit/support/world/fixtures/yaml.yml +3 -0
  70. data/spec/unit/support/world/test_world.rb +56 -0
  71. data/spec/unit/test_configuration.rb +50 -1
  72. data/spec/unit/tester/test_asserter.rb +198 -3
  73. data/spec/unit/tester/test_assertions.rb +8 -6
  74. data/spec/unit/web/mocker/test_mocker.rb +35 -0
  75. data/spec/unit/web/openapi/test_generator.rb +31 -0
  76. metadata +72 -61
  77. data/examples/restful/Gemfile +0 -5
  78. data/examples/restful/Gemfile.lock +0 -105
  79. data/examples/restful/Rakefile +0 -25
  80. data/examples/restful/app.rb +0 -180
  81. data/examples/restful/webspicy/config.rb +0 -23
  82. data/examples/restful/webspicy/rack.rb +0 -7
  83. data/examples/restful/webspicy/real.rb +0 -8
  84. data/examples/restful/webspicy/schema.fio +0 -20
  85. data/examples/restful/webspicy/support/must_be_an_admin.rb +0 -20
  86. data/examples/restful/webspicy/support/must_be_authenticated.rb +0 -48
  87. data/examples/restful/webspicy/support/todo_removed.rb +0 -18
  88. data/examples/restful/webspicy/todo/deleteTodo.yml +0 -52
  89. data/examples/restful/webspicy/todo/getTodo.yml +0 -50
  90. data/examples/restful/webspicy/todo/getTodoSingleServiceFormat.yml +0 -46
  91. data/examples/restful/webspicy/todo/getTodos.yml +0 -36
  92. data/examples/restful/webspicy/todo/options.yml +0 -32
  93. data/examples/restful/webspicy/todo/patchTodo.yml +0 -66
  94. data/examples/restful/webspicy/todo/postCsv.yml +0 -43
  95. data/examples/restful/webspicy/todo/postFile.yml +0 -40
  96. data/examples/restful/webspicy/todo/postTodos.yml +0 -51
  97. data/examples/restful/webspicy/todo/putTodo.yml +0 -65
  98. data/examples/restful/webspicy/todo/todos.csv +0 -4
  99. data/examples/single_spec/spec.yml +0 -59
  100. data/examples/website/config.rb +0 -2
  101. data/examples/website/schema.fio +0 -1
  102. data/examples/website/specification/get-http.yml +0 -34
  103. data/examples/website/specification/get-https.yml +0 -34
  104. data/lib/webspicy/checker.rb +0 -25
  105. data/lib/webspicy/mocker.rb +0 -88
  106. data/lib/webspicy/openapi/generator.rb +0 -127
  107. data/lib/webspicy/tester/rspec_asserter.rb +0 -108
  108. data/lib/webspicy/tester/rspec_matchers.rb +0 -104
  109. data/spec/unit/mocker/test_mocker.rb +0 -32
  110. data/spec/unit/openapi/test_generator.rb +0 -28
@@ -0,0 +1,8 @@
1
+ [
2
+ {
3
+ "name": "foo"
4
+ },
5
+ {
6
+ "name": "bar"
7
+ }
8
+ ]
@@ -0,0 +1 @@
1
+ Webspicy::SpecTests::Queue.new
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": 1,
3
+ "name": "single",
4
+ "version": {
5
+ "major": "1",
6
+ "minor": "0"
7
+ },
8
+ "hobbies": [
9
+ { "name": "programming"}
10
+ ]
11
+ }
@@ -0,0 +1,3 @@
1
+ ---
2
+ id: 3
3
+ name: 'YAML'
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ module Webspicy
4
+ module SpecTests
5
+ class Queue
6
+ include Webspicy::Support::World::Item
7
+
8
+ end
9
+ end
10
+ end
11
+
12
+ module Webspicy
13
+ module Support
14
+ describe World do
15
+
16
+ let(:config){
17
+ Configuration.new(restful_folder)
18
+ }
19
+
20
+ subject do
21
+ World.new Path.dir/"fixtures", config
22
+ end
23
+
24
+ it 'supports single objects' do
25
+ expect(subject.single.name).to eql("single")
26
+ expect(subject.single.version.minor).to eql("0")
27
+ expect(subject.single.hobbies[0].name).to eql("programming")
28
+ end
29
+
30
+ it 'supports yaml too' do
31
+ expect(subject.yaml.name).to eql("YAML")
32
+ end
33
+
34
+ it 'supports arrays' do
35
+ expect(subject.array[0].name).to eql("foo")
36
+ expect(subject.array[1].name).to eql("bar")
37
+ end
38
+
39
+ it 'allows setting new attributes on itself' do
40
+ subject.foo = "bar"
41
+ expect(subject.foo).to eql("bar")
42
+ end
43
+
44
+ it 'allows setting new attributes on existing objects' do
45
+ subject.single.foo = "bar"
46
+ expect(subject.single.foo).to eql("bar")
47
+ end
48
+
49
+ it 'supports ruby files and evaluates them' do
50
+ q = subject.queue
51
+ expect(q).to be_a(Webspicy::SpecTests::Queue)
52
+ expect(q.config).to be(config)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -40,7 +40,7 @@ module Webspicy
40
40
  end
41
41
 
42
42
  it 'supports a single .yml file and returns a specific configuration instance' do
43
- file = restful_folder/"todo/getTodo.yml"
43
+ file = restful_folder/"formaldef/todo/get.yml"
44
44
  c = Configuration.dress(file)
45
45
  expect(c).to be_a(Configuration)
46
46
  expect(c.folder).to eq(restful_folder)
@@ -48,6 +48,11 @@ module Webspicy
48
48
  expect(c.each_scope.to_a.first.each_specification.to_a.size).to eql(1)
49
49
  end
50
50
 
51
+ it 'exposes the world as a World instance' do
52
+ c = Configuration.dress(restful_folder)
53
+ expect(c.world).to be_a(Support::World)
54
+ end
55
+
51
56
  it 'yields the block with the configuration, if given' do
52
57
  seen = nil
53
58
  Configuration.dress(Path.dir/'configuration'){|c|
@@ -106,6 +111,7 @@ module Webspicy
106
111
  ENV['ROBUST'] = 'yes'
107
112
  config = Configuration.new
108
113
  expect(config.run_counterexamples?).to eql(true)
114
+ ENV.delete('ROBUST')
109
115
  end
110
116
 
111
117
  it 'ignores the environment is set explicitly' do
@@ -114,6 +120,7 @@ module Webspicy
114
120
  c.run_counterexamples = false
115
121
  end
116
122
  expect(config.run_counterexamples?).to eql(false)
123
+ ENV.delete('ROBUST')
117
124
  end
118
125
  end
119
126
 
@@ -130,6 +137,7 @@ module Webspicy
130
137
  expect(config.file_filter).to be_a(Regexp)
131
138
  expect(config.file_filter).to match("foo/bar/getTodo.yml")
132
139
  expect(config.file_filter).not_to match("foo/bar/getTodos.yml")
140
+ ENV.delete('RESOURCE')
133
141
  end
134
142
 
135
143
  it 'allows expressing a no match' do
@@ -138,6 +146,7 @@ module Webspicy
138
146
  expect(config.file_filter).to be_a(Proc)
139
147
  expect(config.file_filter.call("foo/bar/getTodos.yml")).to eq(true)
140
148
  expect(config.file_filter.call("foo/bar/getTodo.yml")).to eq(false)
149
+ ENV.delete('RESOURCE')
141
150
  end
142
151
 
143
152
  it 'ignores the environment if set explicitly' do
@@ -146,6 +155,7 @@ module Webspicy
146
155
  c.file_filter = nil
147
156
  end
148
157
  expect(config.file_filter).to be_nil
158
+ ENV.delete('RESOURCE')
149
159
  end
150
160
  end
151
161
 
@@ -160,6 +170,7 @@ module Webspicy
160
170
  ENV['METHOD'] = 'GET'
161
171
  config = Configuration.new
162
172
  expect(config.service_filter).to be_a(Proc)
173
+ ENV.delete('METHOD')
163
174
  end
164
175
 
165
176
  it 'ignores the environment is set explicitly' do
@@ -168,6 +179,36 @@ module Webspicy
168
179
  c.service_filter = nil
169
180
  end
170
181
  expect(config.service_filter).to be_nil
182
+ ENV.delete('METHOD')
183
+ end
184
+ end
185
+
186
+ describe 'insecure' do
187
+
188
+ it 'is false by default' do
189
+ config = Configuration.new
190
+ expect(config.insecure).to eql(false)
191
+ end
192
+
193
+ it 'is true if INSECURE is set to yes' do
194
+ ENV['INSECURE'] = 'yes'
195
+ config = Configuration.new
196
+ expect(config.insecure).to eql(true)
197
+ ENV.delete('INSECURE')
198
+ end
199
+
200
+ it 'is true if INSECURE is set to 1' do
201
+ ENV['INSECURE'] = '1'
202
+ config = Configuration.new
203
+ expect(config.insecure).to eql(true)
204
+ ENV.delete('INSECURE')
205
+ end
206
+
207
+ it 'is false if INSECURE is set to no' do
208
+ ENV['INSECURE'] = 'no'
209
+ config = Configuration.new
210
+ expect(config.insecure).to eql(false)
211
+ ENV.delete('INSECURE')
171
212
  end
172
213
  end
173
214
 
@@ -187,48 +228,56 @@ module Webspicy
187
228
  ENV['TAG'] = 'foo'
188
229
  expect(subject).to be_a(Proc)
189
230
  expect(subject.call(tc)).to eql(true)
231
+ ENV.delete('TAG')
190
232
  end
191
233
 
192
234
  it 'allows no matching a single tag' do
193
235
  ENV['TAG'] = 'baz'
194
236
  expect(subject).to be_a(Proc)
195
237
  expect(subject.call(tc)).to eql(false)
238
+ ENV.delete('TAG')
196
239
  end
197
240
 
198
241
  it 'allows setting multiple tags' do
199
242
  ENV['TAG'] = 'foo,baz'
200
243
  expect(subject).to be_a(Proc)
201
244
  expect(subject.call(tc)).to eql(true)
245
+ ENV.delete('TAG')
202
246
  end
203
247
 
204
248
  it 'allows no matching any of multiple tags' do
205
249
  ENV['TAG'] = 'foi,baz'
206
250
  expect(subject).to be_a(Proc)
207
251
  expect(subject.call(tc)).to eql(false)
252
+ ENV.delete('TAG')
208
253
  end
209
254
 
210
255
  it 'allows setting a single negative tag' do
211
256
  ENV['TAG'] = '!foo'
212
257
  expect(subject).to be_a(Proc)
213
258
  expect(subject.call(tc)).to eql(false)
259
+ ENV.delete('TAG')
214
260
  end
215
261
 
216
262
  it 'allows not matching a single negative tag' do
217
263
  ENV['TAG'] = '!baz'
218
264
  expect(subject).to be_a(Proc)
219
265
  expect(subject.call(tc)).to eql(true)
266
+ ENV.delete('TAG')
220
267
  end
221
268
 
222
269
  it 'allows mixing positive & negative tags and have a match' do
223
270
  ENV['TAG'] = 'foo,!baz'
224
271
  expect(subject).to be_a(Proc)
225
272
  expect(subject.call(tc)).to eql(true)
273
+ ENV.delete('TAG')
226
274
  end
227
275
 
228
276
  it 'allows mixing positive & negative tags and have no match' do
229
277
  ENV['TAG'] = 'foo,!bar'
230
278
  expect(subject).to be_a(Proc)
231
279
  expect(subject.call(tc)).to eql(false)
280
+ ENV.delete('TAG')
232
281
  end
233
282
 
234
283
  end
@@ -3,10 +3,75 @@ require 'spec_helper'
3
3
  module Webspicy
4
4
  class Tester
5
5
  describe Asserter do
6
- let(:asserter) { Asserter.new(target) }
6
+ describe '#includes' do
7
+ it 'returns nil when the value is found in an array' do
8
+ expect(Asserter.new([:a, 'foo', 99]).includes('', 'foo'))
9
+ .to eq nil
10
+ end
11
+
12
+ it 'returns nil when the assertion is identical to a non-array' do
13
+ expect(Asserter.new({ foo: Time.at(0) }).includes('', { foo: Time.at(0) }))
14
+ .to eq nil
15
+ end
16
+
17
+ it 'raises an exception with a descriptive message when the assertion is false' do
18
+ expect { Asserter.new([:a, 'foo', 99]).includes('', 42) }
19
+ .to raise_exception Failure,
20
+ 'Expected ["a","foo",99] to include 42'
21
+
22
+ end
23
+ end
24
+
25
+ describe '#notIncludes' do
26
+ it 'returns nil when the value is not found in an array' do
27
+ expect(Asserter.new([:a, 'foo', 99]).notIncludes('', 'boom'))
28
+ .to eq nil
29
+ end
30
+
31
+ it 'returns nil when the assertion and target are not identical' do
32
+ expect(Asserter.new({ foo: Time.at(0) }).notIncludes('', 'LOL'))
33
+ .to eq nil
34
+ end
35
+
36
+ it 'raises an exception with a descriptive message when the assertion is false' do
37
+ expect { Asserter.new([:a, 'foo', 99]).notIncludes('', 'foo') }
38
+ .to raise_exception Failure,
39
+ 'Expected ["a","foo",99] not to include foo'
40
+ end
41
+ end
42
+
43
+ describe '#empty' do
44
+ it 'returns nil when the target is empty' do
45
+ expect(Asserter.new([]).empty).to eq nil
46
+ expect(Asserter.new({}).empty).to eq nil
47
+ end
48
+
49
+ it 'raises an exception with a descriptive message when the assertion is false' do
50
+ expect { Asserter.new(['foo']).empty }
51
+ .to raise_exception Failure,
52
+ 'Expected ["foo"] to be empty'
53
+ end
54
+ end
55
+
56
+ describe '#notEmpty' do
57
+ it 'returns nil when the target is not empty' do
58
+ expect(Asserter.new(['foo']).notEmpty).to eq nil
59
+ expect(Asserter.new({ foo: 'bar' }).notEmpty).to eq nil
60
+ end
61
+
62
+ it 'raises an exception with a descriptive message when the assertion is false' do
63
+ expect { Asserter.new([]).notEmpty }
64
+ .to raise_exception Failure,
65
+ 'Expected [] to be non empty'
66
+ expect { Asserter.new({}).notEmpty }
67
+ .to raise_exception Failure,
68
+ 'Expected {} to be non empty'
69
+ end
70
+ end
7
71
 
8
72
  describe '#size' do
9
73
  let(:target) { [1, 2, 3, 4] }
74
+ let(:asserter) { Asserter.new(target) }
10
75
 
11
76
  it 'returns nil when the assertion is true for a plain array' do
12
77
  expect(asserter.size('', 4)).to eq nil
@@ -14,7 +79,7 @@ module Webspicy
14
79
 
15
80
  it 'raises an exception with a descriptive message when the assertion is false' do
16
81
  expect { asserter.size('', 3) }
17
- .to raise_exception RuntimeError, 'Expected [1,2,3,4] to have a size of 3, actual size is: 4'
82
+ .to raise_exception Failure, 'Expected [1,2,3,4] to have a size of 3, actual size is: 4'
18
83
  end
19
84
 
20
85
  context 'with a string' do
@@ -34,7 +99,7 @@ module Webspicy
34
99
 
35
100
  it 'raises an exception with a descriptive message when the assertion is false' do
36
101
  expect { asserter.size('foo/2/bar', 99) }
37
- .to raise_exception RuntimeError,
102
+ .to raise_exception Failure,
38
103
  'Expected [10,11,12] to have a size of 99, actual size is: 3'
39
104
  end
40
105
 
@@ -45,6 +110,136 @@ module Webspicy
45
110
  end
46
111
  end
47
112
  end
113
+
114
+ describe '#idIn' do
115
+ it 'returns nil when the specified ids match exactly' do
116
+ expect(Asserter.new([{ id: 1 }, { id: 2 }]).idIn('', 1, 2)).to eq nil
117
+ expect(Asserter.new({ id: 123 }).idIn('', 123)).to eq nil
118
+
119
+ os = OpenStruct.new(id: 'foo')
120
+ expect(Asserter.new(os).idIn('', 'foo')).to eq nil
121
+ end
122
+
123
+ it 'raises an exception with a descriptive message when the assertion is false' do
124
+ expect { Asserter.new([{ id: 1}, { id: 2}]).idIn('', 123, 125) }
125
+ .to raise_exception Failure,
126
+ 'Expected [{"id":1},{"id":2}] to have ids 123,125'
127
+ expect { Asserter.new([{ id: 1}, { id: 2}]).idIn('', 1, 2, 3) }
128
+ .to raise_exception Failure,
129
+ 'Expected [{"id":1},{"id":2}] to have ids 1,2,3'
130
+ expect { Asserter.new([{ id: 1}, { id: 2}]).idIn('', 1) }
131
+ .to raise_exception Failure,
132
+ 'Expected [{"id":1},{"id":2}] to have ids 1'
133
+ end
134
+ end
135
+
136
+ describe '#idNotIn' do
137
+ it 'returns nil when the specified ids do not match exactly' do
138
+ expect(Asserter.new([{ id: 1 }, { id: 2 }]).idNotIn('', 123, 125)).to eq nil
139
+ expect(Asserter.new({ id: 123 }).idNotIn('', 1, 2, 3)).to eq nil
140
+ expect(Asserter.new({ id: 123 }).idNotIn('', 1)).to eq nil
141
+ end
142
+
143
+ it 'raises an exception with a descriptive message when the assertion is false' do
144
+ expect { Asserter.new([{ id: 1}, { id: 2}]).idNotIn('', 1, 2) }
145
+ .to raise_exception Failure,
146
+ 'Expected [{"id":1},{"id":2}] to not have ids 1,2'
147
+ expect { Asserter.new({ id: 1}).idNotIn('', 1) }
148
+ .to raise_exception Failure,
149
+ 'Expected {"id":1} to not have ids 1'
150
+
151
+ os = OpenStruct.new(id: 'foo')
152
+ expect { Asserter.new(os).idNotIn('', 'foo') }
153
+ .to raise_exception Failure,
154
+ 'Expected "#<OpenStruct id=\"foo\">"... to not have ids foo'
155
+ end
156
+ end
157
+ end
158
+
159
+ describe '#idFD' do
160
+ let(:target) do
161
+ [
162
+ { id: 1, a: 'a1', b: 'b1' },
163
+ { id: 2, a: 'a2', b: 'b2' }
164
+ ]
165
+ end
166
+
167
+ it 'returns nil when the element with specified id matches the expected keys-value pairs' do
168
+ expect(Asserter.new(target).idFD('', 2, { b: 'b2' })).to eq nil
169
+ expect(Asserter.new(target).idFD('', 2, { a: 'a2', b: 'b2' })).to eq nil
170
+ end
171
+
172
+ it 'raises an exception when the assertion is false' do
173
+ expect { Asserter.new(target).idFD('', 2, { c: 'c2' }) }
174
+ .to raise_exception Failure,
175
+ 'Expected [{"id":1,"a":"a1","b":"b1"... ' \
176
+ 'to contain the key(s) and value(s) {:c=>"c2"}'
177
+ expect { Asserter.new(target).idFD('', 2, { b: 'b1' }) }
178
+ .to raise_exception Failure,
179
+ 'Expected [{"id":1,"a":"a1","b":"b1"... ' \
180
+ 'to contain the key(s) and value(s) {:b=>"b1"}'
181
+ end
182
+
183
+ it 'raises an exception with a descriptive message when no element with the specified id is present in target' do
184
+ expect { Asserter.new(target).idFD('', 3, { a: 'a3' }) }
185
+ .to raise_exception Failure,
186
+ 'Expected an element with id 3 to contain ' \
187
+ 'the key(s) and value(s) {:a=>"a3"}, '\
188
+ 'but there is no element with that id'
189
+ end
190
+ end
191
+
192
+ describe '#pathFD' do
193
+ let(:target) do
194
+ [
195
+ { a: 'a1', b: 'b1' },
196
+ { a: 'a2', b: 'b2' }
197
+ ]
198
+ end
199
+
200
+ it 'returns nil when the target matches the expected keys-value pairs' do
201
+ expect(Asserter.new(target).pathFD('0', { b: 'b1' })).to eq nil
202
+ expect(Asserter.new(target).pathFD('0', { a: 'a1', b: 'b1' })).to eq nil
203
+ expect(Asserter.new(target).pathFD('1', { b: 'b2' })).to eq nil
204
+ expect(Asserter.new(target).pathFD('1', { a: 'a2', b: 'b2' })).to eq nil
205
+ end
206
+
207
+ it 'raises an exception when the assertion is false' do
208
+ expect { Asserter.new(target).pathFD('0', { c: 'c2' }) }
209
+ .to raise_exception Failure,
210
+ 'Expected {"a":"a1","b":"b1"} ' \
211
+ 'to contain the key(s) and value(s) {:c=>"c2"}'
212
+ expect { Asserter.new(target).pathFD('0', { b: 'b2' }) }
213
+ .to raise_exception Failure,
214
+ 'Expected {"a":"a1","b":"b1"} ' \
215
+ 'to contain the key(s) and value(s) {:b=>"b2"}'
216
+ end
217
+ end
218
+
219
+ describe '#match' do
220
+ it 'returns nil when the target matches the specified regexp' do
221
+ expect(Asserter.new('Empathise').match('', /path/)).to eq nil
222
+ expect(Asserter.new('Empathise').match('', /.mp/)).to eq nil
223
+ end
224
+
225
+ it 'raises an exception when the assertion is false' do
226
+ expect { Asserter.new('Empathise').match('', /ize/) }
227
+ .to raise_exception Failure,
228
+ 'Expected "Empathise" to match /ize/'
229
+ end
230
+ end
231
+
232
+ describe '#notMatch' do
233
+ it 'returns nil when the target does not matche the specified regexp' do
234
+ expect(Asserter.new('Empathise').notMatch('', /ize/)).to eq nil
235
+ expect(Asserter.new('Empathise').notMatch('', /^path/)).to eq nil
236
+ end
237
+
238
+ it 'raises an exception when the assertion is false' do
239
+ expect { Asserter.new('Empathise').notMatch('', /path/) }
240
+ .to raise_exception Failure,
241
+ 'Expected "Empathise" not to match /path/'
242
+ end
48
243
  end
49
244
  end
50
245
  end