rspec-expectations 2.13.0 → 2.14.0.rc1

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 (60) hide show
  1. data/Changelog.md +34 -0
  2. data/README.md +43 -87
  3. data/features/README.md +8 -9
  4. data/features/built_in_matchers/README.md +41 -41
  5. data/features/built_in_matchers/be_within.feature +3 -3
  6. data/features/built_in_matchers/expect_change.feature +6 -6
  7. data/features/built_in_matchers/expect_error.feature +2 -2
  8. data/features/built_in_matchers/start_with.feature +1 -1
  9. data/features/built_in_matchers/throw_symbol.feature +11 -11
  10. data/features/built_in_matchers/yield.feature +18 -3
  11. data/features/custom_matchers/define_diffable_matcher.feature +1 -1
  12. data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
  13. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
  14. data/features/customized_message.feature +1 -1
  15. data/features/support/env.rb +10 -1
  16. data/features/syntax_configuration.feature +3 -0
  17. data/features/test_frameworks/test_unit.feature +15 -17
  18. data/lib/rspec/expectations.rb +1 -1
  19. data/lib/rspec/expectations/deprecation.rb +12 -33
  20. data/lib/rspec/expectations/differ.rb +25 -7
  21. data/lib/rspec/expectations/expectation_target.rb +7 -8
  22. data/lib/rspec/expectations/extensions/object.rb +2 -12
  23. data/lib/rspec/expectations/fail_with.rb +11 -1
  24. data/lib/rspec/expectations/handler.rb +11 -6
  25. data/lib/rspec/expectations/syntax.rb +2 -2
  26. data/lib/rspec/expectations/version.rb +1 -1
  27. data/lib/rspec/matchers.rb +134 -144
  28. data/lib/rspec/matchers/be_close.rb +1 -1
  29. data/lib/rspec/matchers/built_in/be_within.rb +1 -1
  30. data/lib/rspec/matchers/built_in/have.rb +20 -4
  31. data/lib/rspec/matchers/built_in/raise_error.rb +23 -7
  32. data/lib/rspec/matchers/built_in/yield.rb +78 -3
  33. data/lib/rspec/matchers/operator_matcher.rb +1 -1
  34. data/lib/rspec/matchers/test_unit_integration.rb +11 -0
  35. data/spec/rspec/expectations/differ_spec.rb +27 -5
  36. data/spec/rspec/expectations/expectation_target_spec.rb +10 -3
  37. data/spec/rspec/expectations/extensions/kernel_spec.rb +5 -5
  38. data/spec/rspec/expectations/fail_with_spec.rb +19 -0
  39. data/spec/rspec/expectations/handler_spec.rb +42 -21
  40. data/spec/rspec/expectations/syntax_spec.rb +45 -3
  41. data/spec/rspec/matchers/be_close_spec.rb +6 -6
  42. data/spec/rspec/matchers/be_spec.rb +36 -36
  43. data/spec/rspec/matchers/be_within_spec.rb +4 -0
  44. data/spec/rspec/matchers/change_spec.rb +6 -6
  45. data/spec/rspec/matchers/configuration_spec.rb +57 -89
  46. data/spec/rspec/matchers/description_generation_spec.rb +1 -1
  47. data/spec/rspec/matchers/exist_spec.rb +9 -9
  48. data/spec/rspec/matchers/has_spec.rb +1 -1
  49. data/spec/rspec/matchers/have_spec.rb +12 -2
  50. data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
  51. data/spec/rspec/matchers/include_spec.rb +4 -4
  52. data/spec/rspec/matchers/match_array_spec.rb +1 -1
  53. data/spec/rspec/matchers/match_spec.rb +1 -1
  54. data/spec/rspec/matchers/raise_error_spec.rb +189 -99
  55. data/spec/rspec/matchers/respond_to_spec.rb +4 -4
  56. data/spec/rspec/matchers/satisfy_spec.rb +1 -1
  57. data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
  58. data/spec/rspec/matchers/yield_spec.rb +81 -4
  59. data/spec/spec_helper.rb +1 -1
  60. metadata +10 -12
