sspec-support 3.8.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 +7 -0
- data/Changelog.md +242 -0
- data/LICENSE.md +23 -0
- data/README.md +40 -0
- data/lib/rspec/support.rb +149 -0
- data/lib/rspec/support/caller_filter.rb +83 -0
- data/lib/rspec/support/comparable_version.rb +46 -0
- data/lib/rspec/support/differ.rb +215 -0
- data/lib/rspec/support/directory_maker.rb +63 -0
- data/lib/rspec/support/encoded_string.rb +165 -0
- data/lib/rspec/support/fuzzy_matcher.rb +48 -0
- data/lib/rspec/support/hunk_generator.rb +47 -0
- data/lib/rspec/support/matcher_definition.rb +42 -0
- data/lib/rspec/support/method_signature_verifier.rb +426 -0
- data/lib/rspec/support/mutex.rb +73 -0
- data/lib/rspec/support/object_formatter.rb +275 -0
- data/lib/rspec/support/recursive_const_methods.rb +76 -0
- data/lib/rspec/support/reentrant_mutex.rb +53 -0
- data/lib/rspec/support/ruby_features.rb +176 -0
- data/lib/rspec/support/source.rb +75 -0
- data/lib/rspec/support/source/location.rb +21 -0
- data/lib/rspec/support/source/node.rb +110 -0
- data/lib/rspec/support/source/token.rb +87 -0
- data/lib/rspec/support/spec.rb +81 -0
- data/lib/rspec/support/spec/deprecation_helpers.rb +64 -0
- data/lib/rspec/support/spec/formatting_support.rb +9 -0
- data/lib/rspec/support/spec/in_sub_process.rb +69 -0
- data/lib/rspec/support/spec/library_wide_checks.rb +150 -0
- data/lib/rspec/support/spec/shell_out.rb +84 -0
- data/lib/rspec/support/spec/stderr_splitter.rb +63 -0
- data/lib/rspec/support/spec/string_matcher.rb +46 -0
- data/lib/rspec/support/spec/with_isolated_directory.rb +13 -0
- data/lib/rspec/support/spec/with_isolated_stderr.rb +13 -0
- data/lib/rspec/support/version.rb +7 -0
- data/lib/rspec/support/warnings.rb +39 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0f173734cc4075a1d6d5915625d44b635087b0bb763ba0f95b0f955969b8c4ec
|
4
|
+
data.tar.gz: 5dabc4a30e098c128d61538937bd833150f1b34c2e5c9b64291008f32b956efd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26a15e8f82365c1e80a00ad1e90b55246d51ce10dc89e76414fdcbdf457b4c09309a16f939ef013ca48752c78f96a5cdb5e7b2e561ff64af17d98b2de279732b
|
7
|
+
data.tar.gz: a4a33af04219e97d032ced83017812991bb013b1470f04599f38569f6ddf0abcebc9ad9c230f616792fb65c2fdbfcadbecec61a1f89cbcfd0db7d5905cfbad7a
|
data/Changelog.md
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
### 3.8.0 / 2018-08-04
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.7.1...v3.8.0)
|
3
|
+
|
4
|
+
Bug Fixes:
|
5
|
+
|
6
|
+
* Order hash keys before diffing to improve diff accuracy when using mocked calls.
|
7
|
+
(James Crisp, #334)
|
8
|
+
|
9
|
+
### 3.7.1 / 2018-01-29
|
10
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.7.0...v3.7.1)
|
11
|
+
|
12
|
+
Bug Fixes:
|
13
|
+
|
14
|
+
* Fix source extraction logic so that it does not trigger a `SystemStackError`
|
15
|
+
when processing deeply nested example groups. (Craig Bass, #343)
|
16
|
+
|
17
|
+
### 3.7.0 / 2017-10-17
|
18
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.6.0...v3.7.0)
|
19
|
+
|
20
|
+
Enhancements:
|
21
|
+
|
22
|
+
* Improve compatibility with `--enable-frozen-string-literal` option
|
23
|
+
on Ruby 2.3+. (Pat Allan, #320)
|
24
|
+
* Add `Support.class_of` for extracting class of any object.
|
25
|
+
(Yuji Nakayama, #325)
|
26
|
+
|
27
|
+
Bug Fixes:
|
28
|
+
|
29
|
+
* Fix recursive const support to not blow up when given buggy classes
|
30
|
+
that raise odd errors from `#to_str`. (Myron Marston, #317)
|
31
|
+
|
32
|
+
### 3.6.0 / 2017-05-04
|
33
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.6.0.beta2...3.6.0)
|
34
|
+
|
35
|
+
Enhancements:
|
36
|
+
|
37
|
+
* Import `Source` classes from rspec-core. (Yuji Nakayama, #315)
|
38
|
+
|
39
|
+
### 3.6.0.beta2 / 2016-12-12
|
40
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.6.0.beta1...v3.6.0.beta2)
|
41
|
+
|
42
|
+
No user-facing changes.
|
43
|
+
|
44
|
+
### 3.6.0.beta1 / 2016-10-09
|
45
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0...v3.6.0.beta1)
|
46
|
+
|
47
|
+
Bug Fixes:
|
48
|
+
|
49
|
+
* Prevent truncated formatted object output from mangling console codes. (#294, Anson Kelly)
|
50
|
+
|
51
|
+
### 3.5.0 / 2016-07-01
|
52
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0.beta4...v3.5.0)
|
53
|
+
|
54
|
+
**No user facing changes since beta4**
|
55
|
+
|
56
|
+
### 3.5.0.beta4 / 2016-06-05
|
57
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0.beta3...v3.5.0.beta4)
|
58
|
+
|
59
|
+
Enhancements:
|
60
|
+
* Improve `MethodSignature` to better support keyword arguments. (#250, Rob Smith).
|
61
|
+
|
62
|
+
### 3.5.0.beta3 / 2016-04-02
|
63
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0.beta2...v3.5.0.beta3)
|
64
|
+
|
65
|
+
Bug Fixes:
|
66
|
+
|
67
|
+
* Fix `EncodedString` to properly handle the behavior of `String#split`
|
68
|
+
on JRuby when the string contains invalid bytes. (Jon Rowe, #268)
|
69
|
+
* Fix `ObjectFormatter` so that formatting objects that don't respond to
|
70
|
+
`#inspect` (such as `BasicObject`) does not cause `NoMethodError`.
|
71
|
+
(Yuji Nakayama, #269)
|
72
|
+
* Fix `ObjectFormatter` so that formatting recursive array or hash does not
|
73
|
+
cause `SystemStackError`. (Yuji Nakayama, #270, #272)
|
74
|
+
|
75
|
+
### 3.5.0.beta2 / 2016-03-10
|
76
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0.beta1...v3.5.0.beta2)
|
77
|
+
|
78
|
+
No user-facing changes.
|
79
|
+
|
80
|
+
### 3.5.0.beta1 / 2016-02-06
|
81
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.4.1...v3.5.0.beta1)
|
82
|
+
|
83
|
+
Enhancements:
|
84
|
+
|
85
|
+
* Improve formatting of objects by allowing truncation to a pre-configured length.
|
86
|
+
(Liam M, #256)
|
87
|
+
|
88
|
+
### 3.4.1 / 2015-11-20
|
89
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.4.0...v3.4.1)
|
90
|
+
|
91
|
+
Bug Fixes:
|
92
|
+
|
93
|
+
* Fix `RSpec::Support::RubyFeature.ripper_supported?` so it returns
|
94
|
+
`false` on Rubinius since the Rubinius team has no plans to support
|
95
|
+
it. This prevents rspec-core from trying to load and use ripper to
|
96
|
+
extract failure snippets. (Aaron Stone, #251)
|
97
|
+
|
98
|
+
Changes:
|
99
|
+
|
100
|
+
* Remove `VersionChecker` in favor of `ComparableVersion`. (Yuji Nakayama, #266)
|
101
|
+
|
102
|
+
### 3.4.0 / 2015-11-11
|
103
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.3.0...v3.4.0)
|
104
|
+
|
105
|
+
Enhancements:
|
106
|
+
|
107
|
+
* Improve formatting of `Delegator` based objects (e.g. `SimpleDelgator`) in
|
108
|
+
failure messages and diffs. (Andrew Horner, #215)
|
109
|
+
* Add `ComparableVersion`. (Yuji Nakayama, #245)
|
110
|
+
* Add `Ripper` support detection. (Yuji Nakayama, #245)
|
111
|
+
|
112
|
+
Bug Fixes:
|
113
|
+
|
114
|
+
* Work around bug in JRuby that reports that `attr_writer` methods
|
115
|
+
have no parameters, causing RSpec's verifying doubles to wrongly
|
116
|
+
fail when mocking or stubbing a writer method on JRuby. (Myron Marston, #225)
|
117
|
+
|
118
|
+
### 3.3.0 / 2015-06-12
|
119
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.2.2...v3.3.0)
|
120
|
+
|
121
|
+
Enhancements:
|
122
|
+
|
123
|
+
* Improve formatting of arrays and hashes in failure messages so they
|
124
|
+
use our custom formatting of matchers, time objects, etc.
|
125
|
+
(Myron Marston, Nicholas Chmielewski, #205)
|
126
|
+
* Use improved formatting for diffs as well. (Nicholas Chmielewski, #205)
|
127
|
+
|
128
|
+
Bug Fixes:
|
129
|
+
|
130
|
+
* Fix `FuzzyMatcher` so that it checks `expected == actual` rather than
|
131
|
+
`actual == expected`, which avoids errors in situations where the
|
132
|
+
`actual` object's `==` is improperly implemented to assume that only
|
133
|
+
objects of the same type will be given. This allows rspec-mocks'
|
134
|
+
`anything` to match against objects with buggy `==` definitions.
|
135
|
+
(Myron Marston, #193)
|
136
|
+
|
137
|
+
### 3.2.2 / 2015-02-23
|
138
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.2.1...v3.2.2)
|
139
|
+
|
140
|
+
Bug Fixes:
|
141
|
+
|
142
|
+
* Fix an encoding issue with `EncodedString#split` when encountering an
|
143
|
+
invalid byte string. (Benjamin Fleischer, #1760)
|
144
|
+
|
145
|
+
### 3.2.1 / 2015-02-04
|
146
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.2.0...v3.2.1)
|
147
|
+
|
148
|
+
Bug Fixes:
|
149
|
+
|
150
|
+
* Fix `RSpec::CallerFilter` to work on Rubinius 2.2.
|
151
|
+
(Myron Marston, #169)
|
152
|
+
|
153
|
+
### 3.2.0 / 2015-02-03
|
154
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.1.2...v3.2.0)
|
155
|
+
|
156
|
+
Enhancements:
|
157
|
+
|
158
|
+
* Add extra Ruby type detection. (Jon Rowe, #133)
|
159
|
+
* Make differ instance re-usable. (Alexey Fedorov, #160)
|
160
|
+
|
161
|
+
Bug Fixes:
|
162
|
+
|
163
|
+
* Do not consider `[]` and `{}` to match when performing fuzzy matching.
|
164
|
+
(Myron Marston, #157)
|
165
|
+
|
166
|
+
### 3.1.2 / 2014-10-08
|
167
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.1.1...v3.1.2)
|
168
|
+
|
169
|
+
Bug Fixes:
|
170
|
+
|
171
|
+
* Fix method signature to not blow up with a `NoMethodError` on 1.8.7 when
|
172
|
+
verifying against an RSpec matcher. (Myron Marston, #116)
|
173
|
+
|
174
|
+
### 3.1.1 / 2014-09-26
|
175
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.1.0...v3.1.1)
|
176
|
+
|
177
|
+
Bug Fixes:
|
178
|
+
|
179
|
+
* Fix `RSpec::Support::DirectoryMaker` (used by `rspec --init` and
|
180
|
+
`rails generate rspec:install`) so that it detects absolute paths
|
181
|
+
on Windows properly. (Scott Archer, #107, #108, #109) (Jon Rowe, #110)
|
182
|
+
|
183
|
+
### 3.1.0 / 2014-09-04
|
184
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.4...v3.1.0)
|
185
|
+
|
186
|
+
Bug Fixes:
|
187
|
+
|
188
|
+
* Fix `FuzzyMatcher` so that it does not wrongly match a struct against
|
189
|
+
an array. (Myron Marston, #97)
|
190
|
+
* Prevent infinitely recursing `#flatten` methods from causing the differ
|
191
|
+
to hang. (Jon Rowe, #101)
|
192
|
+
|
193
|
+
### 3.0.4 / 2014-08-14
|
194
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.3...v3.0.4)
|
195
|
+
|
196
|
+
Bug Fixes:
|
197
|
+
|
198
|
+
* Fix `FuzzyMatcher` so that it does not silence `ArgumentError` raised
|
199
|
+
from broken implementations of `==`. (Myron Marston, #94)
|
200
|
+
|
201
|
+
### 3.0.3 / 2014-07-21
|
202
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.2...v3.0.3)
|
203
|
+
|
204
|
+
Bug Fixes:
|
205
|
+
|
206
|
+
* Fix regression in `Support#method_handle_for` where proxy objects
|
207
|
+
with method delegated would wrongly not return a method handle.
|
208
|
+
(Jon Rowe, #90)
|
209
|
+
* Properly detect Module#prepend support in Ruby 2.1+ (Ben Langfeld, #91)
|
210
|
+
* Fix `rspec/support/warnings.rb` so it can be loaded and used in
|
211
|
+
isolation. (Myron Marston, #93)
|
212
|
+
|
213
|
+
### 3.0.2 / 2014-06-20
|
214
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.1...v3.0.2)
|
215
|
+
|
216
|
+
* Revert `BlockSignature` change from 3.0.1 because of a ruby bug that
|
217
|
+
caused it to change the block's behavior (https://bugs.ruby-lang.org/issues/9967).
|
218
|
+
(Myron Marston, rspec-mocks#721)
|
219
|
+
|
220
|
+
### 3.0.1 / 2014-06-19
|
221
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.0...v3.0.1)
|
222
|
+
|
223
|
+
* Fix `BlockSignature` so that it correctly differentiates between
|
224
|
+
required and optional block args. (Myron Marston, rspec-mocks#714)
|
225
|
+
|
226
|
+
### 3.0.0 / 2014-06-01
|
227
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.0.rc1...v3.0.0)
|
228
|
+
|
229
|
+
### 3.0.0.rc1 / 2014-05-18
|
230
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.0.beta2...v3.0.0.rc1)
|
231
|
+
|
232
|
+
### 3.0.0.beta2 / 2014-02-17
|
233
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.0.beta1...v3.0.0.beta2)
|
234
|
+
|
235
|
+
Bug Fixes:
|
236
|
+
|
237
|
+
* Issue message when :replacement is passed to `RSpec.warn_with`. (Jon Rowe)
|
238
|
+
|
239
|
+
### 3.0.0.beta1 / 2013-11-07
|
240
|
+
[Full Changelog](https://github.com/rspec/rspec-support/compare/0dc12d1bdbbacc757a9989f8c09cd08ef3a4837e...v3.0.0.beta1)
|
241
|
+
|
242
|
+
Initial release.
|
data/LICENSE.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
====================
|
3
|
+
|
4
|
+
* Copyright © 2013 David Chelimsky, Myron Marston, Jon Rowe, Sam Phippen, Xavier Shay, Bradley Schaefer
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# RSpec::Support
|
2
|
+
|
3
|
+
`RSpec::Support` provides common functionality to `RSpec::Core`,
|
4
|
+
`RSpec::Expectations` and `RSpec::Mocks`. It is considered
|
5
|
+
suitable for internal use only at this time.
|
6
|
+
|
7
|
+
## Installation / Usage
|
8
|
+
|
9
|
+
Install one or more of the `RSpec` gems.
|
10
|
+
|
11
|
+
Want to run against the `master` branch? You'll need to include the dependent
|
12
|
+
RSpec repos as well. Add the following to your `Gemfile`:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
%w[rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
16
|
+
gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'master'
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
Once you've set up the environment, you'll need to cd into the working
|
23
|
+
directory of whichever repo you want to work in. From there you can run the
|
24
|
+
specs and cucumber features, and make patches.
|
25
|
+
|
26
|
+
NOTE: You do not need to use rspec-dev to work on a specific RSpec repo. You
|
27
|
+
can treat each RSpec repo as an independent project.
|
28
|
+
|
29
|
+
- [Build details](BUILD_DETAIL.md)
|
30
|
+
- [Code of Conduct](CODE_OF_CONDUCT.md)
|
31
|
+
- [Detailed contributing guide](CONTRIBUTING.md)
|
32
|
+
- [Development setup guide](DEVELOPMENT.md)
|
33
|
+
|
34
|
+
## Patches
|
35
|
+
|
36
|
+
Please submit a pull request or a github issue. If you submit an issue, please
|
37
|
+
include a link to either of:
|
38
|
+
|
39
|
+
* a gist (or equivalent) of the patch
|
40
|
+
* a branch or commit in your github fork of the repo
|
@@ -0,0 +1,149 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Support
|
3
|
+
# @api private
|
4
|
+
#
|
5
|
+
# Defines a helper method that is optimized to require files from the
|
6
|
+
# named lib. The passed block MUST be `{ |f| require_relative f }`
|
7
|
+
# because for `require_relative` to work properly from within the named
|
8
|
+
# lib the line of code must be IN that lib.
|
9
|
+
#
|
10
|
+
# `require_relative` is preferred when available because it is always O(1),
|
11
|
+
# regardless of the number of dirs in $LOAD_PATH. `require`, on the other
|
12
|
+
# hand, does a linear O(N) search over the dirs in the $LOAD_PATH until
|
13
|
+
# it can resolve the file relative to one of the dirs.
|
14
|
+
def self.define_optimized_require_for_rspec(lib, &require_relative)
|
15
|
+
name = "require_rspec_#{lib}"
|
16
|
+
|
17
|
+
if Kernel.respond_to?(:require_relative)
|
18
|
+
(class << self; self; end).__send__(:define_method, name) do |f|
|
19
|
+
require_relative.call("#{lib}/#{f}")
|
20
|
+
end
|
21
|
+
else
|
22
|
+
(class << self; self; end).__send__(:define_method, name) do |f|
|
23
|
+
require "rspec/#{lib}/#{f}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
define_optimized_require_for_rspec(:support) { |f| require_relative(f) }
|
29
|
+
require_rspec_support "version"
|
30
|
+
require_rspec_support "ruby_features"
|
31
|
+
|
32
|
+
# @api private
|
33
|
+
KERNEL_METHOD_METHOD = ::Kernel.instance_method(:method)
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
#
|
37
|
+
# Used internally to get a method handle for a particular object
|
38
|
+
# and method name.
|
39
|
+
#
|
40
|
+
# Includes handling for a few special cases:
|
41
|
+
#
|
42
|
+
# - Objects that redefine #method (e.g. an HTTPRequest struct)
|
43
|
+
# - BasicObject subclasses that mixin a Kernel dup (e.g. SimpleDelegator)
|
44
|
+
# - Objects that undefine method and delegate everything to another
|
45
|
+
# object (e.g. Mongoid association objects)
|
46
|
+
if RubyFeatures.supports_rebinding_module_methods?
|
47
|
+
def self.method_handle_for(object, method_name)
|
48
|
+
KERNEL_METHOD_METHOD.bind(object).call(method_name)
|
49
|
+
rescue NameError => original
|
50
|
+
begin
|
51
|
+
handle = object.method(method_name)
|
52
|
+
raise original unless handle.is_a? Method
|
53
|
+
handle
|
54
|
+
rescue Support::AllExceptionsExceptOnesWeMustNotRescue
|
55
|
+
raise original
|
56
|
+
end
|
57
|
+
end
|
58
|
+
else
|
59
|
+
def self.method_handle_for(object, method_name)
|
60
|
+
if ::Kernel === object
|
61
|
+
KERNEL_METHOD_METHOD.bind(object).call(method_name)
|
62
|
+
else
|
63
|
+
object.method(method_name)
|
64
|
+
end
|
65
|
+
rescue NameError => original
|
66
|
+
begin
|
67
|
+
handle = object.method(method_name)
|
68
|
+
raise original unless handle.is_a? Method
|
69
|
+
handle
|
70
|
+
rescue Support::AllExceptionsExceptOnesWeMustNotRescue
|
71
|
+
raise original
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# @api private
|
77
|
+
#
|
78
|
+
# Used internally to get a class of a given object, even if it does not respond to #class.
|
79
|
+
def self.class_of(object)
|
80
|
+
object.class
|
81
|
+
rescue NoMethodError
|
82
|
+
singleton_class = class << object; self; end
|
83
|
+
singleton_class.ancestors.find { |ancestor| !ancestor.equal?(singleton_class) }
|
84
|
+
end
|
85
|
+
|
86
|
+
# A single thread local variable so we don't excessively pollute that namespace.
|
87
|
+
def self.thread_local_data
|
88
|
+
Thread.current[:__rspec] ||= {}
|
89
|
+
end
|
90
|
+
|
91
|
+
# @api private
|
92
|
+
def self.failure_notifier=(callable)
|
93
|
+
thread_local_data[:failure_notifier] = callable
|
94
|
+
end
|
95
|
+
|
96
|
+
# @private
|
97
|
+
DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure }
|
98
|
+
|
99
|
+
# @api private
|
100
|
+
def self.failure_notifier
|
101
|
+
thread_local_data[:failure_notifier] || DEFAULT_FAILURE_NOTIFIER
|
102
|
+
end
|
103
|
+
|
104
|
+
# @api private
|
105
|
+
def self.notify_failure(failure, options={})
|
106
|
+
failure_notifier.call(failure, options)
|
107
|
+
end
|
108
|
+
|
109
|
+
# @api private
|
110
|
+
def self.with_failure_notifier(callable)
|
111
|
+
orig_notifier = failure_notifier
|
112
|
+
self.failure_notifier = callable
|
113
|
+
yield
|
114
|
+
ensure
|
115
|
+
self.failure_notifier = orig_notifier
|
116
|
+
end
|
117
|
+
|
118
|
+
class << self
|
119
|
+
# @api private
|
120
|
+
attr_writer :warning_notifier
|
121
|
+
end
|
122
|
+
|
123
|
+
# @private
|
124
|
+
DEFAULT_WARNING_NOTIFIER = lambda { |warning| ::Kernel.warn warning }
|
125
|
+
|
126
|
+
# @api private
|
127
|
+
def self.warning_notifier
|
128
|
+
@warning_notifier ||= DEFAULT_WARNING_NOTIFIER
|
129
|
+
end
|
130
|
+
|
131
|
+
# @private
|
132
|
+
module AllExceptionsExceptOnesWeMustNotRescue
|
133
|
+
# These exceptions are dangerous to rescue as rescuing them
|
134
|
+
# would interfere with things we should not interfere with.
|
135
|
+
AVOID_RESCUING = [NoMemoryError, SignalException, Interrupt, SystemExit]
|
136
|
+
|
137
|
+
def self.===(exception)
|
138
|
+
AVOID_RESCUING.none? { |ar| ar === exception }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# The Differ is only needed when a a spec fails with a diffable failure.
|
143
|
+
# In the more common case of all specs passing or the only failures being
|
144
|
+
# non-diffable, we can avoid the extra cost of loading the differ, diff-lcs,
|
145
|
+
# pp, etc by avoiding an unnecessary require. Instead, autoload will take
|
146
|
+
# care of loading the differ on first use.
|
147
|
+
autoload :Differ, "rspec/support/differ"
|
148
|
+
end
|
149
|
+
end
|