rspec-expectations 2.14.0 → 3.13.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 (155) 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 +976 -25
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +162 -26
  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 +127 -51
  11. data/lib/rspec/expectations/fail_with.rb +17 -57
  12. data/lib/rspec/expectations/failure_aggregator.rb +229 -0
  13. data/lib/rspec/expectations/handler.rb +146 -32
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -100
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +58 -23
  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 +191 -20
  21. data/lib/rspec/matchers/built_in/be.rb +114 -114
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +15 -4
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +35 -18
  26. data/lib/rspec/matchers/built_in/change.rb +389 -80
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +310 -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 +30 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +23 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +55 -22
  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 +184 -32
  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 +192 -44
  42. data/lib/rspec/matchers/built_in/respond_to.rb +154 -28
  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 +240 -161
  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 +531 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  52. data/lib/rspec/matchers/generated_descriptions.rb +14 -8
  53. data/lib/rspec/matchers/matcher_delegator.rb +61 -0
  54. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  55. data/lib/rspec/matchers/multi_matcher_diff.rb +82 -0
  56. data/lib/rspec/matchers.rb +520 -173
  57. data.tar.gz.sig +0 -0
  58. metadata +141 -242
  59. metadata.gz.sig +2 -0
  60. data/features/README.md +0 -48
  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 -175
  64. data/features/built_in_matchers/be_within.feature +0 -48
  65. data/features/built_in_matchers/cover.feature +0 -47
  66. data/features/built_in_matchers/end_with.feature +0 -48
  67. data/features/built_in_matchers/equality.feature +0 -139
  68. data/features/built_in_matchers/exist.feature +0 -45
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -144
  71. data/features/built_in_matchers/have.feature +0 -109
  72. data/features/built_in_matchers/include.feature +0 -174
  73. data/features/built_in_matchers/match.feature +0 -52
  74. data/features/built_in_matchers/operators.feature +0 -227
  75. data/features/built_in_matchers/predicates.feature +0 -137
  76. data/features/built_in_matchers/respond_to.feature +0 -84
  77. data/features/built_in_matchers/satisfy.feature +0 -33
  78. data/features/built_in_matchers/start_with.feature +0 -48
  79. data/features/built_in_matchers/throw_symbol.feature +0 -91
  80. data/features/built_in_matchers/types.feature +0 -116
  81. data/features/built_in_matchers/yield.feature +0 -161
  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 -368
  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 -14
  92. data/features/syntax_configuration.feature +0 -71
  93. data/features/test_frameworks/test_unit.feature +0 -44
  94. data/lib/rspec/expectations/deprecation.rb +0 -17
  95. data/lib/rspec/expectations/differ.rb +0 -133
  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 -29
  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 -124
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  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 -108
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -300
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -109
  110. data/lib/rspec/matchers/pretty.rb +0 -70
  111. data/lib/rspec/matchers/test_unit_integration.rb +0 -11
  112. data/lib/rspec-expectations.rb +0 -1
  113. data/spec/rspec/expectations/differ_spec.rb +0 -192
  114. data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
  115. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  116. data/spec/rspec/expectations/fail_with_spec.rb +0 -114
  117. data/spec/rspec/expectations/handler_spec.rb +0 -227
  118. data/spec/rspec/expectations/syntax_spec.rb +0 -139
  119. data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
  120. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  121. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
  122. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
  123. data/spec/rspec/matchers/be_spec.rb +0 -516
  124. data/spec/rspec/matchers/be_within_spec.rb +0 -137
  125. data/spec/rspec/matchers/change_spec.rb +0 -553
  126. data/spec/rspec/matchers/configuration_spec.rb +0 -206
  127. data/spec/rspec/matchers/cover_spec.rb +0 -69
  128. data/spec/rspec/matchers/description_generation_spec.rb +0 -190
  129. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  130. data/spec/rspec/matchers/eq_spec.rb +0 -60
  131. data/spec/rspec/matchers/eql_spec.rb +0 -41
  132. data/spec/rspec/matchers/equal_spec.rb +0 -78
  133. data/spec/rspec/matchers/exist_spec.rb +0 -124
  134. data/spec/rspec/matchers/has_spec.rb +0 -122
  135. data/spec/rspec/matchers/have_spec.rb +0 -455
  136. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  137. data/spec/rspec/matchers/include_spec.rb +0 -531
  138. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  139. data/spec/rspec/matchers/match_spec.rb +0 -61
  140. data/spec/rspec/matchers/matcher_spec.rb +0 -471
  141. data/spec/rspec/matchers/matchers_spec.rb +0 -37
  142. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  143. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
  144. data/spec/rspec/matchers/raise_error_spec.rb +0 -485
  145. data/spec/rspec/matchers/respond_to_spec.rb +0 -292
  146. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  147. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
  148. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  149. data/spec/rspec/matchers/yield_spec.rb +0 -514
  150. data/spec/spec_helper.rb +0 -54
  151. data/spec/support/classes.rb +0 -56
  152. data/spec/support/in_sub_process.rb +0 -38
  153. data/spec/support/matchers.rb +0 -22
  154. data/spec/support/ruby_version.rb +0 -10
  155. data/spec/support/shared_examples.rb +0 -13