@@ -52,7 +52,17 @@ module RSpec
52
52
 
53
53
  def coerce_to_string(string_or_array)
54
54
  return string_or_array unless Array === string_or_array
55
- string_or_array.join(',')
55
+ diffably_stringify(string_or_array).join("\n")
56
+ end
57
+
58
+ def diffably_stringify(array)
59
+ array.map do |entry|
60
+ if Array === entry
61
+ entry.inspect
62
+ else
63
+ entry.to_s.gsub("\n", "\\n")
64
+ end
65
+ end
56
66
  end
57
67
 
58
68
  if String.method_defined?(:encoding)
@@ -2,13 +2,14 @@ module RSpec
2
2
  module Expectations
3
3
 
4
4
  class ExpectationHandler
5
- def self.message_must_be_string(msg)
6
- "WARNING: ignoring the provided expectation message argument " +
7
- "(#{msg.inspect}) since it is not a string."
8
- end
9
-
10
5
  def self.check_message(msg)
11
- ::Kernel.warn message_must_be_string(msg) unless msg.nil? || msg.is_a?(String)
6
+ unless msg.nil? || msg.respond_to?(:to_str) || msg.respond_to?(:call)
7
+ ::Kernel.warn [
8
+ "WARNING: ignoring the provided expectation message argument (",
9
+ msg.inspect,
10
+ ") since it is not a string or a proc."
11
+ ].join
12
+ end
12
13
  end
13
14
  end
14
15
 
@@ -23,6 +24,8 @@ module RSpec
23
24
  match = matcher.matches?(actual, &block)
24
25
  return match if match
25
26
 
27
+ message = message.call if message.respond_to?(:call)
28
+
26
29
  message ||= matcher.respond_to?(:failure_message_for_should) ?
27
30
  matcher.failure_message_for_should :
28
31
  matcher.failure_message
@@ -47,6 +50,8 @@ module RSpec
47
50
  matcher.matches?(actual, &block)
48
51
  return match unless match
49
52
 
53
+ message = message.call if message.respond_to?(:call)
54
+
50
55
  message ||= matcher.respond_to?(:failure_message_for_should_not) ?
51
56
  matcher.failure_message_for_should_not :
52
57
  matcher.negative_failure_message
@@ -32,10 +32,10 @@ module RSpec
32
32
  # `ExpectationTarget`.
33
33
  # @example
34
34
  # expect(actual).to eq(expected)
35
- # expect(actual).to_not eq(expected)
35
+ # expect(actual).not_to eq(expected)
36
36
  # @return [ExpectationTarget]
37
37
  # @see ExpectationTarget#to
38
- # @see ExpectationTarget#to_not
38
+ # @see ExpectationTarget#not_to
39
39
 
40
40
  # @api private
41
41
  # Determines where we add `should` and `should_not`.
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '2.13.0'
5
+ STRING = '2.14.0.rc1'
6
6
  end
7
7
  end
8
8
  end
@@ -1,5 +1,19 @@
1
+ require 'rspec/matchers/extensions/instance_eval_with_args'
2
+ require 'rspec/matchers/pretty'
3
+
4
+ require 'rspec/matchers/built_in'
5
+ require 'rspec/matchers/matcher'
6
+ require 'rspec/matchers/operator_matcher'
7
+ require 'rspec/matchers/be_close'
8
+
9
+ require 'rspec/matchers/generated_descriptions'
10
+ require 'rspec/matchers/method_missing'
11
+ require 'rspec/matchers/compatibility'
12
+ require 'rspec/matchers/dsl'
13
+ require 'rspec/matchers/test_unit_integration'
14
+
1
15
  module RSpec
2
- # RSpec::Matchers provides a number of useful matchers we use to compose
16
+ # RSpec::Matchers provides a number of useful matchers we use to define
3
17
  # expectations. A matcher is any object that responds to the following:
4
18
  #
5
19
  # matches?(actual)
@@ -20,28 +34,29 @@ module RSpec
20
34
  # A Ruby predicate is a method that ends with a "?" and returns true or false.
21
35
  # Common examples are `empty?`, `nil?`, and `instance_of?`.
22
36
  #
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:
37
+ # All you need to do is write `expect(..).to be_` followed by the predicate
38
+ # without the question mark, and RSpec will figure it out from there.
39
+ # For example:
25
40
  #
26
- # [].should be_empty # => [].empty?() | passes
27
- # [].should_not be_empty # => [].empty?() | fails
41
+ # expect([]).to be_empty # => [].empty?() | passes
42
+ # expect([]).not_to be_empty # => [].empty?() | fails
28
43
  #
29
44
  # In addtion to prefixing the predicate matchers with "be_", you can also use "be_a_"
30
45
  # and "be_an_", making your specs read much more naturally:
31
46
  #
32
- # "a string".should be_an_instance_of(String) =>"a string".instance_of?(String) #passes
47
+ # expect("a string").to be_an_instance_of(String) # =>"a string".instance_of?(String) # passes
33
48
  #
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
49
+ # expect(3).to be_a_kind_of(Fixnum) # => 3.kind_of?(Numeric) | passes
50
+ # expect(3).to be_a_kind_of(Numeric) # => 3.kind_of?(Numeric) | passes
51
+ # expect(3).to be_an_instance_of(Fixnum) # => 3.instance_of?(Fixnum) | passes
52
+ # expect(3).not_to be_an_instance_of(Numeric) # => 3.instance_of?(Numeric) | fails
38
53
  #
39
54
  # RSpec will also create custom matchers for predicates like `has_key?`. To
40
55
  # use this feature, just state that the object should have_key(:key) and RSpec will
41
56
  # call has_key?(:key) on the target. For example:
42
57
  #
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
58
+ # expect(:a => "A").to have_key(:a)
59
+ # expect(:a => "A").to have_key(:b) # fails
45
60
  #
46
61
  # You can use this feature to invoke any predicate that begins with "has_", whether it is
47
62
  # part of the Ruby libraries (like `Hash#has_key?`) or a method you wrote on your own class.
@@ -58,15 +73,15 @@ module RSpec
58
73
  # zones on a virtual board. To specify that bob should be in zone 4, you
59
74
  # could say:
60
75
  #
61
- # bob.current_zone.should eql(Zone.new("4"))
76
+ # expect(bob.current_zone).to eql(Zone.new("4"))
62
77
  #
63
78
  # But you might find it more expressive to say:
64
79
  #
65
- # bob.should be_in_zone("4")
80
+ # expect(bob).to be_in_zone("4")
66
81
  #
67
82
  # and/or
68
83
  #
69
- # bob.should_not be_in_zone("3")
84
+ # expect(bob).not_to be_in_zone("3")
70
85
  #
71
86
  # You can create such a matcher like so:
72
87
  #
@@ -102,7 +117,7 @@ module RSpec
102
117
  # passed to the <tt>create</tt> method (in this case, <tt>zone</tt>). The
103
118
  # failure message methods (<tt>failure_message_for_should</tt> and
104
119
  # <tt>failure_message_for_should_not</tt>) are passed the actual value (the
105
- # receiver of <tt>should</tt> or <tt>should_not</tt>).
120
+ # receiver of <tt>expect(..)</tt> or <tt>expect(..).not_to</tt>).
106
121
  #
107
122
  # ### Custom Matcher from scratch
108
123
  #
@@ -158,35 +173,6 @@ module RSpec
158
173
  # RSpec::configure do |config|
159
174
  # config.include(CustomGameMatchers)
160
175
  # end
