rspec-expectations 2.13.0 → 2.99.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 (96) hide show
  1. checksums.yaml +15 -0
  2. data/Changelog.md +204 -23
  3. data/README.md +43 -87
  4. data/features/README.md +10 -10
  5. data/features/built_in_matchers/README.md +41 -41
  6. data/features/built_in_matchers/be.feature +40 -40
  7. data/features/built_in_matchers/be_within.feature +3 -3
  8. data/features/built_in_matchers/expect_change.feature +6 -6
  9. data/features/built_in_matchers/expect_error.feature +2 -2
  10. data/features/built_in_matchers/start_with.feature +1 -1
  11. data/features/built_in_matchers/throw_symbol.feature +11 -11
  12. data/features/built_in_matchers/yield.feature +18 -3
  13. data/features/custom_matchers/define_diffable_matcher.feature +1 -1
  14. data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
  15. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
  16. data/features/customized_message.feature +1 -1
  17. data/features/diffing.feature +1 -1
  18. data/features/step_definitions/additional_cli_steps.rb +10 -0
  19. data/features/support/env.rb +10 -1
  20. data/features/support/rubinius.rb +6 -0
  21. data/features/syntax_configuration.feature +3 -0
  22. data/features/test_frameworks/test_unit.feature +55 -17
  23. data/lib/rspec/expectations/caller_filter.rb +60 -0
  24. data/lib/rspec/{matchers → expectations}/configuration.rb +5 -3
  25. data/lib/rspec/expectations/deprecation.rb +20 -31
  26. data/lib/rspec/expectations/differ.rb +48 -9
  27. data/lib/rspec/expectations/expectation_target.rb +81 -15
  28. data/lib/rspec/expectations/extensions/object.rb +2 -12
  29. data/lib/rspec/expectations/fail_with.rb +11 -1
  30. data/lib/rspec/expectations/handler.rb +16 -7
  31. data/lib/rspec/expectations/syntax.rb +5 -7
  32. data/lib/rspec/expectations/version.rb +1 -1
  33. data/lib/rspec/expectations.rb +28 -2
  34. data/lib/rspec/matchers/be_close.rb +4 -1
  35. data/lib/rspec/matchers/built_in/base_matcher.rb +17 -10
  36. data/lib/rspec/matchers/built_in/be.rb +69 -32
  37. data/lib/rspec/matchers/built_in/be_within.rb +9 -3
  38. data/lib/rspec/matchers/built_in/change.rb +49 -3
  39. data/lib/rspec/matchers/built_in/has.rb +40 -7
  40. data/lib/rspec/matchers/built_in/have.rb +170 -5
  41. data/lib/rspec/matchers/built_in/include.rb +3 -11
  42. data/lib/rspec/matchers/built_in/match.rb +5 -0
  43. data/lib/rspec/matchers/built_in/match_array.rb +1 -1
  44. data/lib/rspec/matchers/built_in/raise_error.rb +34 -8
  45. data/lib/rspec/matchers/built_in/respond_to.rb +7 -1
  46. data/lib/rspec/matchers/built_in/satisfy.rb +7 -1
  47. data/lib/rspec/matchers/built_in/throw_symbol.rb +10 -2
  48. data/lib/rspec/matchers/built_in/yield.rb +102 -5
  49. data/lib/rspec/matchers/built_in.rb +2 -2
  50. data/lib/rspec/matchers/differentiate_block_method_types.rb +55 -0
  51. data/lib/rspec/matchers/dsl.rb +2 -1
  52. data/lib/rspec/matchers/match_aliases.rb +22 -0
  53. data/lib/rspec/matchers/matcher.rb +131 -10
  54. data/lib/rspec/matchers/operator_matcher.rb +70 -66
  55. data/lib/rspec/matchers/pretty.rb +11 -1
  56. data/lib/rspec/matchers/test_unit_integration.rb +28 -0
  57. data/lib/rspec/matchers.rb +175 -146
  58. data/lib/rspec-expectations.rb +5 -0
  59. data/spec/rspec/{matchers → expectations}/configuration_spec.rb +78 -91
  60. data/spec/rspec/expectations/differ_spec.rb +65 -6
  61. data/spec/rspec/expectations/expectation_target_spec.rb +72 -3
  62. data/spec/rspec/expectations/extensions/kernel_spec.rb +9 -5
  63. data/spec/rspec/expectations/fail_with_spec.rb +19 -0
  64. data/spec/rspec/expectations/handler_spec.rb +43 -22
  65. data/spec/rspec/expectations/syntax_spec.rb +51 -9
  66. data/spec/rspec/expectations_spec.rb +71 -0
  67. data/spec/rspec/matchers/base_matcher_spec.rb +33 -18
  68. data/spec/rspec/matchers/be_close_spec.rb +9 -6
  69. data/spec/rspec/matchers/be_spec.rb +146 -45
  70. data/spec/rspec/matchers/be_within_spec.rb +8 -0
  71. data/spec/rspec/matchers/change_spec.rb +107 -7
  72. data/spec/rspec/matchers/description_generation_spec.rb +38 -20
  73. data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +39 -0
  74. data/spec/rspec/matchers/eq_spec.rb +1 -1
  75. data/spec/rspec/matchers/equal_spec.rb +26 -0
  76. data/spec/rspec/matchers/exist_spec.rb +9 -9
  77. data/spec/rspec/matchers/has_spec.rb +25 -1
  78. data/spec/rspec/matchers/have_spec.rb +411 -3
  79. data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
  80. data/spec/rspec/matchers/include_spec.rb +4 -4
  81. data/spec/rspec/matchers/match_array_spec.rb +1 -1
  82. data/spec/rspec/matchers/match_spec.rb +14 -1
  83. data/spec/rspec/matchers/matcher_spec.rb +213 -24
  84. data/spec/rspec/matchers/operator_matcher_spec.rb +56 -8
  85. data/spec/rspec/matchers/pretty_spec.rb +23 -0
  86. data/spec/rspec/matchers/raise_error_spec.rb +242 -102
  87. data/spec/rspec/matchers/respond_to_spec.rb +4 -4
  88. data/spec/rspec/matchers/satisfy_spec.rb +1 -1
  89. data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
  90. data/spec/rspec/matchers/throw_symbol_spec.rb +14 -14
  91. data/spec/rspec/matchers/yield_spec.rb +81 -4
  92. data/spec/spec_helper.rb +5 -3
  93. data/spec/support/helper_methods.rb +42 -0
  94. data/spec/support/shared_examples.rb +42 -0
  95. metadata +40 -44
  96. data/spec/rspec/matchers/matchers_spec.rb +0 -37
