rspec-expectations 3.1.2 → 3.2.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +45 -0
- data/README.md +17 -6
- data/lib/rspec/expectations.rb +2 -1
- data/lib/rspec/expectations/configuration.rb +1 -1
- data/lib/rspec/expectations/fail_with.rb +1 -2
- data/lib/rspec/expectations/handler.rb +13 -10
- data/lib/rspec/expectations/minitest_integration.rb +1 -0
- data/lib/rspec/expectations/syntax.rb +1 -1
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +37 -49
- data/lib/rspec/matchers/built_in.rb +2 -2
- data/lib/rspec/matchers/built_in/be.rb +6 -10
- data/lib/rspec/matchers/built_in/compound.rb +38 -3
- data/lib/rspec/matchers/built_in/have_attributes.rb +34 -5
- data/lib/rspec/matchers/built_in/include.rb +3 -3
- data/lib/rspec/matchers/built_in/output.rb +41 -0
- data/lib/rspec/matchers/built_in/{start_and_end_with.rb → start_or_end_with.rb} +17 -7
- data/lib/rspec/matchers/built_in/yield.rb +8 -12
- data/lib/rspec/matchers/dsl.rb +56 -7
- data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +79 -0
- data/lib/rspec/matchers/matcher_protocol.rb +66 -66
- metadata +41 -28
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a17c12beef7f8a1e2fa131987dbd3f487b9df046
|
4
|
+
data.tar.gz: 0854aa31f5d41a21d11f7cb33feccb38f19f76f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7952e648e91578f32c772b5f1d4679e06bbec42483a84b15c9e96828f4246a43f7e96a63d4bb7a50c0f809c6aa03a6df3a7439cc0815130518165b4e18cd2193
|
7
|
+
data.tar.gz: 50ca10401b8ead80b338c126b132381fd70df460c52a6d7df426f19020ac2fc5e423d7636456855099122be84df1e396a0a024e27849f8ac959becf7e82c29ba
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,3 +1,48 @@
|
|
1
|
+
### 3.2.0 / 2015-02-03
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.1.2...v3.2.0)
|
3
|
+
|
4
|
+
Enhancements:
|
5
|
+
|
6
|
+
* Add `block_arg` method to custom matcher API, which allows you to
|
7
|
+
access the block passed to a custom matcher, if there is one.
|
8
|
+
(Mike Dalton, #645)
|
9
|
+
* Provide more detail in failure message of `yield_control` matcher.
|
10
|
+
(Jon Rowe, #650)
|
11
|
+
* Add a shorthand syntax for `chain` in the matcher DSL which assigns values
|
12
|
+
for use elsewhere, for example `chain :and_smaller_than, :small_value`
|
13
|
+
creates an `attr_reader` for `small_value` (Tom Stuart, #644)
|
14
|
+
* Provide a more helpful deprecation message when using the `should` syntax.
|
15
|
+
(Elia Schito, #663)
|
16
|
+
* Provide more detail in the `have_attributes` matcher failure message.
|
17
|
+
(Jon Rowe, #668)
|
18
|
+
* Make the `have_attributes` matcher diffable.
|
19
|
+
(Jon Rowe, Alexey Fedorov, #668)
|
20
|
+
* Add `output(...).to_std(out|err)_from_any_process` as alternatives
|
21
|
+
to `output(...).to_std(out|err)`. The latter doesn't work when a sub
|
22
|
+
process writes to the named stream but is much faster.
|
23
|
+
(Alex Genco, #700)
|
24
|
+
* Improve compound matchers (created by `and` and `or`) so that diffs
|
25
|
+
are included in failures when one or more of their matchers
|
26
|
+
are diffable. (Alexey Fedorov, #713)
|
27
|
+
|
28
|
+
Bug Fixes:
|
29
|
+
|
30
|
+
* Avoid calling `private_methods` from the `be` predicate matcher on
|
31
|
+
the target object if the object publicly responds to the predicate
|
32
|
+
method. This avoids a possible error that can occur if the object
|
33
|
+
raises errors from `private_methods` (which can happen with celluloid
|
34
|
+
objects). (@chapmajs, #670)
|
35
|
+
* Make `yield_control` (with no modifier) default to
|
36
|
+
`at_least(:once)` rather than raising a confusing error
|
37
|
+
when multiple yields are encountered.
|
38
|
+
(Myron Marston, #675)
|
39
|
+
* Fix "instance variable @color not initialized" warning when using
|
40
|
+
rspec-expectations outside of an rspec-core context. (Myron Marston, #689)
|
41
|
+
* Fix `start_with` and `end_with` to work properly when checking a
|
42
|
+
string against an array of strings. (Myron Marston, #690)
|
43
|
+
* Don't use internally delegated matchers when generating descriptions
|
44
|
+
for examples without doc strings. (Myron Marston, #692)
|
45
|
+
|
1
46
|
### 3.1.2 / 2014-09-26
|
2
47
|
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.1.1...v3.1.2)
|
3
48
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RSpec Expectations [](http://travis-ci.org/rspec/rspec-expectations) [](https://codeclimate.com/github/rspec/rspec-expectations)
|
2
2
|
|
3
3
|
RSpec::Expectations lets you express expected outcomes on an object in an
|
4
4
|
example.
|
@@ -13,6 +13,15 @@ rspec-core and rspec-mocks):
|
|
13
13
|
|
14
14
|
gem install rspec
|
15
15
|
|
16
|
+
Want to run against the `master` branch? You'll need to include the dependent
|
17
|
+
RSpec repos as well. Add the following to your `Gemfile`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
%w[rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
21
|
+
gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => 'master'
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
16
25
|
If you want to use rspec-expectations with another tool, like Test::Unit,
|
17
26
|
Minitest, or Cucumber, you can install it directly:
|
18
27
|
|
@@ -52,6 +61,7 @@ the example passes. If not, it fails with a message like:
|
|
52
61
|
```ruby
|
53
62
|
expect(actual).to eq(expected) # passes if actual == expected
|
54
63
|
expect(actual).to eql(expected) # passes if actual.eql?(expected)
|
64
|
+
expect(actual).not_to eql(not_expected) # passes if not(actual.eql?(expected))
|
55
65
|
```
|
56
66
|
|
57
67
|
Note: The new `expect` syntax no longer supports the `==` matcher.
|
@@ -93,11 +103,12 @@ expect(actual).to be_a_kind_of(expected) # another alias
|
|
93
103
|
### Truthiness
|
94
104
|
|
95
105
|
```ruby
|
96
|
-
expect(actual).to be_truthy
|
97
|
-
expect(actual).to be true
|
98
|
-
expect(actual).to be_falsy
|
99
|
-
expect(actual).to be false
|
100
|
-
expect(actual).to be_nil
|
106
|
+
expect(actual).to be_truthy # passes if actual is truthy (not nil or false)
|
107
|
+
expect(actual).to be true # passes if actual == true
|
108
|
+
expect(actual).to be_falsy # passes if actual is falsy (nil or false)
|
109
|
+
expect(actual).to be false # passes if actual == false
|
110
|
+
expect(actual).to be_nil # passes if actual is nil
|
111
|
+
expect(actual).to_not be_nil # passes if actual is not nil
|
101
112
|
```
|
102
113
|
|
103
114
|
### Expecting errors
|
data/lib/rspec/expectations.rb
CHANGED
@@ -24,8 +24,7 @@ module RSpec
|
|
24
24
|
"appropriate failure_message[_when_negated] method to return a string?"
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
message = "#{message}\nDiff:#{diff}" unless diff.empty?
|
27
|
+
message = ::RSpec::Matchers::ExpectedsForMultipleDiffs.from(expected).message_with_diff(message, differ, actual)
|
29
28
|
|
30
29
|
raise RSpec::Expectations::ExpectationNotMetError, message
|
31
30
|
end
|
@@ -21,10 +21,13 @@ module RSpec
|
|
21
21
|
LegacyMatcherAdapter::RSpec1.wrap(matcher) || matcher
|
22
22
|
end
|
23
23
|
|
24
|
-
def self.
|
24
|
+
def self.with_matcher(handler, matcher, message)
|
25
25
|
check_message(message)
|
26
|
+
matcher = modern_matcher_from(matcher)
|
27
|
+
yield matcher
|
28
|
+
ensure
|
26
29
|
::RSpec::Matchers.last_expectation_handler = handler
|
27
|
-
::RSpec::Matchers.last_matcher =
|
30
|
+
::RSpec::Matchers.last_matcher = matcher
|
28
31
|
end
|
29
32
|
|
30
33
|
def self.handle_failure(matcher, message, failure_message_method)
|
@@ -42,10 +45,10 @@ module RSpec
|
|
42
45
|
# @private
|
43
46
|
class PositiveExpectationHandler
|
44
47
|
def self.handle_matcher(actual, initial_matcher, message=nil, &block)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
ExpectationHelper.with_matcher(self, initial_matcher, message) do |matcher|
|
49
|
+
return ::RSpec::Matchers::BuiltIn::PositiveOperatorMatcher.new(actual) unless initial_matcher
|
50
|
+
matcher.matches?(actual, &block) || ExpectationHelper.handle_failure(matcher, message, :failure_message)
|
51
|
+
end
|
49
52
|
end
|
50
53
|
|
51
54
|
def self.verb
|
@@ -64,10 +67,10 @@ module RSpec
|
|
64
67
|
# @private
|
65
68
|
class NegativeExpectationHandler
|
66
69
|
def self.handle_matcher(actual, initial_matcher, message=nil, &block)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
70
|
+
ExpectationHelper.with_matcher(self, initial_matcher, message) do |matcher|
|
71
|
+
return ::RSpec::Matchers::BuiltIn::NegativeOperatorMatcher.new(actual) unless initial_matcher
|
72
|
+
!(does_not_match?(matcher, actual, &block) || ExpectationHelper.handle_failure(matcher, message, :failure_message_when_negated))
|
73
|
+
end
|
71
74
|
end
|
72
75
|
|
73
76
|
def self.does_not_match?(matcher, actual, &block)
|
@@ -27,7 +27,7 @@ module RSpec
|
|
27
27
|
|
28
28
|
RSpec.deprecate(
|
29
29
|
"Using `#{method_name}` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax",
|
30
|
-
:replacement => "the new `:expect` syntax or explicitly enable `:should`"
|
30
|
+
:replacement => "the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }`"
|
31
31
|
)
|
32
32
|
|
33
33
|
@warn_about_should = false
|
data/lib/rspec/matchers.rb
CHANGED
@@ -10,6 +10,7 @@ RSpec::Support.define_optimized_require_for_rspec(:matchers) { |f| require_relat
|
|
10
10
|
dsl
|
11
11
|
matcher_delegator
|
12
12
|
aliased_matcher
|
13
|
+
expecteds_for_multiple_diffs
|
13
14
|
].each { |file| RSpec::Support.require_rspec_matchers(file) }
|
14
15
|
|
15
16
|
# RSpec's top level namespace. All of rspec-expectations is contained
|
@@ -220,19 +221,16 @@ module RSpec
|
|
220
221
|
# @param old_name [Symbol] the original name for the matcher
|
221
222
|
# @param options [Hash] options for the aliased matcher
|
222
223
|
# @option options [Class] :klass the ruby class to use as the decorator. (Not normally used).
|
223
|
-
# @yield [String] optional block that, when given is used to define the overriden
|
224
|
-
#
|
225
|
-
# provided, a default
|
226
|
-
# new names.
|
224
|
+
# @yield [String] optional block that, when given, is used to define the overriden
|
225
|
+
# logic. The yielded arg is the original description or failure message. If no
|
226
|
+
# block is provided, a default override is used based on the old and new names.
|
227
227
|
#
|
228
228
|
# @example
|
229
|
-
#
|
230
229
|
# RSpec::Matchers.alias_matcher :a_list_that_sums_to, :sum_to
|
231
230
|
# sum_to(3).description # => "sum to 3"
|
232
231
|
# a_list_that_sums_to(3).description # => "a list that sums to 3"
|
233
232
|
#
|
234
233
|
# @example
|
235
|
-
#
|
236
234
|
# RSpec::Matchers.alias_matcher :a_list_sorted_by, :be_sorted_by do |description|
|
237
235
|
# description.sub("be sorted by", "a list sorted by")
|
238
236
|
# end
|
@@ -261,16 +259,20 @@ module RSpec
|
|
261
259
|
#
|
262
260
|
# @param negated_name [Symbol] the name for the negated matcher
|
263
261
|
# @param base_name [Symbol] the name of the original matcher that will be negated
|
264
|
-
# @yield [String] optional block that, when given is used to define the overriden
|
265
|
-
#
|
266
|
-
# provided, a default
|
267
|
-
# new names.
|
262
|
+
# @yield [String] optional block that, when given, is used to define the overriden
|
263
|
+
# logic. The yielded arg is the original description or failure message. If no
|
264
|
+
# block is provided, a default override is used based on the old and new names.
|
268
265
|
#
|
269
266
|
# @example
|
267
|
+
# RSpec::Matchers.define_negated_matcher :exclude, :include
|
268
|
+
# include(1, 2).description # => "include 1 and 2"
|
269
|
+
# exclude(1, 2).description # => "exclude 1 and 2"
|
270
270
|
#
|
271
|
-
#
|
272
|
-
#
|
273
|
-
#
|
271
|
+
# @note While the most obvious negated form may be to add a `not_` prefix,
|
272
|
+
# the failure messages you get with that form can be confusing (e.g.
|
273
|
+
# "expected [actual] to not [verb], but did not"). We've found it works
|
274
|
+
# best to find a more positive name for the negated form, such as
|
275
|
+
# `avoid_changing` rather than `not_change`.
|
274
276
|
def self.define_negated_matcher(negated_name, base_name, &description_override)
|
275
277
|
alias_matcher(negated_name, base_name, :klass => AliasedNegatedMatcher, &description_override)
|
276
278
|
end
|
@@ -329,7 +331,6 @@ module RSpec
|
|
329
331
|
# Passes if actual.instance_of?(expected)
|
330
332
|
#
|
331
333
|
# @example
|
332
|
-
#
|
333
334
|
# expect(5).to be_an_instance_of(Fixnum)
|
334
335
|
# expect(5).not_to be_an_instance_of(Numeric)
|
335
336
|
# expect(5).not_to be_an_instance_of(Float)
|
@@ -342,7 +343,6 @@ module RSpec
|
|
342
343
|
# Passes if actual.kind_of?(expected)
|
343
344
|
#
|
344
345
|
# @example
|
345
|
-
#
|
346
346
|
# expect(5).to be_a_kind_of(Fixnum)
|
347
347
|
# expect(5).to be_a_kind_of(Numeric)
|
348
348
|
# expect(5).not_to be_a_kind_of(Float)
|
@@ -360,7 +360,6 @@ module RSpec
|
|
360
360
|
# but you can make it `exclusive` by chaining that off the matcher.
|
361
361
|
#
|
362
362
|
# @example
|
363
|
-
#
|
364
363
|
# expect(5).to be_between(1, 10)
|
365
364
|
# expect(11).not_to be_between(1, 10)
|
366
365
|
# expect(10).not_to be_between(1, 10).exclusive
|
@@ -372,7 +371,6 @@ module RSpec
|
|
372
371
|
# Passes if actual == expected +/- delta
|
373
372
|
#
|
374
373
|
# @example
|
375
|
-
#
|
376
374
|
# expect(result).to be_within(0.5).of(3.0)
|
377
375
|
# expect(result).not_to be_within(0.5).of(3.0)
|
378
376
|
def be_within(delta)
|
@@ -407,7 +405,6 @@ module RSpec
|
|
407
405
|
# * `by_at_most`
|
408
406
|
#
|
409
407
|
# @example
|
410
|
-
#
|
411
408
|
# expect {
|
412
409
|
# team.add_player(player)
|
413
410
|
# }.to change(roster, :count)
|
@@ -474,7 +471,6 @@ module RSpec
|
|
474
471
|
# but `=~` is not supported with `expect`.
|
475
472
|
#
|
476
473
|
# @example
|
477
|
-
#
|
478
474
|
# expect([1, 2, 3]).to contain_exactly(1, 2, 3)
|
479
475
|
# expect([1, 2, 3]).to contain_exactly(1, 3, 2)
|
480
476
|
#
|
@@ -509,7 +505,6 @@ module RSpec
|
|
509
505
|
# `expected.length` elements of the actual array.
|
510
506
|
#
|
511
507
|
# @example
|
512
|
-
#
|
513
508
|
# expect("this string").to end_with "string"
|
514
509
|
# expect([0, 1, 2, 3, 4]).to end_with 4
|
515
510
|
# expect([0, 2, 3, 4, 4]).to end_with 3, 4
|
@@ -526,7 +521,6 @@ module RSpec
|
|
526
521
|
# information about equality in Ruby.
|
527
522
|
#
|
528
523
|
# @example
|
529
|
-
#
|
530
524
|
# expect(5).to eq(5)
|
531
525
|
# expect(5).not_to eq(3)
|
532
526
|
def eq(expected)
|
@@ -541,7 +535,6 @@ module RSpec
|
|
541
535
|
# information about equality in Ruby.
|
542
536
|
#
|
543
537
|
# @example
|
544
|
-
#
|
545
538
|
# expect(5).to eql(5)
|
546
539
|
# expect(5).not_to eql(3)
|
547
540
|
def eql(expected)
|
@@ -556,7 +549,6 @@ module RSpec
|
|
556
549
|
# information about equality in Ruby.
|
557
550
|
#
|
558
551
|
# @example
|
559
|
-
#
|
560
552
|
# expect(5).to equal(5) # Fixnums are equal
|
561
553
|
# expect("5").not_to equal("5") # Strings that look the same are not the same object
|
562
554
|
def equal(expected)
|
@@ -579,7 +571,6 @@ module RSpec
|
|
579
571
|
# This works no matter how you define your attribute readers.
|
580
572
|
#
|
581
573
|
# @example
|
582
|
-
#
|
583
574
|
# Person = Struct.new(:name, :age)
|
584
575
|
# person = Person.new("Bob", 32)
|
585
576
|
#
|
@@ -589,7 +580,6 @@ module RSpec
|
|
589
580
|
# @note It will fail if actual doesn't respond to any of the expected attributes.
|
590
581
|
#
|
591
582
|
# @example
|
592
|
-
#
|
593
583
|
# expect(person).to have_attributes(:color => "red")
|
594
584
|
def have_attributes(expected)
|
595
585
|
BuiltIn::HaveAttributes.new(expected)
|
@@ -601,13 +591,18 @@ module RSpec
|
|
601
591
|
# and it will only pass if all args are found in collection.
|
602
592
|
#
|
603
593
|
# @example
|
604
|
-
#
|
605
594
|
# expect([1,2,3]).to include(3)
|
606
595
|
# expect([1,2,3]).to include(2,3)
|
607
596
|
# expect([1,2,3]).to include(2,3,4) # fails
|
608
597
|
# expect([1,2,3]).not_to include(4)
|
609
598
|
# expect("spread").to include("read")
|
610
599
|
# expect("spread").not_to include("red")
|
600
|
+
# expect(:a => 1, :b => 2).to include(:a)
|
601
|
+
# expect(:a => 1, :b => 2).to include(:a, :b)
|
602
|
+
# expect(:a => 1, :b => 2).to include(:a => 1)
|
603
|
+
# expect(:a => 1, :b => 2).to include(:b => 2, :a => 1)
|
604
|
+
# expect(:a => 1, :b => 2).to include(:c) # fails
|
605
|
+
# expect(:a => 1, :b => 2).not_to include(:a => 2)
|
611
606
|
def include(*expected)
|
612
607
|
BuiltIn::Include.new(*expected)
|
613
608
|
end
|
@@ -616,11 +611,10 @@ module RSpec
|
|
616
611
|
alias_matcher :a_hash_including, :include
|
617
612
|
alias_matcher :including, :include
|
618
613
|
|
619
|
-
# Passes if
|
620
|
-
#
|
614
|
+
# Passes if the provided matcher passes when checked against all
|
615
|
+
# elements of the collection.
|
621
616
|
#
|
622
617
|
# @example
|
623
|
-
#
|
624
618
|
# expect([1, 3, 5]).to all be_odd
|
625
619
|
# expect([1, 3, 6]).to all be_odd # fails
|
626
620
|
#
|
@@ -642,12 +636,10 @@ module RSpec
|
|
642
636
|
# pair of elements.
|
643
637
|
#
|
644
638
|
# @example
|
645
|
-
#
|
646
639
|
# expect(email).to match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
|
647
640
|
# expect(email).to match("@example.com")
|
648
641
|
#
|
649
642
|
# @example
|
650
|
-
#
|
651
643
|
# hash = {
|
652
644
|
# :a => {
|
653
645
|
# :b => ["foo", 5],
|
@@ -682,7 +674,6 @@ module RSpec
|
|
682
674
|
# that splatted out as individual items.
|
683
675
|
#
|
684
676
|
# @example
|
685
|
-
#
|
686
677
|
# expect(results).to contain_exactly(1, 2)
|
687
678
|
# # is identical to:
|
688
679
|
# expect(results).to match_array([1, 2])
|
@@ -693,11 +684,14 @@ module RSpec
|
|
693
684
|
end
|
694
685
|
|
695
686
|
# With no arg, passes if the block outputs `to_stdout` or `to_stderr`.
|
696
|
-
# With a string, passes if the
|
697
|
-
# With a regexp or matcher, passes if the
|
687
|
+
# With a string, passes if the block outputs that specific string `to_stdout` or `to_stderr`.
|
688
|
+
# With a regexp or matcher, passes if the block outputs a string `to_stdout` or `to_stderr` that matches.
|
698
689
|
#
|
699
|
-
#
|
690
|
+
# To capture output from any spawned subprocess as well, use `to_stdout_from_any_process` or
|
691
|
+
# `to_stderr_from_any_process`. Output from any process that inherits the main process's corresponding
|
692
|
+
# standard stream will be captured.
|
700
693
|
#
|
694
|
+
# @example
|
701
695
|
# expect { print 'foo' }.to output.to_stdout
|
702
696
|
# expect { print 'foo' }.to output('foo').to_stdout
|
703
697
|
# expect { print 'foo' }.to output(/foo/).to_stdout
|
@@ -710,10 +704,15 @@ module RSpec
|
|
710
704
|
#
|
711
705
|
# expect { do_something }.to_not output.to_stderr
|
712
706
|
#
|
713
|
-
#
|
714
|
-
#
|
707
|
+
# expect { system('echo foo') }.to output("foo\n").to_stdout_from_any_process
|
708
|
+
# expect { system('echo foo', out: :err) }.to output("foo\n").to_stderr_from_any_process
|
709
|
+
#
|
710
|
+
# @note `to_stdout` and `to_stderr` work by temporarily replacing `$stdout` or `$stderr`,
|
711
|
+
# so they're not able to intercept stream output that explicitly uses `STDOUT`/`STDERR`
|
715
712
|
# or that uses a reference to `$stdout`/`$stderr` that was stored before the
|
716
|
-
# matcher
|
713
|
+
# matcher was used.
|
714
|
+
# @note `to_stdout_from_any_process` and `to_stderr_from_any_process` use Tempfiles, and
|
715
|
+
# are thus significantly (~30x) slower than `to_stdout` and `to_stderr`.
|
717
716
|
def output(expected=nil)
|
718
717
|
BuiltIn::Output.new(expected)
|
719
718
|
end
|
@@ -726,7 +725,6 @@ module RSpec
|
|
726
725
|
# Pass an optional block to perform extra verifications on the exception matched
|
727
726
|
#
|
728
727
|
# @example
|
729
|
-
#
|
730
728
|
# expect { do_something_risky }.to raise_error
|
731
729
|
# expect { do_something_risky }.to raise_error(PoorRiskDecisionError)
|
732
730
|
# expect { do_something_risky }.to raise_error(PoorRiskDecisionError) { |error| expect(error.data).to eq 42 }
|
@@ -751,7 +749,6 @@ module RSpec
|
|
751
749
|
# provided. Names can be Strings or Symbols.
|
752
750
|
#
|
753
751
|
# @example
|
754
|
-
#
|
755
752
|
# expect("string").to respond_to(:length)
|
756
753
|
#
|
757
754
|
def respond_to(*names)
|
@@ -771,7 +768,6 @@ module RSpec
|
|
771
768
|
# a custom matcher, which would likely make your specs more expressive.
|
772
769
|
#
|
773
770
|
# @example
|
774
|
-
#
|
775
771
|
# expect(5).to satisfy { |n| n > 3 }
|
776
772
|
def satisfy(&block)
|
777
773
|
BuiltIn::Satisfy.new(&block)
|
@@ -785,7 +781,6 @@ module RSpec
|
|
785
781
|
# `expected.length` elements of the actual array.
|
786
782
|
#
|
787
783
|
# @example
|
788
|
-
#
|
789
784
|
# expect("this string").to start_with "this s"
|
790
785
|
# expect([0, 1, 2, 3, 4]).to start_with 0
|
791
786
|
# expect([0, 2, 3, 4, 4]).to start_with 0, 1
|
@@ -804,7 +799,6 @@ module RSpec
|
|
804
799
|
# specified Symbol with the specified arg.
|
805
800
|
#
|
806
801
|
# @example
|
807
|
-
#
|
808
802
|
# expect { do_something_risky }.to throw_symbol
|
809
803
|
# expect { do_something_risky }.to throw_symbol(:that_was_risky)
|
810
804
|
# expect { do_something_risky }.to throw_symbol(:that_was_risky, 'culprit')
|
@@ -828,14 +822,11 @@ module RSpec
|
|
828
822
|
# of whether or not arguments are yielded.
|
829
823
|
#
|
830
824
|
# @example
|
831
|
-
#
|
832
825
|
# expect { |b| 5.tap(&b) }.to yield_control
|
833
826
|
# expect { |b| "a".to_sym(&b) }.not_to yield_control
|
834
827
|
#
|
835
828
|
# @note Your expect block must accept a parameter and pass it on to
|
836
829
|
# the method-under-test as a block.
|
837
|
-
# @note This matcher is not designed for use with methods that yield
|
838
|
-
# multiple times.
|
839
830
|
def yield_control
|
840
831
|
BuiltIn::YieldControl.new
|
841
832
|
end
|
@@ -846,7 +837,6 @@ module RSpec
|
|
846
837
|
# no arguments. Fails if it does not yield, or yields with arguments.
|
847
838
|
#
|
848
839
|
# @example
|
849
|
-
#
|
850
840
|
# expect { |b| User.transaction(&b) }.to yield_with_no_args
|
851
841
|
# expect { |b| 5.tap(&b) }.not_to yield_with_no_args # because it yields with `5`
|
852
842
|
# expect { |b| "a".to_sym(&b) }.not_to yield_with_no_args # because it does not yield
|
@@ -873,7 +863,6 @@ module RSpec
|
|
873
863
|
# operator, the matcher will pass.
|
874
864
|
#
|
875
865
|
# @example
|
876
|
-
#
|
877
866
|
# expect { |b| 5.tap(&b) }.to yield_with_args # because #tap yields an arg
|
878
867
|
# expect { |b| 5.tap(&b) }.to yield_with_args(5) # because 5 == 5
|
879
868
|
# expect { |b| 5.tap(&b) }.to yield_with_args(Fixnum) # because Fixnum === 5
|
@@ -901,7 +890,6 @@ module RSpec
|
|
901
890
|
# operator, the matcher will pass.
|
902
891
|
#
|
903
892
|
# @example
|
904
|
-
#
|
905
893
|
# expect { |b| [1, 2, 3].each(&b) }.to yield_successive_args(1, 2, 3)
|
906
894
|
# expect { |b| { :a => 1, :b => 2 }.each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
|
907
895
|
# expect { |b| [1, 2, 3].each(&b) }.not_to yield_successive_args(1, 2)
|