161
- 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
175
-
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'
183
-
184
- require 'rspec/matchers/generated_descriptions'
185
- require 'rspec/matchers/method_missing'
186
- require 'rspec/matchers/compatibility'
187
- require 'rspec/matchers/dsl'
188
-
189
- module RSpec
190
176
  module Matchers
191
177
 
192
178
  # Passes if actual is truthy (anything but false or nil)
@@ -205,12 +191,12 @@ module RSpec
205
191
  end
206
192
 
207
193
  # @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)
194
+ # expect(actual).to be_true
195
+ # expect(actual).to be_false
196
+ # expect(actual).to be_nil
197
+ # expect(actual).to be_[arbitrary_predicate](*args)
198
+ # expect(actual).not_to be_nil
199
+ # expect(actual).not_to be_[arbitrary_predicate](*args)
214
200
  #
215
201
  # Given true, false, or nil, will pass if actual value is true, false or
216
202
  # nil (respectively). Given no args means the caller should satisfy an if
@@ -240,9 +226,9 @@ module RSpec
240
226
  #
241
227
  # @example
242
228
  #
243
- # 5.should be_instance_of(Fixnum)
244
- # 5.should_not be_instance_of(Numeric)
245
- # 5.should_not be_instance_of(Float)
229
+ # expect(5).to be_an_instance_of(Fixnum)
230
+ # expect(5).not_to be_an_instance_of(Numeric)
231
+ # expect(5).not_to be_an_instance_of(Float)
246
232
  def be_an_instance_of(expected)
247
233
  BuiltIn::BeAnInstanceOf.new(expected)
248
234
  end
@@ -253,9 +239,9 @@ module RSpec
253
239
  #
254
240
  # @example
255
241
  #
256
- # 5.should be_kind_of(Fixnum)
257
- # 5.should be_kind_of(Numeric)
258
- # 5.should_not be_kind_of(Float)
242
+ # expect(5).to be_a_kind_of(Fixnum)
243
+ # expect(5).to be_a_kind_of(Numeric)
244
+ # expect(5).not_to be_a_kind_of(Float)
259
245
  def be_a_kind_of(expected)
260
246
  BuiltIn::BeAKindOf.new(expected)
261
247
  end
@@ -266,8 +252,8 @@ module RSpec
266
252
  #
267
253
  # @example
268
254
  #
269
- # result.should be_within(0.5).of(3.0)
270
- # result.should_not be_within(0.5).of(3.0)
255
+ # expect(result).to be_within(0.5).of(3.0)
256
+ # expect(result).not_to be_within(0.5).of(3.0)
271
257
  def be_within(delta)
272
258
  BuiltIn::BeWithin.new(delta)
273
259
  end
@@ -283,55 +269,59 @@ module RSpec
283
269
  #
284
270
  # When passing a block, it must use the <tt>{ ... }</tt> format, not
285
271
  # do/end, as <tt>{ ... }</tt> binds to the +change+ method, whereas do/end
286
- # would errantly bind to the +should+ or +should_not+ method.
272
+ # would errantly bind to the +expect(..)+ or +expect(..).not_to+ method.
287
273
  #
288
274
  # @example
289
275
  #
290
- # lambda {
276
+ # expect {
291
277
  # team.add_player(player)
292
- # }.should change(roster, :count)
278
+ # }.to change(roster, :count)
293
279
  #
294
- # lambda {
280
+ # expect {
295
281
  # team.add_player(player)
296
- # }.should change(roster, :count).by(1)
282
+ # }.to change(roster, :count).by(1)
297
283
  #
298
- # lambda {
284
+ # expect {
299
285
  # team.add_player(player)
300
- # }.should change(roster, :count).by_at_least(1)
286
+ # }.to change(roster, :count).by_at_least(1)
301
287
  #
302
- # lambda {
288
+ # expect {
303
289
  # team.add_player(player)
304
- # }.should change(roster, :count).by_at_most(1)
290
+ # }.to change(roster, :count).by_at_most(1)
305
291
  #
306
292
  # string = "string"