@@ -1,5 +1,20 @@
1
+ require 'rspec/matchers/extensions/instance_eval_with_args'
2
+ require 'rspec/matchers/pretty'
3
+
4
+ require 'rspec/matchers/match_aliases'
5
+ require 'rspec/matchers/built_in'
6
+ require 'rspec/matchers/matcher'
7
+ require 'rspec/matchers/operator_matcher'
8
+ require 'rspec/matchers/be_close'
9
+
10
+ require 'rspec/matchers/generated_descriptions'
11
+ require 'rspec/matchers/method_missing'
12
+ require 'rspec/matchers/compatibility'
13
+ require 'rspec/matchers/dsl'
14
+ require 'rspec/matchers/test_unit_integration'
15
+
1
16
  module RSpec
2
- # RSpec::Matchers provides a number of useful matchers we use to compose
17
+ # RSpec::Matchers provides a number of useful matchers we use to define
3
18
  # expectations. A matcher is any object that responds to the following:
4
19
  #
5
20
  # matches?(actual)
@@ -10,6 +25,7 @@ module RSpec
10
25
  # does_not_match?(actual)
11
26
  # failure_message_for_should_not
12
27
  # description
28
+ # supports_block_expectations?
13
29
  #
14
30
  # ## Predicates
15
31
  #
@@ -20,28 +36,29 @@ module RSpec
20
36
  # A Ruby predicate is a method that ends with a "?" and returns true or false.
21
37
  # Common examples are `empty?`, `nil?`, and `instance_of?`.
22
38
  #
23
- # All you need to do is write `should be_` followed by the predicate without
24
- # the question mark, and RSpec will figure it out from there. For example:
39
+ # All you need to do is write `expect(..).to be_` followed by the predicate
40
+ # without the question mark, and RSpec will figure it out from there.
41
+ # For example:
25
42
  #
