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,434 +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
- m1.matches?(1).should be_true
37
- m2.matches?(2).should 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
- matcher.should respond_to(:included_method)
54
- end
55
-
56
- it "does not run the module's extended hook" do
57
- matcher.should_not 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
- m.should be_a(Enumerable)
65
- m.should 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
- @matcher.description.should == "be a multiple of 3"
80
- end
81
-
82
- it "provides a default failure message for #should" do
83
- @matcher.matches?(8)
84
- @matcher.failure_message_for_should.should == "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
- @matcher.failure_message_for_should_not.should == "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
- matcher.matches?(77).should be_true
108
- matcher.matches?(18).should be_false
109
- end
110
-
111
- it "invokes the match_for_should_not block for #does_not_match?" do
112
- matcher.does_not_match?(77).should be_false
113
- matcher.does_not_match?(18).should be_true
114
- end
115
-
116
- it "provides a default failure message for #should_not" do
117
- matcher.does_not_match?(77)
118
- matcher.failure_message_for_should_not.should == "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
- matcher.sum.should == 7
128
- end
129
-
130
- it "is not diffable by default" do
131
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}
132
- matcher.should_not 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
- matcher.should be_diffable
138
- end
139
-
140
- it "provides expected" do
141
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}.for_expected('expected string')
142
- matcher.expected.should == ['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
- matcher.actual.should == '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
- actual.should == expected
160
- end
161
- end.for_expected('value')
162
- matcher.matches?('value').should 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
- actual.should == expected
169
- end
170
- end.for_expected('value')
171
- matcher.matches?('other value').should 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
- @matcher.matches?(true).should be_true
195
- end
196
-
197
- it "does not hide result of match block when false" do
198
- @matcher.matches?(false).should be_false
199
- end
200
-
201
- it "overrides the description" do
202
- @matcher.description.should == "be the boolean true"
203
- end
204
-
205
- it "overrides the failure message for #should" do
206
- @matcher.matches?(false)
207
- @matcher.failure_message_for_should.should == "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
- @matcher.failure_message_for_should_not.should == "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
- matcher.matches?(5).should 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
- matcher.matches?(5).should 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
- @matcher.matches?(5).should be_true
247
- end
248
-
249
- it "describes" do
250
- @matcher.description.should == "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
- @matcher.matches?(5).should be_true
265
- end
266
-
267
- it "describes" do
268
- @matcher.description.should == "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
- @matcher.matches?(10).should be_true
283
- end
284
-
285
- it "describes" do
286
- @matcher.description.should == "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
- matcher.matches?([2,3,1]).should 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
- matcher.second_word.should == 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
- actual.should eql(5 + expected)
324
- end
325
- end.for_expected(3)
326
-
327
- matcher.matches?(8).should be_true
328
- end
329
-
330
- describe "#match_unless_raises" do
331
- context "with an assertion" do
332
- let(:mod) do
333
- Module.new do
334
- def assert_equal(a,b)
335
- a == b ? nil : (raise UnexpectedError.new("#{b} does not equal #{a}"))
336
- end
337
- end
338
- end
339
- let(:matcher) do
340
- m = mod
341
- RSpec::Matchers::DSL::Matcher.new :equal do |expected|
342
- extend m
343
- match_unless_raises UnexpectedError do
344
- assert_equal expected, actual
345
- end
346
- end.for_expected(4)
347
- end
348
-
349
- context "with passing assertion" do
350
- it "passes" do
351
- matcher.matches?(4).should be_true
352
- end
353
- end
354
-
355
- context "with failing assertion" do
356
- it "fails" do
357
- matcher.matches?(5).should be_false
358
- end
359
-
360
- it "provides the raised exception" do
361
- matcher.matches?(5)
362
- matcher.rescued_exception.message.
363
- should eq("5 does not equal 4")
364
- end
365
- end
366
- end
367
-
368
- context "with an unexpected error" do
369
- let(:matcher) do
370
- RSpec::Matchers::DSL::Matcher.new :foo do |expected|
371
- match_unless_raises SyntaxError do |actual|
372
- raise "unexpected exception"
373
- end
374
- end.for_expected(:bar)
375
- end
376
-
377
- it "raises the error" do
378
- expect do
379
- matcher.matches?(:bar)
380
- end.to raise_error("unexpected exception")
381
- end
382
- end
383
-
384
- end
385
-
386
- it "can define chainable methods" do
387
- matcher = RSpec::Matchers::DSL::Matcher.new(:name) do
388
- chain(:expecting) do |expected_value|
389
- @expected_value = expected_value
390
- end
391
- match { |actual| actual == @expected_value }
392
- end.for_expected
393
-
394
- matcher.expecting('value').matches?('value').should be_true
395
- matcher.expecting('value').matches?('other value').should be_false
396
- end
397
-
398
- it "prevents name collisions on chainable methods from different matchers" do
399
- m1 = RSpec::Matchers::DSL::Matcher.new(:m1) { chain(:foo) { raise "foo in m1" } }.for_expected
400
- m2 = RSpec::Matchers::DSL::Matcher.new(:m2) { chain(:foo) { raise "foo in m2" } }.for_expected
401
-
402
- expect { m1.foo }.to raise_error("foo in m1")
403
- expect { m2.foo }.to raise_error("foo in m2")
404
- end
405
-
406
- context "defined using the dsl" do
407
- def a_method_in_the_example
408
- "method defined in the example"
409
- end
410
-
411
- it "can access methods in the running example" do
412
- RSpec::Matchers.define(:__access_running_example) do
413
- match do |actual|
414
- a_method_in_the_example == "method defined in the example"
415
- end
416
- end
417
- example.should __access_running_example
418
- end
419
-
420
- it "raises NoMethodError for methods not in the running_example" do
421
- RSpec::Matchers.define(:__raise_no_method_error) do
422
- match do |actual|
423
- a_method_not_in_the_example == "method defined in the example"
424
- end
425
- end
426
-
427
- expect do
428
- example.should __raise_no_method_error
429
- end.to raise_error(/RSpec::Matchers::DSL::Matcher/)
430
- end
431
- end
432
-
433
- end
434
- end
@@ -1,31 +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
- it "includes itself in Test::Unit::TestCase" do
15
- test_unit_case = Test::Unit::TestCase.allocate
16
- sample_matchers.each do |sample_matcher|
17
- test_unit_case.should respond_to(sample_matcher)
18
- end
19
- end
20
-
21
- it "includes itself in MiniTest::Unit::TestCase", :if => defined?(MiniTest) do
22
- minitest_case = MiniTest::Unit::TestCase.allocate
23
- sample_matchers.each do |sample_matcher|
24
- minitest_case.should respond_to(sample_matcher)
25
- end
26
- end
27
-
28
- end
29
-
30
- end
31
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples_for "a well-behaved method_missing hook" do
4
- it "raises a NoMethodError (and not SystemStackError) for an undefined method" do
5
- expect { subject.some_undefined_method }.to raise_error(NoMethodError)
6
- end
7
- end
8
-
9
- describe "RSpec::Matchers method_missing hook" do
10
- subject { self }
11
-
12
- it_behaves_like "a well-behaved method_missing hook"
13
-
14
- context 'when invoked in a Test::Unit::TestCase' do
15
- subject { Test::Unit::TestCase.allocate }
16
- it_behaves_like "a well-behaved method_missing hook"
17
- end
18
-
19
- context 'when invoked in a MiniTest::Unit::TestCase', :if => defined?(MiniTest) do
20
- subject { MiniTest::Unit::TestCase.allocate }
21
- it_behaves_like "a well-behaved method_missing hook"
22
- end
23
- end
24
-
@@ -1,221 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "should ==" do
4
-
5
- it "delegates message to target" do
6
- subject = "apple"
7
- subject.should_receive(:==).with("apple").and_return(true)
8
- subject.should == "apple"
9
- end
10
-
11
- it "returns true on success" do
12
- subject = "apple"
13
- (subject.should == "apple").should be_true
14
- end
15
-
16
- it "fails when target.==(actual) returns false" do
17
- subject = "apple"
18
- RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ==)], "orange", "apple")
19
- subject.should == "orange"
20
- end
21
-
22
- end
23
-
24
- describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do
25
- it "raises an appropriate error for should != expected" do
26
- expect {
27
- "apple".should != "pear"
28
- }.to raise_error(/does not support `should != expected`. Use `should_not == expected`/)
29
- end
30
-
31
- it "raises an appropriate error for should_not != expected" do
32
- expect {
33
- "apple".should_not != "pear"
34
- }.to raise_error(/does not support `should_not != expected`. Use `should == expected`/)
35
- end
36
-
37
- it "raises an appropriate error for should !~ expected" do
38
- expect {
39
- "apple".should !~ /regex/
40
- }.to raise_error(/does not support `should !~ expected`. Use `should_not =~ expected`/)
41
- end
42
-
43
- it "raises an appropriate error for should_not !~ expected" do
44
- expect {
45
- "apple".should_not !~ /regex/
46
- }.to raise_error(/does not support `should_not !~ expected`. Use `should =~ expected`/)
47
- end
48
- end
49
-
50
- describe "should_not ==" do
51
-
52
- it "delegates message to target" do
53
- subject = "orange"
54
- subject.should_receive(:==).with("apple").and_return(false)
55
- subject.should_not == "apple"
56
- end
57
-
58
- it "returns true on success" do
59
- subject = "apple"
60
- (subject.should_not == "orange").should be_false
61
- end
62
-
63
- it "fails when target.==(actual) returns false" do
64
- subject = "apple"
65
- RSpec::Expectations.should_receive(:fail_with).with(%[expected not: == "apple"\n got: "apple"], "apple", "apple")
66
- subject.should_not == "apple"
67
- end
68
-
69
- end
70
-
71
- describe "should ===" do
72
-
73
- it "delegates message to target" do
74
- subject = "apple"
75
- subject.should_receive(:===).with("apple").and_return(true)
76
- subject.should === "apple"
77
- end
78
-
79
- it "fails when target.===(actual) returns false" do
80
- subject = "apple"
81
- subject.should_receive(:===).with("orange").and_return(false)
82
- RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ===)], "orange", "apple")
83
- subject.should === "orange"
84
- end
85
-
86
- end
87
-
88
- describe "should_not ===" do
89
-
90
- it "delegates message to target" do
91
- subject = "orange"
92
- subject.should_receive(:===).with("apple").and_return(false)
93
- subject.should_not === "apple"
94
- end
95
-
96
- it "fails when target.===(actual) returns false" do
97
- subject = "apple"
98
- subject.should_receive(:===).with("apple").and_return(true)
99
- RSpec::Expectations.should_receive(:fail_with).with(%[expected not: === "apple"\n got: "apple"], "apple", "apple")
100
- subject.should_not === "apple"
101
- end
102
-
103
- end
104
-
105
- describe "should =~" do
106
-
107
- it "delegates message to target" do
108
- subject = "foo"
109
- subject.should_receive(:=~).with(/oo/).and_return(true)
110
- subject.should =~ /oo/
111
- end
112
-
113
- it "fails when target.=~(actual) returns false" do
114
- subject = "fu"
115
- subject.should_receive(:=~).with(/oo/).and_return(false)
116
- RSpec::Expectations.should_receive(:fail_with).with(%[expected: /oo/\n got: "fu" (using =~)], /oo/, "fu")
117
- subject.should =~ /oo/
118
- end
119
-
120
- end
121
-
122
- describe "should_not =~" do
123
-
124
- it "delegates message to target" do
125
- subject = "fu"
126
- subject.should_receive(:=~).with(/oo/).and_return(false)
127
- subject.should_not =~ /oo/
128
- end
129
-
130
- it "fails when target.=~(actual) returns false" do
131
- subject = "foo"
132
- subject.should_receive(:=~).with(/oo/).and_return(true)
133
- RSpec::Expectations.should_receive(:fail_with).with(%[expected not: =~ /oo/\n got: "foo"], /oo/, "foo")
134
- subject.should_not =~ /oo/
135
- end
136
-
137
- end
138
-
139
- describe "should >" do
140
-
141
- it "passes if > passes" do
142
- 4.should > 3
143
- end
144
-
145
- it "fails if > fails" do
146
- RSpec::Expectations.should_receive(:fail_with).with(%[expected: > 5\n got: 4], 5, 4)
147
- 4.should > 5
148
- end
149
-
150
- end
151
-
152
- describe "should >=" do
153
-
154
- it "passes if actual == expected" do
155
- 4.should >= 4
156
- end
157
-
158
- it "passes if actual > expected" do
159
- 4.should >= 3
160
- end
161
-
162
- it "fails if > fails" do
163
- RSpec::Expectations.should_receive(:fail_with).with(%[expected: >= 5\n got: 4], 5, 4)
164
- 4.should >= 5
165
- end
166
-
167
- end
168
-
169
- describe "should <" do
170
-
171
- it "passes if < passes" do
172
- 4.should < 5
173
- end
174
-
175
- it "fails if > fails" do
176
- RSpec::Expectations.should_receive(:fail_with).with(%[expected: < 3\n got: 4], 3, 4)
177
- 4.should < 3
178
- end
179
-
180
- end
181
-
182
- describe "should <=" do
183
-
184
- it "passes if actual == expected" do
185
- 4.should <= 4
186
- end
187
-
188
- it "passes if actual < expected" do
189
- 4.should <= 5
190
- end
191
-
192
- it "fails if > fails" do
193
- RSpec::Expectations.should_receive(:fail_with).with(%[expected: <= 3\n got: 4], 3, 4)
194
- 4.should <= 3
195
- end
196
-
197
- end
198
-
199
- describe RSpec::Matchers::BuiltIn::PositiveOperatorMatcher do
200
-
201
- it "works when the target has implemented #send" do
202
- o = Object.new
203
- def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
204
- lambda {
205
- o.should == o
206
- }.should_not raise_error
207
- end
208
-
209
- end
210
-
211
- describe RSpec::Matchers::BuiltIn::NegativeOperatorMatcher do
212
-
213
- it "works when the target has implemented #send" do
214
- o = Object.new
215
- def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
216
- lambda {
217
- o.should_not == :foo
218
- }.should_not raise_error
219
- end
220
-
221
- end