307
- # lambda {
293
+ # expect {
308
294
  # string.reverse!
309
- # }.should change { string }.from("string").to("gnirts")
295
+ # }.to change { string }.from("string").to("gnirts")
310
296
  #
311
- # lambda {
297
+ # string = "string"
298
+ # expect {
299
+ # string
300
+ # }.not_to change { string }
301
+ #
302
+ # expect {
312
303
  # person.happy_birthday
313
- # }.should change(person, :birthday).from(32).to(33)
304
+ # }.to change(person, :birthday).from(32).to(33)
314
305
  #
315
- # lambda {
306
+ # expect {
316
307
  # employee.develop_great_new_social_networking_app
317
- # }.should change(employee, :title).from("Mail Clerk").to("CEO")
308
+ # }.to change(employee, :title).from("Mail Clerk").to("CEO")
318
309
  #
319
- # lambda {
310
+ # expect {
320
311
  # doctor.leave_office
321
- # }.should change(doctor, :sign).from(/is in/).to(/is out/)
312
+ # }.to change(doctor, :sign).from(/is in/).to(/is out/)
322
313
  #
323
314
  # user = User.new(:type => "admin")
324
- # lambda {
315
+ # expect {
325
316
  # user.symbolize_type
326
- # }.should change(user, :type).from(String).to(Symbol)
317
+ # }.to change(user, :type).from(String).to(Symbol)
327
318
  #
328
319
  # == Notes
329
320
  #
330
321
  # 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).
322
+ # evaluates the block passed to <tt>expect</tt>.
333
323
  #
334
- # <tt>should_not change</tt> only supports the form with no subsequent
324
+ # <tt>expect( ... ).not_to change</tt> only supports the form with no subsequent
335
325
  # calls to <tt>by</tt>, <tt>by_at_least</tt>, <tt>by_at_most</tt>,
336
326
  # <tt>to</tt> or <tt>from</tt>.
337
327
  def change(receiver=nil, message=nil, &block)
@@ -343,11 +333,11 @@ module RSpec
343
333
  # and it will only pass if all args are found in Range.
344
334
  #
345
335
  # @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
336
+ # expect(1..10).to cover(5)
337
+ # expect(1..10).to cover(4, 6)
338
+ # expect(1..10).to cover(4, 6, 11) # fails
339
+ # expect(1..10).not_to cover(11)
340
+ # expect(1..10).not_to cover(5) # fails
351
341
  #
352
342
  # ### Warning:: Ruby >= 1.9 only
353
343
  def cover(*values)
@@ -361,45 +351,48 @@ module RSpec
361
351
  #
362
352
  # @example
363
353
  #
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
354
+ # expect("this string").to end_with "string"
355
+ # expect([0, 1, 2, 3, 4]).to end_with 4
356
+ # expect([0, 2, 3, 4, 4]).to end_with 3, 4
367
357
  def end_with(*expected)
368
358
  BuiltIn::EndWith.new(*expected)
369
359
  end
370
360
 
371
361
  # Passes if <tt>actual == expected</tt>.
372
362
  #
373
- # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
363
+ # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more
364
+ # information about equality in Ruby.
374
365
  #
375
366
  # @example
376
367
  #
377
- # 5.should eq(5)
378
- # 5.should_not eq(3)
368
+ # expect(5).to eq(5)
369
+ # expect(5).not_to eq(3)
379
370
  def eq(expected)
380
371
  BuiltIn::Eq.new(expected)
381
372
  end
382
373
 
383
374
  # Passes if +actual.eql?(expected)+
384
375
  #
385
- # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
376
+ # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more
377
+ # information about equality in Ruby.
386
378
  #
387
379
  # @example
388
380
  #
389
- # 5.should eql(5)
390
- # 5.should_not eql(3)
381
+ # expect(5).to eql(5)
382
+ # expect(5).not_to eql(3)
391
383
  def eql(expected)