26
- # [].should be_empty # => [].empty?() | passes
27
- # [].should_not be_empty # => [].empty?() | fails
43
+ # expect([]).to be_empty # => [].empty?() | passes
44
+ # expect([]).not_to be_empty # => [].empty?() | fails
28
45
  #
29
46
  # In addtion to prefixing the predicate matchers with "be_", you can also use "be_a_"
30
47
  # and "be_an_", making your specs read much more naturally:
31
48
  #
32
- # "a string".should be_an_instance_of(String) =>"a string".instance_of?(String) #passes
49
+ # expect("a string").to be_an_instance_of(String) # =>"a string".instance_of?(String) # passes
33
50
  #
34
- # 3.should be_a_kind_of(Fixnum) # => 3.kind_of?(Numeric) | passes
35
- # 3.should be_a_kind_of(Numeric) # => 3.kind_of?(Numeric) | passes
36
- # 3.should be_an_instance_of(Fixnum) # => 3.instance_of?(Fixnum) | passes
37
- # 3.should_not be_instance_of(Numeric) # => 3.instance_of?(Numeric) | fails
51
+ # expect(3).to be_a_kind_of(Fixnum) # => 3.kind_of?(Numeric) | passes
52
+ # expect(3).to be_a_kind_of(Numeric) # => 3.kind_of?(Numeric) | passes
53
+ # expect(3).to be_an_instance_of(Fixnum) # => 3.instance_of?(Fixnum) | passes
54
+ # expect(3).not_to be_an_instance_of(Numeric) # => 3.instance_of?(Numeric) | fails
38
55
  #
39
56
  # RSpec will also create custom matchers for predicates like `has_key?`. To
40
57
  # use this feature, just state that the object should have_key(:key) and RSpec will
41
58
  # call has_key?(:key) on the target. For example:
42
59
  #
43
- # {:a => "A"}.should have_key(:a) # => {:a => "A"}.has_key?(:a) | passes
44
- # {:a => "A"}.should have_key(:b) # => {:a => "A"}.has_key?(:b) | fails
60
+ # expect(:a => "A").to have_key(:a)
61
+ # expect(:a => "A").to have_key(:b) # fails
45
62
  #
46
63
  # You can use this feature to invoke any predicate that begins with "has_", whether it is
47
64
  # part of the Ruby libraries (like `Hash#has_key?`) or a method you wrote on your own class.
@@ -58,15 +75,15 @@ module RSpec
58
75
  # zones on a virtual board. To specify that bob should be in zone 4, you
59
76
  # could say:
60
77
  #
61
- # bob.current_zone.should eql(Zone.new("4"))
78
+ # expect(bob.current_zone).to eql(Zone.new("4"))
62
79
  #
63
80
  # But you might find it more expressive to say:
64
81
  #
65
- # bob.should be_in_zone("4")
82
+ # expect(bob).to be_in_zone("4")
66
83
  #
67
84
  # and/or
68
85
  #
69
- # bob.should_not be_in_zone("3")
86
+ # expect(bob).not_to be_in_zone("3")
70
87
  #
71
88
  # You can create such a matcher like so:
72
89
  #
@@ -102,7 +119,7 @@ module RSpec
102
119
  # passed to the <tt>create</tt> method (in this case, <tt>zone</tt>). The
103
120
  # failure message methods (<tt>failure_message_for_should</tt> and
104
121
  # <tt>failure_message_for_should_not</tt>) are passed the actual value (the
105
- # receiver of <tt>should</tt> or <tt>should_not</tt>).
122
+ # receiver of <tt>expect(..)</tt> or <tt>expect(..).not_to</tt>).
106
123
  #
107
124
  # ### Custom Matcher from scratch
108
125
  #
@@ -159,58 +176,55 @@ module RSpec
159
176
  # config.include(CustomGameMatchers)
160
177
  # end
161
178
  module Matchers
