rspec-support 3.0.4 → 3.12.1

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 (41) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +322 -0
  4. data/{LICENSE.txt → LICENSE.md} +3 -2
  5. data/README.md +29 -6
  6. data/lib/rspec/support/caller_filter.rb +35 -16
  7. data/lib/rspec/support/comparable_version.rb +46 -0
  8. data/lib/rspec/support/differ.rb +51 -41
  9. data/lib/rspec/support/directory_maker.rb +63 -0
  10. data/lib/rspec/support/encoded_string.rb +110 -15
  11. data/lib/rspec/support/fuzzy_matcher.rb +5 -6
  12. data/lib/rspec/support/hunk_generator.rb +0 -1
  13. data/lib/rspec/support/matcher_definition.rb +42 -0
  14. data/lib/rspec/support/method_signature_verifier.rb +287 -54
  15. data/lib/rspec/support/mutex.rb +73 -0
  16. data/lib/rspec/support/object_formatter.rb +275 -0
  17. data/lib/rspec/support/recursive_const_methods.rb +76 -0
  18. data/lib/rspec/support/reentrant_mutex.rb +78 -0
  19. data/lib/rspec/support/ruby_features.rb +177 -14
  20. data/lib/rspec/support/source/location.rb +21 -0
  21. data/lib/rspec/support/source/node.rb +110 -0
  22. data/lib/rspec/support/source/token.rb +94 -0
  23. data/lib/rspec/support/source.rb +85 -0
  24. data/lib/rspec/support/spec/deprecation_helpers.rb +19 -32
  25. data/lib/rspec/support/spec/diff_helpers.rb +31 -0
  26. data/lib/rspec/support/spec/in_sub_process.rb +43 -16
  27. data/lib/rspec/support/spec/library_wide_checks.rb +150 -0
  28. data/lib/rspec/support/spec/shell_out.rb +108 -0
  29. data/lib/rspec/support/spec/stderr_splitter.rb +31 -9
  30. data/lib/rspec/support/spec/string_matcher.rb +45 -0
  31. data/lib/rspec/support/spec/with_isolated_directory.rb +13 -0
  32. data/lib/rspec/support/spec/with_isolated_stderr.rb +0 -2
  33. data/lib/rspec/support/spec.rb +46 -26
  34. data/lib/rspec/support/version.rb +1 -1
  35. data/lib/rspec/support/warnings.rb +6 -6
  36. data/lib/rspec/support/with_keywords_when_needed.rb +33 -0
  37. data/lib/rspec/support.rb +87 -3
  38. data.tar.gz.sig +0 -0
  39. metadata +70 -52
  40. metadata.gz.sig +0 -0
  41. data/lib/rspec/support/version_checker.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 71ada7066e53a0b40d343dd8f26528715c2fbf24
4
- data.tar.gz: 712553112d6764d89e35fa1a1657a268f16d2d83
2
+ SHA256:
3
+ metadata.gz: cd43ff0da6f307b7e9ccc56ceb9e3fdd972f27b7d160b8ba860c6625bb62f39b
4
+ data.tar.gz: a0c09feee171d7a1b02793888c995d9dd42f20660b6449db9c79eeed4a297b3f
5
5
  SHA512:
6
- metadata.gz: 2e5ffa54dcf62a550f3b87fdbfb1c548e2db1ac97f70a5b3608c9c51955fd81b496738b37050e991987788b32bbdd8d76179ef86fa091e99437593c34145947d
7
- data.tar.gz: a394b169979e054239c96ec27a10326f96273098ae993159a78c9db9e72f2fbc1ea334c3513f73d48b39771f47f31f16a339824c1ce602ea913230d0800fd0a8
6
+ metadata.gz: 247e3e818ef3c367c1ecbc4938dca5a0ca7c9b185c1b608900461e146ea1f8c5053e0d97adc692cd0871debeb764407a3403682ce425aebf1de6511f17f366fc
7
+ data.tar.gz: b3b600ca9061f37b529af60308df73b4c9724de1d173ee01eda44c0f61404396d8f2af7a52b071db93299bb607905e8b1aa3ddac29cc364ef41136a1815735d1
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,3 +1,325 @@
1
+ ### Development
2
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.12.1...3-12-maintenance)
3
+
4
+ ### 3.12.1 / 2023-06-26
5
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.12.0...v3.12.1)
6
+
7
+ Bug Fixes:
8
+
9
+ * Fix `RSpec::Support.thread_local_data` to be Thread local but not Fiber local.
10
+ (Jon Rowe, #581)
11
+
12
+ ### 3.12.0 / 2022-10-26
13
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.11.1...v3.12.0)
14
+ Enhancements:
15
+
16
+ * Add `RSpec::Support::RubyFeatures.distincts_kw_args_from_positional_hash?`
17
+ (Jean byroot Boussier, #535)
18
+
19
+ ### 3.11.1 / 2022-09-12
20
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.11.0...v3.11.1)
21
+
22
+ Bug Fixes:
23
+
24
+ * Fix ripper detection on TruffleRuby. (Brandon Fish, #541)
25
+
26
+ ### 3.11.0 / 2022-02-09
27
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.10.3...v3.11.0)
28
+
29
+ No changes. Released to support other RSpec releases.
30
+
31
+ ### 3.10.3 / 2021-11-03
32
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.10.2...v3.10.3)
33
+
34
+ Bug Fixes:
35
+
36
+ * Use `Mutex#owned?` to allow `RSpec::Support::ReentrantMutex` to work in
37
+ nested Fibers on Ruby 3.0 and later. (Benoit Daloze, #503, #504)
38
+ * Support `end`-less methods in `RSpec::Support::Source::Token`
39
+ so that RSpec won't hang when an `end`-less method raises an error. (Yuji Nakayama, #505)
40
+
41
+ ### 3.10.2 / 2021-01-28
42
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.10.1...v3.10.2)
43
+
44
+ Bug Fixes:
45
+
46
+ * Fix issue with `RSpec::Support.define_optimized_require_for_rspec` on JRuby
47
+ 9.1.17.0 (Jon Rowe, #492)
48
+
49
+ ### 3.10.1 / 2020-12-27
50
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.10.0...v3.10.1)
51
+
52
+ Bug Fixes:
53
+
54
+ * Fix deprecation expectations to fail correctly when
55
+ asserting on messages. (Phil Pirozhkov, #453)
56
+
57
+ ### 3.10.0 / 2020-10-30
58
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.4...v3.10.0)
59
+
60
+ No changes. Released to support other RSpec releases.
61
+
62
+ ### 3.9.4 / 2020-10-23
63
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.3...v3.9.4)
64
+
65
+ Bug Fixes:
66
+
67
+ * Flag ripper as supported on Truffle Ruby. (Brandon Fish, #427)
68
+ * Prevent stubbing `File.read` from breaking source extraction.
69
+ (Jon Rowe, #431)
70
+
71
+ ### 3.9.3 / 2020-05-02
72
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.2...v3.9.3)
73
+
74
+ Bug Fixes:
75
+
76
+ * Mark ripper as unsupported on Truffle Ruby. (Brandon Fish, #395)
77
+ * Mark ripper as unsupported on JRuby 9.2.0.0. (Brian Hawley, #400)
78
+ * Capture `Mutex.new` for our `RSpec::Support:Mutex` in order to
79
+ allow stubbing `Mutex.new`. (Jon Rowe, #411)
80
+
81
+ ### 3.9.2 / 2019-12-30
82
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.1...v3.9.2)
83
+
84
+ Bug Fixes:
85
+
86
+ * Remove unneeded eval. (Matijs van Zuijlen, #394)
87
+
88
+ ### 3.9.1 / 2019-12-28
89
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.0...v3.9.1)
90
+
91
+ Bug Fixes:
92
+
93
+ * Remove warning caused by keyword arguments on Ruby 2.7.0.
94
+ (Jon Rowe, #392)
95
+
96
+ ### 3.9.0 / 2019-10-07
97
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.8.3...v3.9.0)
98
+
99
+ *NO CHANGES*
100
+
101
+ Version 3.9.0 was released to allow other RSpec gems to release 3.9.0.
102
+
103
+ ### 3.8.3 / 2019-10-02
104
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.8.2...v3.8.3)
105
+
106
+ Bug Fixes:
107
+
108
+ * Escape \r when outputting strings inside arrays.
109
+ (Tomita Masahiro, Jon Rowe, #378)
110
+ * Ensure that optional hash arguments are recognised correctly vs keyword
111
+ arguments. (Evgeni Dzhelyov, #366)
112
+
113
+ ### 3.8.2 / 2019-06-10
114
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.8.1...v3.8.2)
115
+
116
+ Bug Fixes:
117
+
118
+ * Ensure that an empty hash is recognised as empty keyword arguments when
119
+ applicable. (Thomas Walpole, #375)
120
+ * Ensure that diffing truthy values produce diffs consistently.
121
+ (Lucas Nestor, #377)
122
+
123
+ ### 3.8.1 / 2019-03-03
124
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.8.0...v3.8.1)
125
+
126
+ Bug Fixes:
127
+
128
+ * Ensure that inspecting a `SimpleDelegator` based object works regardless of
129
+ visibilty of the `__getobj__` method. (Jon Rowe, #369)
130
+
131
+ ### 3.8.0 / 2018-08-04
132
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.7.1...v3.8.0)
133
+
134
+ Bug Fixes:
135
+
136
+ * Order hash keys before diffing to improve diff accuracy when using mocked calls.
137
+ (James Crisp, #334)
138
+
139
+ ### 3.7.1 / 2018-01-29
140
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.7.0...v3.7.1)
141
+
142
+ Bug Fixes:
143
+
144
+ * Fix source extraction logic so that it does not trigger a `SystemStackError`
145
+ when processing deeply nested example groups. (Craig Bass, #343)
146
+
147
+ ### 3.7.0 / 2017-10-17
148
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.6.0...v3.7.0)
149
+
150
+ Enhancements:
151
+
152
+ * Improve compatibility with `--enable-frozen-string-literal` option
153
+ on Ruby 2.3+. (Pat Allan, #320)
154
+ * Add `Support.class_of` for extracting class of any object.
155
+ (Yuji Nakayama, #325)
156
+
157
+ Bug Fixes:
158
+
159
+ * Fix recursive const support to not blow up when given buggy classes
160
+ that raise odd errors from `#to_str`. (Myron Marston, #317)
161
+
162
+ ### 3.6.0 / 2017-05-04
163
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.6.0.beta2...3.6.0)
164
+
165
+ Enhancements:
166
+
167
+ * Import `Source` classes from rspec-core. (Yuji Nakayama, #315)
168
+
169
+ ### 3.6.0.beta2 / 2016-12-12
170
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.6.0.beta1...v3.6.0.beta2)
171
+
172
+ No user-facing changes.
173
+
174
+ ### 3.6.0.beta1 / 2016-10-09
175
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0...v3.6.0.beta1)
176
+
177
+ Bug Fixes:
178
+
179
+ * Prevent truncated formatted object output from mangling console codes. (#294, Anson Kelly)
180
+
181
+ ### 3.5.0 / 2016-07-01
182
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0.beta4...v3.5.0)
183
+
184
+ **No user facing changes since beta4**
185
+
186
+ ### 3.5.0.beta4 / 2016-06-05
187
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0.beta3...v3.5.0.beta4)
188
+
189
+ Enhancements:
190
+ * Improve `MethodSignature` to better support keyword arguments. (#250, Rob Smith).
191
+
192
+ ### 3.5.0.beta3 / 2016-04-02
193
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0.beta2...v3.5.0.beta3)
194
+
195
+ Bug Fixes:
196
+
197
+ * Fix `EncodedString` to properly handle the behavior of `String#split`
198
+ on JRuby when the string contains invalid bytes. (Jon Rowe, #268)
199
+ * Fix `ObjectFormatter` so that formatting objects that don't respond to
200
+ `#inspect` (such as `BasicObject`) does not cause `NoMethodError`.
201
+ (Yuji Nakayama, #269)
202
+ * Fix `ObjectFormatter` so that formatting recursive array or hash does not
203
+ cause `SystemStackError`. (Yuji Nakayama, #270, #272)
204
+
205
+ ### 3.5.0.beta2 / 2016-03-10
206
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.5.0.beta1...v3.5.0.beta2)
207
+
208
+ No user-facing changes.
209
+
210
+ ### 3.5.0.beta1 / 2016-02-06
211
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.4.1...v3.5.0.beta1)
212
+
213
+ Enhancements:
214
+
215
+ * Improve formatting of objects by allowing truncation to a pre-configured length.
216
+ (Liam M, #256)
217
+
218
+ ### 3.4.1 / 2015-11-20
219
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.4.0...v3.4.1)
220
+
221
+ Bug Fixes:
222
+
223
+ * Fix `RSpec::Support::RubyFeature.ripper_supported?` so it returns
224
+ `false` on Rubinius since the Rubinius team has no plans to support
225
+ it. This prevents rspec-core from trying to load and use ripper to
226
+ extract failure snippets. (Aaron Stone, #251)
227
+
228
+ Changes:
229
+
230
+ * Remove `VersionChecker` in favor of `ComparableVersion`. (Yuji Nakayama, #266)
231
+
232
+ ### 3.4.0 / 2015-11-11
233
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.3.0...v3.4.0)
234
+
235
+ Enhancements:
236
+
237
+ * Improve formatting of `Delegator` based objects (e.g. `SimpleDelgator`) in
238
+ failure messages and diffs. (Andrew Horner, #215)
239
+ * Add `ComparableVersion`. (Yuji Nakayama, #245)
240
+ * Add `Ripper` support detection. (Yuji Nakayama, #245)
241
+
242
+ Bug Fixes:
243
+
244
+ * Work around bug in JRuby that reports that `attr_writer` methods
245
+ have no parameters, causing RSpec's verifying doubles to wrongly
246
+ fail when mocking or stubbing a writer method on JRuby. (Myron Marston, #225)
247
+
248
+ ### 3.3.0 / 2015-06-12
249
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.2.2...v3.3.0)
250
+
251
+ Enhancements:
252
+
253
+ * Improve formatting of arrays and hashes in failure messages so they
254
+ use our custom formatting of matchers, time objects, etc.
255
+ (Myron Marston, Nicholas Chmielewski, #205)
256
+ * Use improved formatting for diffs as well. (Nicholas Chmielewski, #205)
257
+
258
+ Bug Fixes:
259
+
260
+ * Fix `FuzzyMatcher` so that it checks `expected == actual` rather than
261
+ `actual == expected`, which avoids errors in situations where the
262
+ `actual` object's `==` is improperly implemented to assume that only
263
+ objects of the same type will be given. This allows rspec-mocks'
264
+ `anything` to match against objects with buggy `==` definitions.
265
+ (Myron Marston, #193)
266
+
267
+ ### 3.2.2 / 2015-02-23
268
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.2.1...v3.2.2)
269
+
270
+ Bug Fixes:
271
+
272
+ * Fix an encoding issue with `EncodedString#split` when encountering an
273
+ invalid byte string. (Benjamin Fleischer, #1760)
274
+
275
+ ### 3.2.1 / 2015-02-04
276
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.2.0...v3.2.1)
277
+
278
+ Bug Fixes:
279
+
280
+ * Fix `RSpec::CallerFilter` to work on Rubinius 2.2.
281
+ (Myron Marston, #169)
282
+
283
+ ### 3.2.0 / 2015-02-03
284
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.1.2...v3.2.0)
285
+
286
+ Enhancements:
287
+
288
+ * Add extra Ruby type detection. (Jon Rowe, #133)
289
+ * Make differ instance re-usable. (Alexey Fedorov, #160)
290
+
291
+ Bug Fixes:
292
+
293
+ * Do not consider `[]` and `{}` to match when performing fuzzy matching.
294
+ (Myron Marston, #157)
295
+
296
+ ### 3.1.2 / 2014-10-08
297
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.1.1...v3.1.2)
298
+
299
+ Bug Fixes:
300
+
301
+ * Fix method signature to not blow up with a `NoMethodError` on 1.8.7 when
302
+ verifying against an RSpec matcher. (Myron Marston, #116)
303
+
304
+ ### 3.1.1 / 2014-09-26
305
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.1.0...v3.1.1)
306
+
307
+ Bug Fixes:
308
+
309
+ * Fix `RSpec::Support::DirectoryMaker` (used by `rspec --init` and
310
+ `rails generate rspec:install`) so that it detects absolute paths
311
+ on Windows properly. (Scott Archer, #107, #108, #109) (Jon Rowe, #110)
312
+
313
+ ### 3.1.0 / 2014-09-04
314
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.4...v3.1.0)
315
+
316
+ Bug Fixes:
317
+
318
+ * Fix `FuzzyMatcher` so that it does not wrongly match a struct against
319
+ an array. (Myron Marston, #97)
320
+ * Prevent infinitely recursing `#flatten` methods from causing the differ
321
+ to hang. (Jon Rowe, #101)
322
+
1
323
  ### 3.0.4 / 2014-08-14
2
324
  [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.3...v3.0.4)
3
325
 
@@ -1,6 +1,7 @@
1
- Copyright (c) 2013 David Chelimsky, Myron Marston, Jon Rowe, Sam Phippen, Xavier Shay, Bradley Schaefer
1
+ The MIT License (MIT)
2
+ ====================
2
3
 
3
- MIT License
4
+ * Copyright © 2013 David Chelimsky, Myron Marston, Jon Rowe, Sam Phippen, Xavier Shay, Bradley Schaefer
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining
6
7
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RSpec::Support
1
+ # RSpec::Support [![Build Status](https://github.com/rspec/rspec-support/workflows/RSpec%20CI/badge.svg)](https://github.com/rspec/rspec-support/actions)
2
2
 
3
3
  `RSpec::Support` provides common functionality to `RSpec::Core`,
4
4
  `RSpec::Expectations` and `RSpec::Mocks`. It is considered
@@ -8,10 +8,33 @@ suitable for internal use only at this time.
8
8
 
9
9
  Install one or more of the `RSpec` gems.
10
10
 
11
+ Want to run against the `main` 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 => 'main'
17
+ end
18
+ ```
19
+
11
20
  ## Contributing
12
21
 
13
- 1. Fork it
14
- 2. Create your feature branch (`git checkout -b my-new-feature`)
15
- 3. Commit your changes (`git commit -am 'Add some feature'`)
16
- 4. Push to the branch (`git push origin my-new-feature`)
17
- 5. Create new Pull Request
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
@@ -1,10 +1,11 @@
1
+ RSpec::Support.require_rspec_support "ruby_features"
2
+
1
3
  module RSpec
2
4
  # Consistent implementation for "cleaning" the caller method to strip out
3
5
  # non-rspec lines. This enables errors to be reported at the call site in
4
6
  # the code using the library, which is far more useful than the particular
5
7
  # internal method that raised an error.
6
8
  class CallerFilter
7
-
8
9
  RSPEC_LIBS = %w[
9
10
  core
10
11
  mocks
@@ -24,10 +25,32 @@ module RSpec
24
25
  # when `CallerFilter.first_non_rspec_line` is called from the top level of a required
25
26
  # file, but it depends on if rubygems is loaded or not. We don't want to have to deal
26
27
  # with this complexity in our `RSpec.deprecate` calls, so we ignore it here.
27
- IGNORE_REGEX = Regexp.union(LIB_REGEX, "rubygems/core_ext/kernel_require.rb")
28
+ IGNORE_REGEX = Regexp.union(LIB_REGEX, "rubygems/core_ext/kernel_require.rb", "<internal:")
29
+
30
+ if RSpec::Support::RubyFeatures.caller_locations_supported?
31
+ # This supports args because it's more efficient when the caller specifies
32
+ # these. It allows us to skip frames the caller knows are part of RSpec,
33
+ # and to decrease the increment size if the caller is confident the line will
34
+ # be found in a small number of stack frames from `skip_frames`.
35
+ #
36
+ # Note that there is a risk to passing a `skip_frames` value that is too high:
37
+ # If it skipped the first non-rspec line, then this method would return the
38
+ # 2nd or 3rd (or whatever) non-rspec line. Thus, you generally shouldn't pass
39
+ # values for these parameters, particularly since most places that use this are
40
+ # not hot spots (generally it gets used for deprecation warnings). However,
41
+ # if you do have a hot spot that calls this, passing `skip_frames` can make
42
+ # a significant difference. Just make sure that that particular use is tested
43
+ # so that if the provided `skip_frames` changes to no longer be accurate in
44
+ # such a way that would return the wrong stack frame, a test will fail to tell you.
45
+ #
46
+ # See benchmarks/skip_frames_for_caller_filter.rb for measurements.
47
+ def self.first_non_rspec_line(skip_frames=3, increment=5)
48
+ # Why a default `skip_frames` of 3?
49
+ # By the time `caller_locations` is called below, the first 3 frames are:
50
+ # lib/rspec/support/caller_filter.rb:63:in `block in first_non_rspec_line'
51
+ # lib/rspec/support/caller_filter.rb:62:in `loop'
52
+ # lib/rspec/support/caller_filter.rb:62:in `first_non_rspec_line'
28
53
 
29
- if RUBY_VERSION >= '2.0.0'
30
- def self.first_non_rspec_line
31
54
  # `caller` is an expensive method that scales linearly with the size of
32
55
  # the stack. The performance hit for fetching it in chunks is small,
33
56
  # and since the target line is probably near the top of the stack, the
@@ -35,28 +58,24 @@ module RSpec
35
58
  #
36
59
  # See benchmarks/caller.rb for measurements.
37
60
 
38
- # Initial value here is mostly arbitrary, but is chosen to give good
39
- # performance on the common case of creating a double.
40
- increment = 5
41
- i = 1
42
- line = nil
61
+ # The default increment of 5 for this method are mostly arbitrary, but
62
+ # is chosen to give good performance on the common case of creating a double.
43
63
 
44
- while !line
45
- stack = caller(i, increment)
64
+ loop do
65
+ stack = caller_locations(skip_frames, increment)
46
66
  raise "No non-lib lines in stack" unless stack
47
67
 
48
- line = stack.find { |l| l !~ IGNORE_REGEX }
68
+ line = stack.find { |l| l.path !~ IGNORE_REGEX }
69
+ return line.to_s if line
49
70
 
50
- i += increment
71
+ skip_frames += increment
51
72
  increment *= 2 # The choice of two here is arbitrary.
52
73
  end
53
-
54
- line
55
74
  end
56
75
  else
57
76
  # Earlier rubies do not support the two argument form of `caller`. This
58
77
  # fallback is logically the same, but slower.
59
- def self.first_non_rspec_line
78
+ def self.first_non_rspec_line(*)
60
79
  caller.find { |line| line !~ IGNORE_REGEX }
61
80
  end
62
81
  end
@@ -0,0 +1,46 @@
1
+ module RSpec
2
+ module Support
3
+ # @private
4
+ class ComparableVersion
5
+ include Comparable
6
+
7
+ attr_reader :string
8
+
9
+ def initialize(string)
10
+ @string = string
11
+ end
12
+
13
+ def <=>(other)
14
+ other = self.class.new(other) unless other.is_a?(self.class)
15
+
16
+ return 0 if string == other.string
17
+
18
+ longer_segment_count = [self, other].map { |version| version.segments.count }.max
19
+
20
+ longer_segment_count.times do |index|
21
+ self_segment = segments[index] || 0
22
+ other_segment = other.segments[index] || 0
23
+
24
+ if self_segment.class == other_segment.class
25
+ result = self_segment <=> other_segment
26
+ return result unless result == 0
27
+ else
28
+ return self_segment.is_a?(String) ? -1 : 1
29
+ end
30
+ end
31
+
32
+ 0
33
+ end
34
+
35
+ def segments
36
+ @segments ||= string.scan(/[a-z]+|\d+/i).map do |segment|
37
+ if segment =~ /\A\d+\z/
38
+ segment.to_i
39
+ else
40
+ segment
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end