392
384
  BuiltIn::Eql.new(expected)
393
385
  end
394
386
 
395
387
  # Passes if <tt>actual.equal?(expected)</tt> (object identity).
396
388
  #
397
- # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
389
+ # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more
390
+ # information about equality in Ruby.
398
391
  #
399
392
  # @example
400
393
  #
401
- # 5.should equal(5) # Fixnums are equal
402
- # "5".should_not equal("5") # Strings that look the same are not the same object
394
+ # expect(5).to equal(5) # Fixnums are equal
395
+ # expect("5").not_to equal("5") # Strings that look the same are not the same object
403
396
  def equal(expected)
404
397
  BuiltIn::Equal.new(expected)
405
398
  end
@@ -407,7 +400,7 @@ module RSpec
407
400
  # Passes if `actual.exist?` or `actual.exists?`
408
401
  #
409
402
  # @example
410
- # File.should exist("path/to/file")
403
+ # expect(File).to exist("path/to/file")
411
404
  def exist(*args)
412
405
  BuiltIn::Exist.new(*args)
413
406
  end
@@ -430,16 +423,16 @@ module RSpec
430
423
  # @example
431
424
  #
432
425
  # # Passes if team.players.size == 11
433
- # team.should have(11).players
426
+ # expect(team).to have(11).players
434
427
  #
435
428
  # # Passes if [1,2,3].length == 3
436
- # [1,2,3].should have(3).items #"items" is pure sugar
429
+ # expect([1,2,3]).to have(3).items #"items" is pure sugar
437
430
  #
438
431
  # # Passes if ['a', 'b', 'c'].count == 3
439
- # [1,2,3].should have(3).items #"items" is pure sugar
432
+ # expect([1,2,3]).to have(3).items #"items" is pure sugar
440
433
  #
441
434
  # # Passes if "this string".length == 11
442
- # "this string".should have(11).characters #"characters" is pure sugar
435
+ # expect("this string").to have(11).characters #"characters" is pure sugar
443
436
  def have(n)
444
437
  BuiltIn::Have.new(n)
445
438
  end
@@ -448,11 +441,11 @@ module RSpec
448
441
  # Exactly like have() with >=.
449
442
  #
450
443
  # @example
451
- # "this".should have_at_least(3).letters
444
+ # expect("this").to have_at_least(3).letters
452
445
  #
453
446
  # ### Warning:
454
447
  #
455
- # `should_not have_at_least` is not supported
448
+ # `expect(..).not_to have_at_least` is not supported
456
449
  def have_at_least(n)
457
450
  BuiltIn::Have.new(n, :at_least)
458
451
  end
@@ -460,11 +453,11 @@ module RSpec
460
453
  # Exactly like have() with <=.
461
454
  #
462
455
  # @example
463
- # should have_at_most(number).items
456
+ # expect("this").to have_at_most(4).letters
464
457
  #
465
458
  # ### Warning:
466
459
  #
467
- # `should_not have_at_most` is not supported
460
+ # `expect(..).not_to have_at_most` is not supported
468
461
  def have_at_most(n)
469
462
  BuiltIn::Have.new(n, :at_most)
470
463
  end
@@ -475,12 +468,12 @@ module RSpec
475
468
  #
476
469
  # @example
477
470
  #
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")
471
+ # expect([1,2,3]).to include(3)
472
+ # expect([1,2,3]).to include(2,3)
473
+ # expect([1,2,3]).to include(2,3,4) # fails
474
+ # expect([1,2,3]).not_to include(4)
475
+ # expect("spread").to include("read")
476
+ # expect("spread").not_to include("red")
484
477
  def include(*expected)
485
478
  BuiltIn::Include.new(*expected)
486
479
  end
@@ -489,10 +482,10 @@ module RSpec
489
482
  #
490
483
  # @example
491
484
  #
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")
485
+ # expect(email).to match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
486
+ # expect(email).to match("@example.com")
487
+ # expect(zipcode).to match_regex(/\A\d{5}(-\d{4})?\z/)
488
+ # expect(zipcode).to match_regex("90210")
496
489
  #