162
- # Include Matchers for other test frameworks. Note that MiniTest _must_
163
- # come before TU because on ruby 1.9, T::U::TC is a subclass of MT::U::TC
164
- # and a 1.9 bug can lead to infinite recursion from the `super` call in our
165
- # method_missing hook. See this gist for more info:
166
- # https://gist.github.com/845896
167
- if defined?(MiniTest::Unit::TestCase)
168
- MiniTest::Unit::TestCase.send(:include, self)
169
- end
170
- if defined?(Test::Unit::TestCase)
171
- Test::Unit::TestCase.send(:include, self)
172
- end
173
- end
174
- end
179
+ # @api private
180
+ def self.is_a_matcher?(obj)
181
+ return true if ::RSpec::Matchers::BuiltIn::BaseMatcher === obj
182
+ return false if obj.respond_to?(:i_respond_to_everything_so_im_not_really_a_matcher)
183
+ return false unless obj.respond_to?(:matches?)
175
184
 
176
- require 'rspec/matchers/extensions/instance_eval_with_args'
177
- require 'rspec/matchers/pretty'
178
-
179
- require 'rspec/matchers/built_in'
180
- require 'rspec/matchers/matcher'
181
- require 'rspec/matchers/operator_matcher'
182
- require 'rspec/matchers/be_close'
185
+ obj.respond_to?(:failure_message_for_should) || obj.respond_to?(:failure_message)
186
+ end
183
187
 
184
- require 'rspec/matchers/generated_descriptions'
185
- require 'rspec/matchers/method_missing'
186
- require 'rspec/matchers/compatibility'
187
- require 'rspec/matchers/dsl'
188
+ def be_true
189
+ RSpec.deprecate("`be_true`", :replacement =>
190
+ "`be_truthy` (for Ruby's conditional semantics) or " +
191
+ "`be true` (for exact `== true` equality)"
192
+ )
193
+ BuiltIn::BeTruthy.new
194
+ end
188
195
 
189
- module RSpec
190
- module Matchers
196
+ def be_false
197
+ RSpec.deprecate("`be_false`", :replacement =>
198
+ "`be_falsey` (for Ruby's conditional semantics) or " +
199
+ "`be false` (for exact `== false` equality)"
200
+ )
201
+ BuiltIn::BeFalsey.new
202
+ end
191
203
 
192
204
  # Passes if actual is truthy (anything but false or nil)
193
- def be_true
194
- BuiltIn::BeTrue.new
205
+ def be_truthy
206
+ BuiltIn::BeTruthy.new
195
207
  end
196
208
 
197
209
  # Passes if actual is falsy (false or nil)
198
- def be_false
199
- BuiltIn::BeFalse.new
210
+ def be_falsey
211
+ BuiltIn::BeFalsey.new
200
212
  end
201
213
 
214
+ alias_method :be_falsy, :be_falsey
215
+
202
216
  # Passes if actual is nil
203
217
  def be_nil
204
218
  BuiltIn::BeNil.new
205
219
  end
206
220
 
207
221
  # @example
208
- # actual.should be_true
209
- # actual.should be_false
210
- # actual.should be_nil
211
- # actual.should be_[arbitrary_predicate](*args)
212
- # actual.should_not be_nil
213
- # actual.should_not be_[arbitrary_predicate](*args)
222
+ # expect(actual).to be_truthy
223
+ # expect(actual).to be_falsey
224
+ # expect(actual).to be_nil
225
+ # expect(actual).to be_[arbitrary_predicate](*args)
226
+ # expect(actual).not_to be_nil
227
+ # expect(actual).not_to be_[arbitrary_predicate](*args)
214
228
  #
215
229
  # Given true, false, or nil, will pass if actual value is true, false or
216
230
  # nil (respectively). Given no args means the caller should satisfy an if
@@ -240,9 +254,9 @@ module RSpec
240
254
  #
241
255
  # @example
242
256
  #
243
- # 5.should be_instance_of(Fixnum)
244
- # 5.should_not be_instance_of(Numeric)
245
- # 5.should_not be_instance_of(Float)
257
+ # expect(5).to be_an_instance_of(Fixnum)
258
+ # expect(5).not_to be_an_instance_of(Numeric)
259
+ # expect(5).not_to be_an_instance_of(Float)
246
260
  def be_an_instance_of(expected)
247
261
  BuiltIn::BeAnInstanceOf.new(expected)
248
262
  end
@@ -253,9 +267,9 @@ module RSpec
253
267
  #
254
268
  # @example
255
269
  #
256
- # 5.should be_kind_of(Fixnum)
257
- # 5.should be_kind_of(Numeric)
258
- # 5.should_not be_kind_of(Float)
270
+ # expect(5).to be_a_kind_of(Fixnum)
271
+ # expect(5).to be_a_kind_of(Numeric)
272
+ # expect(5).not_to be_a_kind_of(Float)
259
273
  def be_a_kind_of(expected)
