rspec-expectations 2.11.3 → 3.11.0

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.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +1 -1
  5. data/Changelog.md +1026 -21
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +174 -78
  8. data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
  9. data/lib/rspec/expectations/configuration.rb +230 -0
  10. data/lib/rspec/expectations/expectation_target.rb +130 -55
  11. data/lib/rspec/expectations/fail_with.rb +17 -33
  12. data/lib/rspec/expectations/failure_aggregator.rb +212 -0
  13. data/lib/rspec/expectations/handler.rb +163 -29
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -54
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +59 -24
  18. data/lib/rspec/matchers/aliased_matcher.rb +116 -0
  19. data/lib/rspec/matchers/built_in/all.rb +86 -0
  20. data/lib/rspec/matchers/built_in/base_matcher.rb +150 -20
  21. data/lib/rspec/matchers/built_in/be.rb +115 -109
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +43 -17
  26. data/lib/rspec/matchers/built_in/change.rb +392 -75
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -0
  29. data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
  30. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  31. data/lib/rspec/matchers/built_in/eq.rb +26 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +19 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +56 -19
  34. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  35. data/lib/rspec/matchers/built_in/has.rb +141 -22
  36. data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
  37. data/lib/rspec/matchers/built_in/include.rb +175 -20
  38. data/lib/rspec/matchers/built_in/match.rb +95 -1
  39. data/lib/rspec/matchers/built_in/operators.rb +128 -0
  40. data/lib/rspec/matchers/built_in/output.rb +207 -0
  41. data/lib/rspec/matchers/built_in/raise_error.rb +212 -38
  42. data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
  43. data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
  44. data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
  45. data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
  46. data/lib/rspec/matchers/built_in/yield.rb +252 -98
  47. data/lib/rspec/matchers/built_in.rb +47 -33
  48. data/lib/rspec/matchers/composable.rb +171 -0
  49. data/lib/rspec/matchers/dsl.rb +530 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
  52. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  53. data/lib/rspec/matchers/generated_descriptions.rb +15 -10
  54. data/lib/rspec/matchers/matcher_delegator.rb +35 -0
  55. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  56. data/lib/rspec/matchers.rb +604 -252
  57. data.tar.gz.sig +0 -0
  58. metadata +178 -278
  59. metadata.gz.sig +0 -0
  60. data/features/README.md +0 -49
  61. data/features/Upgrade.md +0 -53
  62. data/features/built_in_matchers/README.md +0 -90
  63. data/features/built_in_matchers/be.feature +0 -173
  64. data/features/built_in_matchers/be_within.feature +0 -46
  65. data/features/built_in_matchers/cover.feature +0 -45
  66. data/features/built_in_matchers/end_with.feature +0 -46
  67. data/features/built_in_matchers/equality.feature +0 -145
  68. data/features/built_in_matchers/exist.feature +0 -43
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -138
  71. data/features/built_in_matchers/have.feature +0 -103
  72. data/features/built_in_matchers/include.feature +0 -121
  73. data/features/built_in_matchers/match.feature +0 -50
  74. data/features/built_in_matchers/operators.feature +0 -221
  75. data/features/built_in_matchers/predicates.feature +0 -128
  76. data/features/built_in_matchers/respond_to.feature +0 -78
  77. data/features/built_in_matchers/satisfy.feature +0 -31
  78. data/features/built_in_matchers/start_with.feature +0 -46
  79. data/features/built_in_matchers/throw_symbol.feature +0 -85
  80. data/features/built_in_matchers/types.feature +0 -114
  81. data/features/built_in_matchers/yield.feature +0 -146
  82. data/features/custom_matchers/access_running_example.feature +0 -53
  83. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  84. data/features/custom_matchers/define_matcher.feature +0 -340
  85. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  86. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  87. data/features/customized_message.feature +0 -22
  88. data/features/diffing.feature +0 -85
  89. data/features/implicit_docstrings.feature +0 -52
  90. data/features/step_definitions/additional_cli_steps.rb +0 -22
  91. data/features/support/env.rb +0 -5
  92. data/features/syntax_configuration.feature +0 -68
  93. data/features/test_frameworks/test_unit.feature +0 -46
  94. data/lib/rspec/expectations/deprecation.rb +0 -38
  95. data/lib/rspec/expectations/differ.rb +0 -81
  96. data/lib/rspec/expectations/errors.rb +0 -9
  97. data/lib/rspec/expectations/extensions/array.rb +0 -9
  98. data/lib/rspec/expectations/extensions/object.rb +0 -39
  99. data/lib/rspec/expectations/extensions.rb +0 -2
  100. data/lib/rspec/matchers/be_close.rb +0 -9
  101. data/lib/rspec/matchers/built_in/have.rb +0 -108
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -45
  103. data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
  104. data/lib/rspec/matchers/compatibility.rb +0 -14
  105. data/lib/rspec/matchers/configuration.rb +0 -66
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -299
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -84
  110. data/lib/rspec/matchers/pretty.rb +0 -60
  111. data/lib/rspec-expectations.rb +0 -1
  112. data/spec/rspec/expectations/differ_spec.rb +0 -153
  113. data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
  114. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  115. data/spec/rspec/expectations/fail_with_spec.rb +0 -70
  116. data/spec/rspec/expectations/handler_spec.rb +0 -206
  117. data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
  118. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  119. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
  120. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
  121. data/spec/rspec/matchers/be_spec.rb +0 -452
  122. data/spec/rspec/matchers/be_within_spec.rb +0 -80
  123. data/spec/rspec/matchers/change_spec.rb +0 -528
  124. data/spec/rspec/matchers/configuration_spec.rb +0 -202
  125. data/spec/rspec/matchers/cover_spec.rb +0 -69
  126. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  127. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  128. data/spec/rspec/matchers/eq_spec.rb +0 -54
  129. data/spec/rspec/matchers/eql_spec.rb +0 -41
  130. data/spec/rspec/matchers/equal_spec.rb +0 -60
  131. data/spec/rspec/matchers/exist_spec.rb +0 -110
  132. data/spec/rspec/matchers/has_spec.rb +0 -118
  133. data/spec/rspec/matchers/have_spec.rb +0 -461
  134. data/spec/rspec/matchers/include_spec.rb +0 -367
  135. data/spec/rspec/matchers/match_array_spec.rb +0 -124
  136. data/spec/rspec/matchers/match_spec.rb +0 -61
  137. data/spec/rspec/matchers/matcher_spec.rb +0 -434
  138. data/spec/rspec/matchers/matchers_spec.rb +0 -31
  139. data/spec/rspec/matchers/method_missing_spec.rb +0 -24
  140. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
  141. data/spec/rspec/matchers/raise_error_spec.rb +0 -344
  142. data/spec/rspec/matchers/respond_to_spec.rb +0 -295
  143. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  144. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
  145. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  146. data/spec/rspec/matchers/yield_spec.rb +0 -402
  147. data/spec/spec_helper.rb +0 -27
  148. data/spec/support/classes.rb +0 -56
  149. data/spec/support/in_sub_process.rb +0 -31
  150. data/spec/support/matchers.rb +0 -22
  151. data/spec/support/ruby_version.rb +0 -10
  152. data/spec/support/shared_examples.rb +0 -13