@@ -1,471 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class UnexpectedError < StandardError; end
4
- module MatcherHelperModule
5
- def self.included(base)
6
- base.module_eval do
7
- def included_method; end
8
- end
9
- end
10
-
11
- def self.extended(base)
12
- base.instance_eval do
13
- def extended_method; end
14
- end
15
- end
16
-
17
- def greeting
18
- "Hello, World"
19
- end
20
- end
21
-
22
- module RSpec::Matchers::DSL
23
- describe Matcher do
24
- it "can be stored aside and used later" do
25
- # Supports using rspec-expectation matchers as argument matchers in
26
- # rspec-mocks.
27
- RSpec::Matchers.define :example_matcher do |expected|
28
- match do |actual|
29
- actual == expected
30
- end
31
- end
32
-
33
- m1 = example_matcher(1)
34
- m2 = example_matcher(2)
35
-
36
- expect(m1.matches?(1)).to be_true
37
- expect(m2.matches?(2)).to be_true
38
- end
39
-
40
- context "with an included module" do
41
- let(:matcher) do
42
- RSpec::Matchers::DSL::Matcher.new(:be_a_greeting) do
43
- include MatcherHelperModule
44
- match { |actual| actual == greeting }
45
- end.for_expected
46
- end
47
-
48
- it "has access to the module's methods" do
49
- matcher.matches?("Hello, World")
50
- end
51
-
52
- it "runs the module's included hook" do
53
- expect(matcher).to respond_to(:included_method)
54
- end
55
-
56
- it "does not run the module's extended hook" do
57
- expect(matcher).not_to respond_to(:extended_method)
58
- end
59
-
60
- it 'allows multiple modules to be included at once' do
61
- m = RSpec::Matchers::DSL::Matcher.new(:multiple_modules) do
62
- include Enumerable, Comparable
63
- end.for_expected
64
- expect(m).to be_a(Enumerable)
65
- expect(m).to be_a(Comparable)
66
- end
67
- end
68
-
69
- context "without overrides" do
70
- before(:each) do
71
- @matcher = RSpec::Matchers::DSL::Matcher.new(:be_a_multiple_of) do |multiple|
72
- match do |actual|
73
- actual % multiple == 0
74
- end
75
- end.for_expected(3)
76
- end
77
-
78
- it "provides a default description" do
79
- expect(@matcher.description).to eq "be a multiple of 3"
80
- end
81
-
82
- it "provides a default failure message for #should" do
83
- @matcher.matches?(8)
84
- expect(@matcher.failure_message_for_should).to eq "expected 8 to be a multiple of 3"
85
- end
86
-
87
- it "provides a default failure message for #should_not" do
88
- @matcher.matches?(9)
89
- expect(@matcher.failure_message_for_should_not).to eq "expected 9 not to be a multiple of 3"
90
- end
91
- end
92
-
93
- context "with separate match logic for should and should not" do
94
- let(:matcher) do
95
- RSpec::Matchers::DSL::Matcher.new(:to_be_composed_of) do |a, b|
96
- match_for_should do |actual|
97
- actual == a * b
98
- end
99
-
100
- match_for_should_not do |actual|
101
- actual == a + b
102
- end
103
- end.for_expected(7, 11)
104
- end
105
-
106
- it "invokes the match_for_should block for #matches?" do
107
- expect(matcher.matches?(77)).to be_true
108
- expect(matcher.matches?(18)).to be_false
109
- end
110
-
111
- it "invokes the match_for_should_not block for #does_not_match?" do
112
- expect(matcher.does_not_match?(77)).to be_false
113
- expect(matcher.does_not_match?(18)).to be_true
114
- end
115
-
116
- it "provides a default failure message for #should_not" do
117
- matcher.does_not_match?(77)
118
- expect(matcher.failure_message_for_should_not).to eq "expected 77 not to to be composed of 7 and 11"
119
- end
120
- end
121
-
122
- it "allows helper methods to be defined with #define_method to have access to matcher parameters" do
123
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) do |a, b|
124
- define_method(:sum) { a + b }
125
- end.for_expected(3,4)
126
-
127
- expect(matcher.sum).to eq 7
128
- end
129
-
130
- it "is not diffable by default" do
131
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}
132
- expect(matcher).not_to be_diffable
133
- end
134
-
135
- it "is diffable when told to be" do
136
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) { diffable }.for_expected
137
- expect(matcher).to be_diffable
138
- end
139
-
140
- it "provides expected" do
141
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}.for_expected('expected string')
142
- expect(matcher.expected).to eq ['expected string']
143
- end
144
-
145
- it "provides actual" do
146
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) do
147
- match {|actual|}
148
- end.for_expected('expected string')
149
-
150
- matcher.matches?('actual string')
151
-
152
- expect(matcher.actual).to eq 'actual string'
153
- end
154
-
155
- context "wrapping another expectation (should == ...)" do
156
- it "returns true if the wrapped expectation passes" do
157
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) do |expected|
158
- match do |actual|
159
- expect(actual).to eq expected
160
- end
161
- end.for_expected('value')
162
- expect(matcher.matches?('value')).to be_true
163
- end
164
-
165
- it "returns false if the wrapped expectation fails" do
166
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) do |expected|
167
- match do |actual|
168
- expect(actual).to eq expected
169
- end
170
- end.for_expected('value')
171
- expect(matcher.matches?('other value')).to be_false
172
- end
173
- end
174
-
175
- context "with overrides" do
176
- before(:each) do
177
- @matcher = RSpec::Matchers::DSL::Matcher.new(:be_boolean) do |boolean|
178
- match do |actual|
179
- actual
180
- end
181
- description do
182
- "be the boolean #{boolean}"
183
- end
184
- failure_message_for_should do |actual|
185
- "expected #{actual} to be the boolean #{boolean}"
186
- end
187
- failure_message_for_should_not do |actual|
188
- "expected #{actual} not to be the boolean #{boolean}"
189
- end
190
- end.for_expected(true)
191
- end
192
-
193
- it "does not hide result of match block when true" do
194
- expect(@matcher.matches?(true)).to be_true
195
- end
196
-
197
- it "does not hide result of match block when false" do
198
- expect(@matcher.matches?(false)).to be_false
199
- end
200
-
201
- it "overrides the description" do
202
- expect(@matcher.description).to eq "be the boolean true"
203
- end
204
-
205
- it "overrides the failure message for #should" do
206
- @matcher.matches?(false)
207
- expect(@matcher.failure_message_for_should).to eq "expected false to be the boolean true"
208
- end
209
-
210
- it "overrides the failure message for #should_not" do
211
- @matcher.matches?(true)
212
- expect(@matcher.failure_message_for_should_not).to eq "expected true not to be the boolean true"
213
- end
214
- end
215
-
216
- context "#new" do
217
- it "passes matches? arg to match block" do
218
- matcher = RSpec::Matchers::DSL::Matcher.new(:ignore) do
219
- match do |actual|
220
- actual == 5
221
- end
222
- end.for_expected
223
- expect(matcher.matches?(5)).to be_true
224
- end
225
-
226
- it "exposes arg submitted through #new to matcher block" do
227
- matcher = RSpec::Matchers::DSL::Matcher.new(:ignore) do |expected|
228
- match do |actual|
229
- actual > expected
230
- end
231
- end.for_expected(4)
232
- expect(matcher.matches?(5)).to be_true
233
- end
234
- end
235
-
236
- context "with no args" do
237
- before(:each) do
238
- @matcher = RSpec::Matchers::DSL::Matcher.new(:matcher_name) do
239
- match do |actual|
240
- actual == 5
241
- end
242
- end.for_expected
243
- end
244
-
245
- it "matches" do
246
- expect(@matcher.matches?(5)).to be_true
247
- end
248
-
249
- it "describes" do
250
- expect(@matcher.description).to eq "matcher name"
251
- end
252
- end
253
-
254
- context "with 1 arg" do
255
- before(:each) do
256
- @matcher = RSpec::Matchers::DSL::Matcher.new(:matcher_name) do |expected|
257
- match do |actual|
258
- actual == 5 && expected == 1
259
- end
260
- end.for_expected(1)
261
- end
262
-
263
- it "matches" do
264
- expect(@matcher.matches?(5)).to be_true
265
- end
266
-
267
- it "describes" do
268
- expect(@matcher.description).to eq "matcher name 1"
269
- end
270
- end
271
-
272
- context "with multiple args" do
273
- before(:each) do
274
- @matcher = RSpec::Matchers::DSL::Matcher.new(:matcher_name) do |a,b,c,d|
275
- match do |sum|
276
- a + b + c + d == sum
277
- end
278
- end.for_expected(1,2,3,4)
279
- end
280
-
281
- it "matches" do
282
- expect(@matcher.matches?(10)).to be_true
283
- end
284
-
285
- it "describes" do
286
- expect(@matcher.description).to eq "matcher name 1, 2, 3, and 4"
287
- end
288
- end
289
-
290
- it "supports helper methods" do
291
- matcher = RSpec::Matchers::DSL::Matcher.new(:be_similar_to) do |sample|
292
- match do |actual|
293
- similar?(sample, actual)
294
- end
295
-
296
- def similar?(a, b)
297
- a.sort == b.sort
298
- end
299
- end.for_expected([1,2,3])
300
-
301
- expect(matcher.matches?([2,3,1])).to be_true
302
- end
303
-
304
- it "supports fluent interface" do
305
- matcher = RSpec::Matchers::DSL::Matcher.new(:first_word) do
306
- def second_word
307
- self
308
- end
309
- end.for_expected
310
-
311
- expect(matcher.second_word).to eq matcher
312
- end
313
-
314
- it "treats method missing normally for undeclared methods" do
315
- matcher = RSpec::Matchers::DSL::Matcher.new(:ignore) { }.for_expected
316
- expect { matcher.non_existent_method }.to raise_error(NoMethodError)
317
- end
318
-
319
- it "has access to other matchers" do
320
- matcher = RSpec::Matchers::DSL::Matcher.new(:ignore) do |expected|
321
- match do |actual|
322
- extend RSpec::Matchers
323
- expect(actual).to eql(5 + expected)
324
- end
325
- end.for_expected(3)
326
-
327
- expect(matcher.matches?(8)).to be_true
328
- end
329
-
330
- context 'when multiple instances of the same matcher are used in the same example' do
331
- RSpec::Matchers.define(:be_like_a) do |expected|
332
- match { |actual| actual == expected }
333
- description { "be like a #{expected}" }
334
- failure_message_for_should { "expected to be like a #{expected}" }
335
- failure_message_for_should_not { "expected not to be like a #{expected}" }
336
- end
337
-
338
- # Note: these bugs were only exposed when creating both instances
339
- # first, then checking their descriptions/failure messages.
340
- #
341
- # That's why we eager-instantiate them here.
342
- let!(:moose) { be_like_a("moose") }
343
- let!(:horse) { be_like_a("horse") }
344
-
345
- it 'allows them to use the expected value in the description' do
346
- expect(horse.description).to eq("be like a horse")
347
- expect(moose.description).to eq("be like a moose")
348
- end
349
-
350
- it 'allows them to use the expected value in the positive failure message' do
351
- expect(moose.failure_message_for_should).to eq("expected to be like a moose")
352
- expect(horse.failure_message_for_should).to eq("expected to be like a horse")
353
- end
354
-
355
- it 'allows them to use the expected value in the negative failure message' do
356
- expect(moose.failure_message_for_should_not).to eq("expected not to be like a moose")
357
- expect(horse.failure_message_for_should_not).to eq("expected not to be like a horse")
358
- end
359
-
360
- it 'allows them to match separately' do
361
- expect("moose").to moose
362
- expect("horse").to horse
363
- expect("horse").not_to moose
364
- expect("moose").not_to horse
365
- end
366
- end
367
-
368
- describe "#match_unless_raises" do
369
- context "with an assertion" do
370
- let(:mod) do
371
- Module.new do
372
- def assert_equal(a,b)
373
- a == b ? nil : (raise UnexpectedError.new("#{b} does not equal #{a}"))
374
- end
375
- end
376
- end
377
- let(:matcher) do
378
- m = mod
379
- RSpec::Matchers::DSL::Matcher.new :equal do |expected|
380
- extend m
381
- match_unless_raises UnexpectedError do
382
- assert_equal expected, actual
383
- end
384
- end.for_expected(4)
385
- end
386
-
387
- context "with passing assertion" do
388
- it "passes" do
389
- expect(matcher.matches?(4)).to be_true
390
- end
391
- end
392
-
393
- context "with failing assertion" do
394
- it "fails" do
395
- expect(matcher.matches?(5)).to be_false
396
- end
397
-
398
- it "provides the raised exception" do
399
- matcher.matches?(5)
400
- expect(matcher.rescued_exception.message).to eq("5 does not equal 4")
401
- end
402
- end
403
- end
404
-
405
- context "with an unexpected error" do
406
- let(:matcher) do
407
- RSpec::Matchers::DSL::Matcher.new :foo do |expected|
408
- match_unless_raises SyntaxError do |actual|
409
- raise "unexpected exception"
410
- end
411
- end.for_expected(:bar)
412
- end
413
-
414
- it "raises the error" do
415
- expect do
416
- matcher.matches?(:bar)
417
- end.to raise_error("unexpected exception")
418
- end
419
- end
420
-
421
- end
422
-
423
- it "can define chainable methods" do
424
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) do
425
- chain(:expecting) do |expected_value|
426
- @expected_value = expected_value
427
- end
428
- match { |actual| actual == @expected_value }
429
- end.for_expected
430
-
431
- expect(matcher.expecting('value').matches?('value')).to be_true
432
- expect(matcher.expecting('value').matches?('other value')).to be_false
433
- end
434
-
435
- it "prevents name collisions on chainable methods from different matchers" do
436
- m1 = RSpec::Matchers::DSL::Matcher.new(:m1) { chain(:foo) { raise "foo in m1" } }.for_expected
437
- m2 = RSpec::Matchers::DSL::Matcher.new(:m2) { chain(:foo) { raise "foo in m2" } }.for_expected
438
-
439
- expect { m1.foo }.to raise_error("foo in m1")
440
- expect { m2.foo }.to raise_error("foo in m2")
441
- end
442
-
443
- context "defined using the dsl" do
444
- def a_method_in_the_example
445
- "method defined in the example"
446
- end
447
-
448
- it "can access methods in the running example" do
449
- RSpec::Matchers.define(:__access_running_example) do
450
- match do |actual|
451
- a_method_in_the_example == "method defined in the example"
452
- end
453
- end
454
- expect(example).to __access_running_example
455
- end
456
-
457
- it "raises NoMethodError for methods not in the running_example" do
458
- RSpec::Matchers.define(:__raise_no_method_error) do
459
- match do |actual|
460
- a_method_not_in_the_example == "method defined in the example"
461
- end
462
- end
463
-
464
- expect do
465
- expect(example).to __raise_no_method_error
466
- end.to raise_error(/RSpec::Matchers::DSL::Matcher/)
467
- end
468
- end
469
-
470
- end
471
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- describe Matchers do
5
-
6
- let(:sample_matchers) do
7
- [:be,
8
- :be_close,
9
- :be_instance_of,
10
- :be_kind_of]
11
- end
12
-
13
- context "once required" do
14
- include TestUnitIntegrationSupport
15
-
16
- it "includes itself in Test::Unit::TestCase" do
17
- with_test_unit_loaded do
18
- test_unit_case = Test::Unit::TestCase.allocate
19
- sample_matchers.each do |sample_matcher|
20
- expect(test_unit_case).to respond_to(sample_matcher)
21
- end
22
- end
23
- end
24
-
25
- it "includes itself in MiniTest::Unit::TestCase", :if => defined?(MiniTest) do
26
- with_test_unit_loaded do
27
- minitest_case = MiniTest::Unit::TestCase.allocate
28
- sample_matchers.each do |sample_matcher|
29
- expect(minitest_case).to respond_to(sample_matcher)
30
- end
31
- end
32
- end
33
-
34
- end
35
-
36
- end
37
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples_for "a well-behaved method_missing hook" do
4
- include TestUnitIntegrationSupport
5
-
6
- it "raises a NoMethodError (and not SystemStackError) for an undefined method" do
7
- with_test_unit_loaded do
8
- expect { subject.some_undefined_method }.to raise_error(NoMethodError)
9
- end
10
- end
11
- end
12
-
13
- describe "RSpec::Matchers method_missing hook" do
14
- subject { self }
15
-
16
- it_behaves_like "a well-behaved method_missing hook"
17
-
18
- context 'when invoked in a Test::Unit::TestCase' do
19
- subject { Test::Unit::TestCase.allocate }
20
- it_behaves_like "a well-behaved method_missing hook"
21
- end
22
-
23
- context 'when invoked in a MiniTest::Unit::TestCase', :if => defined?(MiniTest) do
24
- subject { MiniTest::Unit::TestCase.allocate }
25
- it_behaves_like "a well-behaved method_missing hook"
26
- end
27
- end
28
-