260
274
  BuiltIn::BeAKindOf.new(expected)
261
275
  end
@@ -266,8 +280,8 @@ module RSpec
266
280
  #
267
281
  # @example
268
282
  #
269
- # result.should be_within(0.5).of(3.0)
270
- # result.should_not be_within(0.5).of(3.0)
283
+ # expect(result).to be_within(0.5).of(3.0)
284
+ # expect(result).not_to be_within(0.5).of(3.0)
271
285
  def be_within(delta)
272
286
  BuiltIn::BeWithin.new(delta)
273
287
  end
@@ -283,55 +297,59 @@ module RSpec
283
297
  #
284
298
  # When passing a block, it must use the <tt>{ ... }</tt> format, not
285
299
  # do/end, as <tt>{ ... }</tt> binds to the +change+ method, whereas do/end
286
- # would errantly bind to the +should+ or +should_not+ method.
300
+ # would errantly bind to the +expect(..)+ or +expect(..).not_to+ method.
287
301
  #
288
302
  # @example
289
303
  #
290
- # lambda {
304
+ # expect {
291
305
  # team.add_player(player)
292
- # }.should change(roster, :count)
306
+ # }.to change(roster, :count)
293
307
  #
294
- # lambda {
308
+ # expect {
295
309
  # team.add_player(player)
296
- # }.should change(roster, :count).by(1)
310
+ # }.to change(roster, :count).by(1)
297
311
  #
298
- # lambda {
312
+ # expect {
299
313
  # team.add_player(player)
300
- # }.should change(roster, :count).by_at_least(1)
314
+ # }.to change(roster, :count).by_at_least(1)
301
315
  #
302
- # lambda {
316
+ # expect {
303
317
  # team.add_player(player)
304
- # }.should change(roster, :count).by_at_most(1)
318
+ # }.to change(roster, :count).by_at_most(1)
305
319
  #
306
320
  # string = "string"
307
- # lambda {
321
+ # expect {
308
322
  # string.reverse!
309
- # }.should change { string }.from("string").to("gnirts")
323
+ # }.to change { string }.from("string").to("gnirts")
310
324
  #
311
- # lambda {
325
+ # string = "string"
326
+ # expect {
327
+ # string
328
+ # }.not_to change { string }
329
+ #
330
+ # expect {
312
331
  # person.happy_birthday
313
- # }.should change(person, :birthday).from(32).to(33)
332
+ # }.to change(person, :birthday).from(32).to(33)
314
333
  #
315
- # lambda {
334
+ # expect {
316
335
  # employee.develop_great_new_social_networking_app
317
- # }.should change(employee, :title).from("Mail Clerk").to("CEO")
336
+ # }.to change(employee, :title).from("Mail Clerk").to("CEO")
318
337
  #
319
- # lambda {
338
+ # expect {
320
339
  # doctor.leave_office
321
- # }.should change(doctor, :sign).from(/is in/).to(/is out/)
340
+ # }.to change(doctor, :sign).from(/is in/).to(/is out/)
322
341
  #
323
342
  # user = User.new(:type => "admin")
324
- # lambda {
343
+ # expect {
325
344
  # user.symbolize_type
326
- # }.should change(user, :type).from(String).to(Symbol)
345
+ # }.to change(user, :type).from(String).to(Symbol)
327
346
  #
328
347
  # == Notes
329
348
  #
330
349
  # Evaluates <tt>receiver.message</tt> or <tt>block</tt> before and after it
331
- # evaluates the proc object (generated by the lambdas in the examples
332
- # above).
350
+ # evaluates the block passed to <tt>expect</tt>.
333
351
  #
334
- # <tt>should_not change</tt> only supports the form with no subsequent
352
+ # <tt>expect( ... ).not_to change</tt> only supports the form with no subsequent
335
353
  # calls to <tt>by</tt>, <tt>by_at_least</tt>, <tt>by_at_most</tt>,
336
354
  # <tt>to</tt> or <tt>from</tt>.
337
355
  def change(receiver=nil, message=nil, &block)
@@ -343,11 +361,11 @@ module RSpec
343
361
  # and it will only pass if all args are found in Range.