497
490
  # @note Due to Ruby's method dispatch mechanism, using the `#match` matcher
498
491
  # within a custom matcher defined via the matcher DSL
@@ -513,16 +506,16 @@ module RSpec
513
506
  #
514
507
  # @example
515
508
  #
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/)
509
+ # expect { do_something_risky }.to raise_error
510
+ # expect { do_something_risky }.to raise_error(PoorRiskDecisionError)
511
+ # expect { do_something_risky }.to raise_error(PoorRiskDecisionError) { |error| expect(error.data).to eq 42 }
512
+ # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, "that was too risky")
513
+ # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, /oo ri/)
521
514
  #
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/)
515
+ # expect { do_something_risky }.not_to raise_error
516
+ # expect { do_something_risky }.not_to raise_error(PoorRiskDecisionError)
517
+ # expect { do_something_risky }.not_to raise_error(PoorRiskDecisionError, "that was too risky")
518
+ # expect { do_something_risky }.not_to raise_error(PoorRiskDecisionError, /oo ri/)
526
519
  def raise_error(error=Exception, message=nil, &block)
527
520
  BuiltIn::RaiseError.new(error, message, &block)
528
521
  end
@@ -534,6 +527,8 @@ module RSpec
534
527
  #
535
528
  # @example
536
529
  #
530
+ # expect("string").to respond_to(:length)
531
+ #
537
532
  def respond_to(*names)
538
533
  BuiltIn::RespondTo.new(*names)
539
534
  end
@@ -550,9 +545,7 @@ module RSpec
550
545
  #
551
546
  # @example
552
547
  #
553
- # 5.should satisfy { |n|
554
- # n > 3
555
- # }
548
+ # expect(5).to satisfy { |n| n > 3 }
556
549
  def satisfy(&block)
557
550
  BuiltIn::Satisfy.new(&block)
558
551
  end
@@ -564,9 +557,9 @@ module RSpec
564
557
  #
565
558
  # @example
566
559
  #
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
560
+ # expect("this string").to start_with "this s"
561
+ # expect([0, 1, 2, 3, 4]).to start_with 0
562
+ # expect([0, 2, 3, 4, 4]).to start_with 0, 1
570
563
  def start_with(*expected)
571
564
  BuiltIn::StartWith.new(*expected)
572
565
  end
@@ -580,13 +573,13 @@ module RSpec
580
573
  #
581
574
  # @example
582
575
  #
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)
576
+ # expect { do_something_risky }.to throw_symbol
577
+ # expect { do_something_risky }.to throw_symbol(:that_was_risky)
578
+ # expect { do_something_risky }.to throw_symbol(:that_was_risky, 'culprit')
586
579
  #
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)
580
+ # expect { do_something_risky }.not_to throw_symbol
581
+ # expect { do_something_risky }.not_to throw_symbol(:that_was_risky)
582
+ # expect { do_something_risky }.not_to throw_symbol(:that_was_risky, 'culprit')
590
583
  def throw_symbol(expected_symbol=nil, expected_arg=nil)
591
584
  BuiltIn::ThrowSymbol.new(expected_symbol, expected_arg)
592
585
  end
@@ -679,17 +672,14 @@ module RSpec
679
672
  #
680
673
  # @note This is also available using the `=~` operator with `should`,
681
674
  # but `=~` is not supported with `expect`.
682
- # @note There is no should_not version of array.should =~ other_array
675
+ #
676
+ # @note This matcher only supports positive expectations.
677
+ # expect(..).not_to match_array(other_array) is not supported.
683
678
  #
684
679
  # @example
685
680
  #
686
681
  # expect([1,2,3]).to match_array([1,2,3])
687
682
  # 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
683
  def match_array(array)
694
684
  BuiltIn::MatchArray.new(array)
695
685
  end