@@ -1,367 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "#include matcher" do
4
- it "is diffable" do
5
- include("a").should be_diffable
6
- end
7
-
8
- describe "should include(with_one_arg)" do
9
- it_behaves_like "an RSpec matcher", :valid_value => [1, 2], :invalid_value => [1] do
10
- let(:matcher) { include(2) }
11
- end
12
-
13
- context "for a string target" do
14
- it "passes if target includes expected" do
15
- "abc".should include("a")
16
- end
17
-
18
- it "fails if target does not include expected" do
19
- lambda {
20
- "abc".should include("d")
21
- }.should fail_matching("expected \"abc\" to include \"d\"")
22
- end
23
-
24
- it "includes a diff when actual is multiline" do
25
- lambda {
26
- "abc\ndef".should include("g")
27
- }.should fail_matching("expected \"abc\\ndef\" to include \"g\"\nDiff")
28
- end
29
-
30
- it "includes a diff when actual is multiline and there are multiple expecteds" do
31
- lambda {
32
- "abc\ndef".should include("g", "h")
33
- }.should fail_matching("expected \"abc\\ndef\" to include \"g\" and \"h\"\nDiff")
34
- end
35
- end
36
-
37
- context "for an array target" do
38
- it "passes if target includes expected" do
39
- [1,2,3].should include(3)
40
- end
41
-
42
- it "fails if target does not include expected" do
43
- lambda {
44
- [1,2,3].should include(4)
45
- }.should fail_matching("expected [1, 2, 3] to include 4")
46
- end
47
- end
48
-
49
- context "for a hash target" do
50
- it 'passes if target has the expected as a key' do
51
- {:key => 'value'}.should include(:key)
52
- end
53
-
54
- it "fails if target does not include expected" do
55
- lambda {
56
- {:key => 'value'}.should include(:other)
57
- }.should fail_matching(%Q|expected {:key=>"value"} to include :other|)
58
- end
59
- end
60
- end
61
-
62
- describe "should include(with, multiple, args)" do
63
- it "has a description" do
64
- matcher = include("a")
65
- matcher.description.should eq("include \"a\"")
66
- end
67
- context "for a string target" do
68
- it "passes if target includes all items" do
69
- "a string".should include("str", "a")
70
- end
71
-
72
- it "fails if target does not include any one of the items" do
73
- lambda {
74
- "a string".should include("str", "a", "foo")
75
- }.should fail_matching(%Q{expected "a string" to include "str", "a", and "foo"})
76
- end
77
- end
78
-
79
- context "for an array target" do
80
- it "passes if target includes all items" do
81
- [1,2,3].should include(1,2,3)
82
- end
83
-
84
- it "fails if target does not include any one of the items" do
85
- lambda {
86
- [1,2,3].should include(1,2,4)
87
- }.should fail_matching("expected [1, 2, 3] to include 1, 2, and 4")
88
- end
89
- end
90
-
91
- context "for a hash target" do
92
- it 'passes if target includes all items as keys' do
93
- {:key => 'value', :other => 'value'}.should include(:key, :other)
94
- end
95
-
96
- it 'fails if target is missing any item as a key' do
97
- lambda {
98
- {:key => 'value'}.should include(:key, :other)
99
- }.should fail_matching(%Q|expected {:key=>"value"} to include :key and :other|)
100
- end
101
- end
102
- end
103
-
104
- describe "should_not include(expected)" do
105
- context "for a string target" do
106
- it "passes if target does not include expected" do
107
- "abc".should_not include("d")
108
- end
109
-
110
- it "fails if target includes expected" do
111
- lambda {
112
- "abc".should_not include("c")
113
- }.should fail_with("expected \"abc\" not to include \"c\"")
114
- end
115
- end
116
-
117
- context "for an array target" do
118
- it "passes if target does not include expected" do
119
- [1,2,3].should_not include(4)
120
- end
121
-
122
- it "fails if target includes expected" do
123
- lambda {
124
- [1,2,3].should_not include(3)
125
- }.should fail_with("expected [1, 2, 3] not to include 3")
126
- end
127
- end
128
-
129
- context "for a hash target" do
130
- it 'passes if target does not have the expected as a key' do
131
- {:other => 'value'}.should_not include(:key)
132
- end
133
-
134
- it "fails if target includes expected key" do
135
- lambda {
136
- {:key => 'value'}.should_not include(:key)
137
- }.should fail_matching(%Q|expected {:key=>"value"} not to include :key|)
138
- end
139
- end
140
-
141
- end
142
-
143
- describe "should_not include(with, multiple, args)" do
144
- context "for a string target" do
145
- it "passes if the target does not include any of the expected" do
146
- "abc".should_not include("d", "e", "f")
147
- end
148
-
149
- it "fails if the target includes all of the expected" do
150
- expect {
151
- "abc".should_not include("c", "a")
152
- }.to fail_with('expected "abc" not to include "c" and "a"')
153
- end
154
-
155
- it "fails if the target includes some (but not all) of the expected" do
156
- expect {
157
- "abc".should_not include("d", "a")
158
- }.to fail_with(%q{expected "abc" not to include "d" and "a"})
159
- end
160
- end
161
-
162
- context "for a hash target" do
163
- it "passes if it does not include any of the expected keys" do
164
- { :a => 1, :b => 2 }.should_not include(:c, :d)
165
- end
166
-
167
- it "fails if the target includes all of the expected keys" do
168
- expect {
169
- { :a => 1, :b => 2 }.should_not include(:a, :b)
170
- }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :a and :b|)
171
- end
172
-
173
- it "fails if the target includes some (but not all) of the expected keys" do
174
- expect {
175
- { :a => 1, :b => 2 }.should_not include(:d, :b)
176
- }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :d and :b|)
177
- end
178
- end
179
-
180
- context "for an array target" do
181
- it "passes if the target does not include any of the expected" do
182
- [1, 2, 3].should_not include(4, 5, 6)
183
- end
184
-
185
- it "fails if the target includes all of the expected" do
186
- expect {
187
- [1, 2, 3].should_not include(3, 1)
188
- }.to fail_with(%q{expected [1, 2, 3] not to include 3 and 1})
189
- end
190
-
191
- it "fails if the target includes some (but not all) of the expected" do
192
- expect {
193
- [1, 2, 3].should_not include(4, 1)
194
- }.to fail_with(%q{expected [1, 2, 3] not to include 4 and 1})
195
- end
196
- end
197
- end
198
-
199
- describe "should include(:key => value)" do
200
- context 'for a hash target' do
201
- it "passes if target includes the key/value pair" do
202
- {:key => 'value'}.should include(:key => 'value')
203
- end
204
-
205
- it "passes if target includes the key/value pair among others" do
206
- {:key => 'value', :other => 'different'}.should include(:key => 'value')
207
- end
208
-
209
- it "fails if target has a different value for key" do
210
- lambda {
211
- {:key => 'different'}.should include(:key => 'value')
212
- }.should fail_matching(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
213
- end
214
-
215
- it "fails if target has a different key" do
216
- lambda {
217
- {:other => 'value'}.should include(:key => 'value')
218
- }.should fail_matching(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
219
- end
220
- end
221
-
222
- context 'for a non-hash target' do
223
- it "fails if the target does not contain the given hash" do
224
- lambda {
225
- ['a', 'b'].should include(:key => 'value')
226
- }.should fail_matching(%q|expected ["a", "b"] to include {:key=>"value"}|)
227
- end
228
-
229
- it "passes if the target contains the given hash" do
230
- ['a', { :key => 'value' } ].should include(:key => 'value')
231
- end
232
- end
233
- end
234
-
235
- describe "should_not include(:key => value)" do
236
- context 'for a hash target' do
237
- it "fails if target includes the key/value pair" do
238
- lambda {
239
- {:key => 'value'}.should_not include(:key => 'value')
240
- }.should fail_matching(%Q|expected {:key=>"value"} not to include {:key=>"value"}|)
241
- end
242
-
243
- it "fails if target includes the key/value pair among others" do
244
- lambda {
245
- {:key => 'value', :other => 'different'}.should_not include(:key => 'value')
246
- }.should fail_matching(%Q|expected #{{:key=>"value", :other=>"different"}.inspect} not to include {:key=>"value"}|)
247
- end
248
-
249
- it "passes if target has a different value for key" do
250
- {:key => 'different'}.should_not include(:key => 'value')
251
- end
252
-
253
- it "passes if target has a different key" do
254
- {:other => 'value'}.should_not include(:key => 'value')
255
- end
256
- end
257
-
258
- context "for a non-hash target" do
259
- it "passes if the target does not contain the given hash" do
260
- ['a', 'b'].should_not include(:key => 'value')
261
- end
262
-
263
- it "fails if the target contains the given hash" do
264
- lambda {
265
- ['a', { :key => 'value' } ].should_not include(:key => 'value')
266
- }.should fail_matching(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
267
- end
268
- end
269
- end
270
-
271
- describe "should include(:key1 => value1, :key2 => value2)" do
272
- context 'for a hash target' do
273
- it "passes if target includes the key/value pairs" do
274
- {:a => 1, :b => 2}.should include(:b => 2, :a => 1)
275
- end
276
-
277
- it "passes if target includes the key/value pairs among others" do
278
- {:a => 1, :c => 3, :b => 2}.should include(:b => 2, :a => 1)
279
- end
280
-
281
- it "fails if target has a different value for one of the keys" do
282
- lambda {
283
- {:a => 1, :b => 2}.should include(:a => 2, :b => 2)
284
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
285
- end
286
-
287
- it "fails if target has a different value for both of the keys" do
288
- lambda {
289
- {:a => 1, :b => 1}.should include(:a => 2, :b => 2)
290
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
291
- end
292
-
293
- it "fails if target lacks one of the keys" do
294
- lambda {
295
- {:a => 1, :b => 1}.should include(:a => 1, :c => 1)
296
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>1, :c=>1}.inspect}|)
297
- end
298
-
299
- it "fails if target lacks both of the keys" do
300
- lambda {
301
- {:a => 1, :b => 1}.should include(:c => 1, :d => 1)
302
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:c=>1, :d=>1}.inspect}|)
303
- end
304
- end
305
-
306
- context 'for a non-hash target' do
307
- it "fails if the target does not contain the given hash" do
308
- lambda {
309
- ['a', 'b'].should include(:a => 1, :b => 1)
310
- }.should fail_matching(%Q|expected ["a", "b"] to include #{{:a=>1, :b=>1}.inspect}|)
311
- end
312
-
313
- it "passes if the target contains the given hash" do
314
- ['a', { :a => 1, :b => 2 } ].should include(:a => 1, :b => 2)
315
- end
316
- end
317
- end
318
-
319
- describe "should_not include(:key1 => value1, :key2 => value2)" do
320
- context 'for a hash target' do
321
- it "fails if target includes the key/value pairs" do
322
- lambda {
323
- {:a => 1, :b => 2}.should_not include(:a => 1, :b => 2)
324
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
325
- end
326
-
327
- it "fails if target includes the key/value pairs among others" do
328
- hash = {:a => 1, :b => 2, :c => 3}
329
- lambda {
330
- hash.should_not include(:a => 1, :b => 2)
331
- }.should fail_matching(%Q|expected #{hash.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
332
- end
333
-
334
- it "fails if target has a different value for one of the keys" do
335
- lambda {
336
- {:a => 1, :b => 2}.should_not include(:a => 2, :b => 2)
337
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>2, :b=>2}.inspect}|)
338
- end
339
-
340
- it "passes if target has a different value for both of the keys" do
341
- {:a => 1, :b => 1}.should_not include(:a => 2, :b => 2)
342
- end
343
-
344
- it "fails if target lacks one of the keys" do
345
- lambda {
346
- {:a => 1, :b => 1}.should_not include(:a => 1, :c => 1)
347
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} not to include #{{:a=>1, :c=>1}.inspect}|)
348
- end
349
-
350
- it "passes if target lacks both of the keys" do
351
- {:a => 1, :b => 1}.should_not include(:c => 1, :d => 1)
352
- end
353
- end
354
-
355
- context 'for a non-hash target' do
356
- it "passes if the target does not contain the given hash" do
357
- ['a', 'b'].should_not include(:a => 1, :b => 1)
358
- end
359
-
360
- it "fails if the target contains the given hash" do
361
- lambda {
362
- ['a', { :a => 1, :b => 2 } ].should_not include(:a => 1, :b => 2)
363
- }.should fail_matching(%Q|expected #{["a", {:a=>1, :b=>2}].inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
364
- end
365
- end
366
- end
367
- end
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class UnsortableObject
4
- def initialize(id)
5
- @id = id
6
- end
7
-
8
- def inspect
9
- @id.to_s
10
- end
11
-
12
- def ==(other)
13
- false
14
- end
15
- end
16
-
17
- describe "using match_array with expect" do
18
- it_behaves_like "an RSpec matcher", :valid_value => [1, 2], :invalid_value => [1] do
19
- let(:matcher) { match_array([2, 1]) }
20
- end
21
-
22
- it "passes a valid positive expectation" do
23
- expect([1, 2]).to match_array [2, 1]
24
- end
25
-
26
- it "fails an invalid positive expectation" do
27
- expect {
28
- expect([1, 2, 3]).to match_array [2, 1]
29
- }.to fail_with(/expected collection contained/)
30
- end
31
- end
32
-
33
- describe "array.should =~ other_array" do
34
- it "passes if target contains all items" do
35
- [1,2,3].should =~ [1,2,3]
36
- end
37
-
38
- it "passes if target contains all items out of order" do
39
- [1,3,2].should =~ [1,2,3]
40
- end
41
-
42
- it "fails if target includes extra items" do
43
- lambda {
44
- [1,2,3,4].should =~ [1,2,3]
45
- }.should fail_with(<<-MESSAGE)
46
- expected collection contained: [1, 2, 3]
47
- actual collection contained: [1, 2, 3, 4]
48
- the extra elements were: [4]
49
- MESSAGE
50
- end
51
-
52
- it "fails if target is missing items" do
53
- lambda {
54
- [1,2].should =~ [1,2,3]
55
- }.should fail_with(<<-MESSAGE)
56
- expected collection contained: [1, 2, 3]
57
- actual collection contained: [1, 2]
58
- the missing elements were: [3]
59
- MESSAGE
60
- end
61
-
62
- it "fails if target is missing items and has extra items" do
63
-
64
- lambda {
65
- [1,2,4].should =~ [1,2,3]
66
- }.should fail_with(<<-MESSAGE)
67
- expected collection contained: [1, 2, 3]
68
- actual collection contained: [1, 2, 4]
69
- the missing elements were: [3]
70
- the extra elements were: [4]
71
- MESSAGE
72
- end
73
-
74
- it "sorts items in the error message if they all respond to <=>" do
75
- lambda {
76
- [6,2,1,5].should =~ [4,1,2,3]
77
- }.should fail_with(<<-MESSAGE)
78
- expected collection contained: [1, 2, 3, 4]
79
- actual collection contained: [1, 2, 5, 6]
80
- the missing elements were: [3, 4]
81
- the extra elements were: [5, 6]
82
- MESSAGE
83
- end
84
-
85
- it "does not sort items in the error message if they don't all respond to <=>" do
86
- lambda {
87
- [UnsortableObject.new(2), UnsortableObject.new(1)].should =~ [UnsortableObject.new(4), UnsortableObject.new(3)]
88
- }.should fail_with(<<-MESSAGE)
89
- expected collection contained: [4, 3]
90
- actual collection contained: [2, 1]
91
- the missing elements were: [4, 3]
92
- the extra elements were: [2, 1]
93
- MESSAGE
94
- end
95
-
96
- it "accurately reports extra elements when there are duplicates" do
97
- lambda {
98
- [1,1,1,5].should =~ [1,5]
99
- }.should fail_with(<<-MESSAGE)
100
- expected collection contained: [1, 5]
101
- actual collection contained: [1, 1, 1, 5]
102
- the extra elements were: [1, 1]
103
- MESSAGE
104
- end
105
-
106
- it "accurately reports missing elements when there are duplicates" do
107
- lambda {
108
- [1,5].should =~ [1,1,5]
109
- }.should fail_with(<<-MESSAGE)
110
- expected collection contained: [1, 1, 5]
111
- actual collection contained: [1, 5]
112
- the missing elements were: [1]
113
- MESSAGE
114
- end
115
-
116
- end
117
-
118
- describe "should_not =~ [:with, :multiple, :args]" do
119
- it "is not supported" do
120
- lambda {
121
- [1,2,3].should_not =~ [1,2,3]
122
- }.should fail_with(/Matcher does not support should_not/)
123
- end
124
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "should match(expected)" do
4
- it_behaves_like "an RSpec matcher", :valid_value => 'ab', :invalid_value => 'bc' do
5
- let(:matcher) { match(/a/) }
6
- end
7
-
8
- it "passes when target (String) matches expected (Regexp)" do
9
- "string".should match(/tri/)
10
- end
11
-
12
- it "passes when target (String) matches expected (String)" do
13
- "string".should match("tri")
14
- end
15
-
16
- it "fails when target (String) does not match expected (Regexp)" do
17
- lambda {
18
- "string".should match(/rings/)
19
- }.should fail
20
- end
21
-
22
- it "fails when target (String) does not match expected (String)" do
23
- lambda {
24
- "string".should match("rings")
25
- }.should fail
26
- end
27
-
28
- it "provides message, expected and actual on failure" do
29
- matcher = match(/rings/)
30
- matcher.matches?("string")
31
- matcher.failure_message_for_should.should == "expected \"string\" to match /rings/"
32
- end
33
- end
34
-
35
- describe "should_not match(expected)" do
36
- it "passes when target (String) matches does not match (Regexp)" do
37
- "string".should_not match(/rings/)
38
- end
39
-
40
- it "passes when target (String) matches does not match (String)" do
41
- "string".should_not match("rings")
42
- end
43
-
44
- it "fails when target (String) matches expected (Regexp)" do
45
- lambda {
46
- "string".should_not match(/tri/)
47
- }.should fail
48
- end
49
-
50
- it "fails when target (String) matches expected (String)" do
51
- lambda {
52
- "string".should_not match("tri")
53
- }.should fail
54
- end
55
-
56
- it "provides message, expected and actual on failure" do
57
- matcher = match(/tri/)
58
- matcher.matches?("string")
59
- matcher.failure_message_for_should_not.should == "expected \"string\" not to match /tri/"
60
- end
61
- end