344
362
  #
345
363
  # @example
346
- # (1..10).should cover(5)
347
- # (1..10).should cover(4, 6)
348
- # (1..10).should cover(4, 6, 11) # will fail
349
- # (1..10).should_not cover(11)
350
- # (1..10).should_not cover(5) # will fail
364
+ # expect(1..10).to cover(5)
365
+ # expect(1..10).to cover(4, 6)
366
+ # expect(1..10).to cover(4, 6, 11) # fails
367
+ # expect(1..10).not_to cover(11)
368
+ # expect(1..10).not_to cover(5) # fails
351
369
  #
352
370
  # ### Warning:: Ruby >= 1.9 only
353
371
  def cover(*values)
@@ -361,45 +379,48 @@ module RSpec
361
379
  #
362
380
  # @example
363
381
  #
364
- # "this string".should end_with "string"
365
- # [0, 1, 2, 3, 4].should end_with 4
366
- # [0, 2, 3, 4, 4].should end_with 3, 4
382
+ # expect("this string").to end_with "string"
383
+ # expect([0, 1, 2, 3, 4]).to end_with 4
384
+ # expect([0, 2, 3, 4, 4]).to end_with 3, 4
367
385
  def end_with(*expected)
368
386
  BuiltIn::EndWith.new(*expected)
369
387
  end
370
388
 
371
389
  # Passes if <tt>actual == expected</tt>.
372
390
  #
373
- # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
391
+ # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more
392
+ # information about equality in Ruby.
374
393
  #
375
394
  # @example
376
395
  #
377
- # 5.should eq(5)
378
- # 5.should_not eq(3)
396
+ # expect(5).to eq(5)
397
+ # expect(5).not_to eq(3)
379
398
  def eq(expected)
380
399
  BuiltIn::Eq.new(expected)
381
400
  end
382
401
 
383
402
  # Passes if +actual.eql?(expected)+
384
403
  #
385
- # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
404
+ # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more
405
+ # information about equality in Ruby.
386
406
  #
387
407
  # @example
388
408
  #
389
- # 5.should eql(5)
390
- # 5.should_not eql(3)
409
+ # expect(5).to eql(5)
410
+ # expect(5).not_to eql(3)
391
411
  def eql(expected)
392
412
  BuiltIn::Eql.new(expected)
393
413
  end
394
414
 
395
415
  # Passes if <tt>actual.equal?(expected)</tt> (object identity).
396
416
  #
397
- # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
417
+ # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more
418
+ # information about equality in Ruby.
398
419
  #
399
420
  # @example
400
421
  #
401
- # 5.should equal(5) # Fixnums are equal
402
- # "5".should_not equal("5") # Strings that look the same are not the same object
422
+ # expect(5).to equal(5) # Fixnums are equal
423
+ # expect("5").not_to equal("5") # Strings that look the same are not the same object
403
424
  def equal(expected)
404
425
  BuiltIn::Equal.new(expected)
405
426
  end
@@ -407,7 +428,7 @@ module RSpec
407
428
  # Passes if `actual.exist?` or `actual.exists?`
408
429
  #
409
430
  # @example
410
- # File.should exist("path/to/file")
431
+ # expect(File).to exist("path/to/file")
411
432
  def exist(*args)
412
433
  BuiltIn::Exist.new(*args)
413
434
  end
@@ -430,16 +451,16 @@ module RSpec
430
451
  # @example
431
452
  #
432
453
  # # Passes if team.players.size == 11
433
- # team.should have(11).players
454
+ # expect(team).to have(11).players
434
455
  #
435
456
  # # Passes if [1,2,3].length == 3
436
- # [1,2,3].should have(3).items #"items" is pure sugar
457
+ # expect([1,2,3]).to have(3).items #"items" is pure sugar
437
458
  #
438
459
  # # Passes if ['a', 'b', 'c'].count == 3
439
- # [1,2,3].should have(3).items #"items" is pure sugar
460
+ # expect([1,2,3]).to have(3).items #"items" is pure sugar
440
461
  #
441
462
  # # Passes if "this string".length == 11
442
- # "this string".should have(11).characters #"characters" is pure sugar
463
+ # expect("this string").to have(11).characters #"characters" is pure sugar
443
464
  def have(n)
444
465
  BuiltIn::Have.new(n)
445
466
  end
@@ -448,11 +469,11 @@ module RSpec
448
469
  # Exactly like have() with >=.
449
470
  #
450
471
  # @example
451
- # "this".should have_at_least(3).letters
472
+ # expect("this").to have_at_least(3).letters
452
473
  #
453
474
  # ### Warning:
454
475
  #
455
- # `should_not have_at_least` is not supported
476
+ # `expect(..).not_to have_at_least` is not supported
456
477
  def have_at_least(n)
457
478
  BuiltIn::Have.new(n, :at_least)
458
479
  end
@@ -460,11 +481,11 @@ module RSpec
460
481
  # Exactly like have() with <=.
461
482
  #
462
483
  # @example
463
- # should have_at_most(number).items
484
+ # expect("this").to have_at_most(4).letters
464
485
  #
465
486
  # ### Warning:
466
487
  #
467
- # `should_not have_at_most` is not supported
488
+ # `expect(..).not_to have_at_most` is not supported
468
489
  def have_at_most(n)
469
490
  BuiltIn::Have.new(n, :at_most)
470
491
  end
@@ -475,12 +496,12 @@ module RSpec
475
496
  #
476
497
  # @example
477
498
  #
478
- # [1,2,3].should include(3)
479
- # [1,2,3].should include(2,3) #would pass
480
- # [1,2,3].should include(2,3,4) #would fail
481
- # [1,2,3].should_not include(4)
482
- # "spread".should include("read")
483
- # "spread".should_not include("red")
499
+ # expect([1,2,3]).to include(3)
500
+ # expect([1,2,3]).to include(2,3)
501
+ # expect([1,2,3]).to include(2,3,4) # fails
502
+ # expect([1,2,3]).not_to include(4)
503
+ # expect("spread").to include("read")
504
+ # expect("spread").not_to include("red")
484
505
  def include(*expected)
485
506
  BuiltIn::Include.new(*expected)
486
507
  end
@@ -489,10 +510,10 @@ module RSpec
489
510
  #
490
511
  # @example
491
512
  #
492
- # email.should match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
493
- # email.should match("@example.com")
494
- # zipcode.should match_regex(/\A\d{5}(-\d{4})?\z/)
495
- # zipcode.should match_regex("90210")
513
+ # expect(email).to match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
514
+ # expect(email).to match("@example.com")
515
+ # expect(zipcode).to match_regex(/\A\d{5}(-\d{4})?\z/)
516
+ # expect(zipcode).to match_regex("90210")
496
517
  #
497
518
  # @note Due to Ruby's method dispatch mechanism, using the `#match` matcher
498
519
  # within a custom matcher defined via the matcher DSL
@@ -513,16 +534,13 @@ module RSpec
513
534
  #
514
535
  # @example
515
536
  #
516
- # lambda { do_something_risky }.should raise_error
517
- # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError)
518
- # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError) { |error| error.data.should == 42 }
519
- # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, "that was too risky")
520
- # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, /oo ri/)
537
+ # expect { do_something_risky }.to raise_error
538
+ # expect { do_something_risky }.to raise_error(PoorRiskDecisionError)
539
+ # expect { do_something_risky }.to raise_error(PoorRiskDecisionError) { |error| expect(error.data).to eq 42 }
540
+ # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, "that was too risky")
541
+ # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, /oo ri/)
521
542
  #
522
- # lambda { do_something_risky }.should_not raise_error
523
- # lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError)
524
- # lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, "that was too risky")
525
- # lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, /oo ri/)
543
+ # expect { do_something_risky }.not_to raise_error
526
544
  def raise_error(error=Exception, message=nil, &block)
527
545
  BuiltIn::RaiseError.new(error, message, &block)
528
546
  end
@@ -534,6 +552,8 @@ module RSpec
534
552
  #
535
553
  # @example
536
554
  #
555
+ # expect("string").to respond_to(:length)
556
+ #
537
557
  def respond_to(*names)
538
558
  BuiltIn::RespondTo.new(*names)
539
559
  end
@@ -550,9 +570,7 @@ module RSpec
550
570
  #
551
571
  # @example
552
572
  #
553
- # 5.should satisfy { |n|
554
- # n > 3
555
- # }
573
+ # expect(5).to satisfy { |n| n > 3 }
556
574
  def satisfy(&block)
557
575
  BuiltIn::Satisfy.new(&block)
558
576
  end
@@ -564,9 +582,9 @@ module RSpec
564
582
  #
565
583
  # @example
566
584
  #
567
- # "this string".should start_with "this s"
568
- # [0, 1, 2, 3, 4].should start_with 0
569
- # [0, 2, 3, 4, 4].should start_with 0, 1
585
+ # expect("this string").to start_with "this s"
586
+ # expect([0, 1, 2, 3, 4]).to start_with 0
587
+ # expect([0, 2, 3, 4, 4]).to start_with 0, 1
570
588
  def start_with(*expected)
571
589
  BuiltIn::StartWith.new(*expected)
572
590
  end
@@ -580,13 +598,13 @@ module RSpec
580
598
  #
581
599
  # @example
582
600
  #
583
- # lambda { do_something_risky }.should throw_symbol
584
- # lambda { do_something_risky }.should throw_symbol(:that_was_risky)
585
- # lambda { do_something_risky }.should throw_symbol(:that_was_risky, culprit)
601
+ # expect { do_something_risky }.to throw_symbol
602
+ # expect { do_something_risky }.to throw_symbol(:that_was_risky)
603
+ # expect { do_something_risky }.to throw_symbol(:that_was_risky, 'culprit')
586
604
  #
587
- # lambda { do_something_risky }.should_not throw_symbol
588
- # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky)
589
- # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky, culprit)
605
+ # expect { do_something_risky }.not_to throw_symbol
606
+ # expect { do_something_risky }.not_to throw_symbol(:that_was_risky)
607
+ # expect { do_something_risky }.not_to throw_symbol(:that_was_risky, 'culprit')
590
608
  def throw_symbol(expected_symbol=nil, expected_arg=nil)
591
609
  BuiltIn::ThrowSymbol.new(expected_symbol, expected_arg)
592
610
  end
@@ -679,21 +697,32 @@ module RSpec
679
697
  #
680
698
  # @note This is also available using the `=~` operator with `should`,
681
699
  # but `=~` is not supported with `expect`.
682
- # @note There is no should_not version of array.should =~ other_array
700
+ #
701
+ # @note This matcher only supports positive expectations.
702
+ # expect(..).not_to match_array(other_array) is not supported.
683
703
  #
684
704
  # @example
685
705
  #
686
706
  # expect([1,2,3]).to match_array([1,2,3])
687
707
  # expect([1,2,3]).to match_array([1,3,2])
688
- # [1,2,3].should =~ [1,2,3] # => would pass
689
- # [1,2,3].should =~ [2,3,1] # => would pass
690
- # [1,2,3,4].should =~ [1,2,3] # => would fail
691
- # [1,2,2,3].should =~ [1,2,3] # => would fail
692
- # [1,2,3].should =~ [1,2,3,4] # => would fail
693
708
  def match_array(array)
694
709
  BuiltIn::MatchArray.new(array)
695
710
  end
696
711
 
697
- OperatorMatcher.register(Enumerable, '=~', BuiltIn::MatchArray)
712
+ BuiltIn::OperatorMatcher.register(Enumerable, '=~', BuiltIn::MatchArray)
713
+
714
+ def self.const_missing(name)
715
+ case name
716
+ when :OperatorMatcher
717
+ RSpec.deprecate("`RSpec::Matchers::OperatorMatcher`",
718
+ :replacement => "`RSpec::Matchers::BuiltIn::OperatorMatcher`")
719
+ BuiltIn::OperatorMatcher
720
+ when :Configuration
721
+ RSpec.deprecate("`RSpec::Matchers::Configuration`",
722
+ :replacement => "`RSpec::Expectations::Configuration`")
723
+ Expectations::Configuration
724
+ else super
725
+ end
726
+ end
698
727
  end
699
728
  end
@@ -1 +1,6 @@
1
1
  require "rspec/expectations"
2
+
3
+ RSpec.deprecate("`require 'rspec-expectations'`",
4
+ :replacement => "`require 'rspec/expectations'`",
5
+ # we explcitly pass a caller because CallerFilter ignores this file
6
+ :call_site => caller[RUBY_PLATFORM == 'java' ? 2 : 0])