rspec-core 3.0.4 → 3.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +2 -1
- data/Changelog.md +888 -2
- data/{License.txt → LICENSE.md} +6 -5
- data/README.md +165 -24
- data/lib/rspec/autorun.rb +1 -0
- data/lib/rspec/core/backtrace_formatter.rb +19 -20
- data/lib/rspec/core/bisect/coordinator.rb +62 -0
- data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
- data/lib/rspec/core/bisect/fork_runner.rb +138 -0
- data/lib/rspec/core/bisect/server.rb +61 -0
- data/lib/rspec/core/bisect/shell_command.rb +126 -0
- data/lib/rspec/core/bisect/shell_runner.rb +73 -0
- data/lib/rspec/core/bisect/utilities.rb +69 -0
- data/lib/rspec/core/configuration.rb +1287 -246
- data/lib/rspec/core/configuration_options.rb +95 -35
- data/lib/rspec/core/did_you_mean.rb +46 -0
- data/lib/rspec/core/drb.rb +21 -12
- data/lib/rspec/core/dsl.rb +10 -6
- data/lib/rspec/core/example.rb +305 -113
- data/lib/rspec/core/example_group.rb +431 -223
- data/lib/rspec/core/example_status_persister.rb +235 -0
- data/lib/rspec/core/filter_manager.rb +86 -115
- data/lib/rspec/core/flat_map.rb +6 -4
- data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
- data/lib/rspec/core/formatters/base_formatter.rb +14 -116
- data/lib/rspec/core/formatters/base_text_formatter.rb +18 -21
- data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
- data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
- data/lib/rspec/core/formatters/console_codes.rb +29 -18
- data/lib/rspec/core/formatters/deprecation_formatter.rb +16 -16
- data/lib/rspec/core/formatters/documentation_formatter.rb +49 -16
- data/lib/rspec/core/formatters/exception_presenter.rb +525 -0
- data/lib/rspec/core/formatters/failure_list_formatter.rb +23 -0
- data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
- data/lib/rspec/core/formatters/helpers.rb +45 -15
- data/lib/rspec/core/formatters/html_formatter.rb +33 -28
- data/lib/rspec/core/formatters/html_printer.rb +30 -20
- data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
- data/lib/rspec/core/formatters/json_formatter.rb +18 -9
- data/lib/rspec/core/formatters/profile_formatter.rb +10 -9
- data/lib/rspec/core/formatters/progress_formatter.rb +5 -4
- data/lib/rspec/core/formatters/protocol.rb +182 -0
- data/lib/rspec/core/formatters/snippet_extractor.rb +113 -82
- data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
- data/lib/rspec/core/formatters.rb +81 -41
- data/lib/rspec/core/hooks.rb +314 -244
- data/lib/rspec/core/invocations.rb +87 -0
- data/lib/rspec/core/memoized_helpers.rb +161 -51
- data/lib/rspec/core/metadata.rb +132 -61
- data/lib/rspec/core/metadata_filter.rb +224 -64
- data/lib/rspec/core/minitest_assertions_adapter.rb +6 -3
- data/lib/rspec/core/mocking_adapters/flexmock.rb +4 -2
- data/lib/rspec/core/mocking_adapters/mocha.rb +11 -9
- data/lib/rspec/core/mocking_adapters/null.rb +2 -0
- data/lib/rspec/core/mocking_adapters/rr.rb +3 -1
- data/lib/rspec/core/mocking_adapters/rspec.rb +3 -1
- data/lib/rspec/core/notifications.rb +192 -206
- data/lib/rspec/core/option_parser.rb +174 -69
- data/lib/rspec/core/ordering.rb +48 -35
- data/lib/rspec/core/output_wrapper.rb +29 -0
- data/lib/rspec/core/pending.rb +25 -33
- data/lib/rspec/core/profiler.rb +34 -0
- data/lib/rspec/core/project_initializer/.rspec +0 -2
- data/lib/rspec/core/project_initializer/spec/spec_helper.rb +59 -39
- data/lib/rspec/core/project_initializer.rb +5 -3
- data/lib/rspec/core/rake_task.rb +99 -55
- data/lib/rspec/core/reporter.rb +128 -15
- data/lib/rspec/core/ruby_project.rb +14 -6
- data/lib/rspec/core/runner.rb +96 -45
- data/lib/rspec/core/sandbox.rb +37 -0
- data/lib/rspec/core/set.rb +54 -0
- data/lib/rspec/core/shared_example_group.rb +133 -43
- data/lib/rspec/core/shell_escape.rb +49 -0
- data/lib/rspec/core/test_unit_assertions_adapter.rb +4 -4
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/warnings.rb +6 -6
- data/lib/rspec/core/world.rb +172 -68
- data/lib/rspec/core.rb +66 -21
- data.tar.gz.sig +0 -0
- metadata +93 -69
- metadata.gz.sig +0 -0
- data/lib/rspec/core/backport_random.rb +0 -336
metadata
CHANGED
@@ -1,40 +1,52 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Baker
|
8
8
|
- David Chelimsky
|
9
9
|
- Chad Humphries
|
10
10
|
- Myron Marston
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain:
|
14
14
|
- |
|
15
15
|
-----BEGIN CERTIFICATE-----
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
16
|
+
MIIF1TCCA72gAwIBAgIJAPXjfUbCjdXUMA0GCSqGSIb3DQEBBQUAMIGAMQswCQYD
|
17
|
+
VQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEO
|
18
|
+
MAwGA1UECgwFUlNwZWMxEzARBgNVBAMMCnJzcGVjLmluZm8xJTAjBgkqhkiG9w0B
|
19
|
+
CQEWFnJzcGVjQGdvb2dsZWdyb3Vwcy5jb20wHhcNMTQxMjIzMDkzNTIyWhcNMjQx
|
20
|
+
MjIyMDkzNTIyWjCBgDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24x
|
21
|
+
EDAOBgNVBAcMB1NlYXR0bGUxDjAMBgNVBAoMBVJTcGVjMRMwEQYDVQQDDApyc3Bl
|
22
|
+
Yy5pbmZvMSUwIwYJKoZIhvcNAQkBFhZyc3BlY0Bnb29nbGVncm91cHMuY29tMIIC
|
23
|
+
IjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAsSmjgcHaKlD0jizRJowi2bGI
|
24
|
+
KMOHnJoExxRNHHxH+3w9kkl95YldvDRVX495b13ZCzwRe0AyqX24wq04tp0G5Z5C
|
25
|
+
e/w2pnNK4ol1eECPwQu+YGpepeODlZICL5gwQspe0cDifbBnHx5QySMiPpvx6bC0
|
26
|
+
tQTox0ppDIaMhch8IPCwyoE4DQK5bpsdwnLSHTsQjUIb7IM8tUMpd/iKrJgNffwc
|
27
|
+
6gC1TmhIlzQoB26nCNh9uK7xZjUM+sGECzvcYuImchUaIgJA/ybrlZS+m/hxzvBo
|
28
|
+
mLnn/xNEC6Vz5HG+3TR0Gb0cSUf6XUu2s51Jk/SJi3MhCZp2gs9OUg4EVZNzQVkZ
|
29
|
+
efLBjAZG2Mxk14JyB4/Omc+Jk0ajprINCBbUNnxzCJrYDM3J9TVWIwyUGNX/U3MO
|
30
|
+
s3tMAT+EVgx/mZMPnBO8EULlyF51MRUp3Wy9Mnw8AYLk30UnMG5AjqgO5JNyFlA7
|
31
|
+
Xeh3EVdWY3vMB1pkhPwlsenpcmj5gOzrd54lELOVbCGHCf48iSqeflY2Lhe0pvzK
|
32
|
+
blXCJBDmtrebvus291rM/dHcbEfK1SVd5Wut/n131iouf6dnNCFskFygDcgBbthC
|
33
|
+
gpEMqf80lEmhX59VUsm0Pv6OEo+ZPHBvXPiJA6DShQh9t3YtpwyA8uVDMbT/i32u
|
34
|
+
2FUsqZbbJcCmkBrGposCAwEAAaNQME4wHQYDVR0OBBYEFPPvQ5XT0Nvuhi6k+hrW
|
35
|
+
Vv35J+TeMB8GA1UdIwQYMBaAFPPvQ5XT0Nvuhi6k+hrWVv35J+TeMAwGA1UdEwQF
|
36
|
+
MAMBAf8wDQYJKoZIhvcNAQEFBQADggIBAIqbQSWH2aAF537DKwAMB8nMFsoe24MD
|
37
|
+
gtuQAyjTtbH+QBE4N2RdQF/sU7Y3PYR7nqdrCsYc3RxyqM5XXi7I3IYdpfe1RuxY
|
38
|
+
+pyPzVQsPPDhMlJlCrwJsADnxlpxZlAgxYSLKOan55ihscaAWA90wqRUrf/ZJM36
|
39
|
+
8LWCPVn5teIt5aaxZWX68RMxa+AXvpbtJOBwXLkIFk3apD8CX4DhelIdw67DbkUe
|
40
|
+
ghUd/u62qrnqBTVgditt7OoWIZjzh24/Fda5d0MxZyvLILGOrf5bN4cTbe/q9Cid
|
41
|
+
Xrik7Upm+mu3y3yQIfrw85xybHq6iNXyYHvCdSrFfCIKrGpd/0CAdmYnJlx59Fk/
|
42
|
+
UbD3Eyx4psBSkU+WKO0Uf+3zNI7N/nVeNIwU/Ft+l8l7/K+427656c+ZGWDO0Gt/
|
43
|
+
BeEOSTDKP7qQ1T+JvMrBcBQo+i0cnRT10J1aoV90BhxsvWTRizIbugbaqR6Tq3bj
|
44
|
+
Akt00cIlNSplL6DenIAKSh5kF7s0tRD0tC3bNkZmNjNGkdoGEcUODEpTB3RHKKiu
|
45
|
+
e6k2Jg6m00z5vGFQhOnROG/QaUzMA3A3mFBe1RHFo07xd0pFeoeWL3vF69Gx9Jwp
|
46
|
+
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
47
|
+
F3MdtaDehhjC
|
36
48
|
-----END CERTIFICATE-----
|
37
|
-
date:
|
49
|
+
date: 2023-04-18 00:00:00.000000000 Z
|
38
50
|
dependencies:
|
39
51
|
- !ruby/object:Gem::Dependency
|
40
52
|
name: rspec-support
|
@@ -42,40 +54,26 @@ dependencies:
|
|
42
54
|
requirements:
|
43
55
|
- - "~>"
|
44
56
|
- !ruby/object:Gem::Version
|
45
|
-
version: 3.
|
57
|
+
version: 3.12.0
|
46
58
|
type: :runtime
|
47
59
|
prerelease: false
|
48
60
|
version_requirements: !ruby/object:Gem::Requirement
|
49
61
|
requirements:
|
50
62
|
- - "~>"
|
51
63
|
- !ruby/object:Gem::Version
|
52
|
-
version: 3.
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: rake
|
55
|
-
requirement: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - "~>"
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: 10.0.0
|
60
|
-
type: :development
|
61
|
-
prerelease: false
|
62
|
-
version_requirements: !ruby/object:Gem::Requirement
|
63
|
-
requirements:
|
64
|
-
- - "~>"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 10.0.0
|
64
|
+
version: 3.12.0
|
67
65
|
- !ruby/object:Gem::Dependency
|
68
66
|
name: cucumber
|
69
67
|
requirement: !ruby/object:Gem::Requirement
|
70
68
|
requirements:
|
71
|
-
- - "
|
69
|
+
- - ">="
|
72
70
|
- !ruby/object:Gem::Version
|
73
71
|
version: '1.3'
|
74
72
|
type: :development
|
75
73
|
prerelease: false
|
76
74
|
version_requirements: !ruby/object:Gem::Requirement
|
77
75
|
requirements:
|
78
|
-
- - "
|
76
|
+
- - ">="
|
79
77
|
- !ruby/object:Gem::Version
|
80
78
|
version: '1.3'
|
81
79
|
- !ruby/object:Gem::Dependency
|
@@ -98,42 +96,28 @@ dependencies:
|
|
98
96
|
requirements:
|
99
97
|
- - "~>"
|
100
98
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
99
|
+
version: 0.14.9
|
102
100
|
type: :development
|
103
101
|
prerelease: false
|
104
102
|
version_requirements: !ruby/object:Gem::Requirement
|
105
103
|
requirements:
|
106
104
|
- - "~>"
|
107
105
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
109
|
-
- !ruby/object:Gem::Dependency
|
110
|
-
name: nokogiri
|
111
|
-
requirement: !ruby/object:Gem::Requirement
|
112
|
-
requirements:
|
113
|
-
- - '='
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
version: 1.5.2
|
116
|
-
type: :development
|
117
|
-
prerelease: false
|
118
|
-
version_requirements: !ruby/object:Gem::Requirement
|
119
|
-
requirements:
|
120
|
-
- - '='
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: 1.5.2
|
106
|
+
version: 0.14.9
|
123
107
|
- !ruby/object:Gem::Dependency
|
124
108
|
name: coderay
|
125
109
|
requirement: !ruby/object:Gem::Requirement
|
126
110
|
requirements:
|
127
111
|
- - "~>"
|
128
112
|
- !ruby/object:Gem::Version
|
129
|
-
version: 1.
|
113
|
+
version: 1.1.1
|
130
114
|
type: :development
|
131
115
|
prerelease: false
|
132
116
|
version_requirements: !ruby/object:Gem::Requirement
|
133
117
|
requirements:
|
134
118
|
- - "~>"
|
135
119
|
- !ruby/object:Gem::Version
|
136
|
-
version: 1.
|
120
|
+
version: 1.1.1
|
137
121
|
- !ruby/object:Gem::Dependency
|
138
122
|
name: mocha
|
139
123
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,6 +160,20 @@ dependencies:
|
|
176
160
|
- - "~>"
|
177
161
|
- !ruby/object:Gem::Version
|
178
162
|
version: 0.9.0
|
163
|
+
- !ruby/object:Gem::Dependency
|
164
|
+
name: thread_order
|
165
|
+
requirement: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - "~>"
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: 1.1.0
|
170
|
+
type: :development
|
171
|
+
prerelease: false
|
172
|
+
version_requirements: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - "~>"
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: 1.1.0
|
179
177
|
description: BDD for Ruby. RSpec runner and example groups.
|
180
178
|
email: rspec@googlegroups.com
|
181
179
|
executables:
|
@@ -186,35 +184,53 @@ files:
|
|
186
184
|
- ".document"
|
187
185
|
- ".yardopts"
|
188
186
|
- Changelog.md
|
189
|
-
-
|
187
|
+
- LICENSE.md
|
190
188
|
- README.md
|
191
189
|
- exe/rspec
|
192
190
|
- lib/rspec/autorun.rb
|
193
191
|
- lib/rspec/core.rb
|
194
|
-
- lib/rspec/core/backport_random.rb
|
195
192
|
- lib/rspec/core/backtrace_formatter.rb
|
193
|
+
- lib/rspec/core/bisect/coordinator.rb
|
194
|
+
- lib/rspec/core/bisect/example_minimizer.rb
|
195
|
+
- lib/rspec/core/bisect/fork_runner.rb
|
196
|
+
- lib/rspec/core/bisect/server.rb
|
197
|
+
- lib/rspec/core/bisect/shell_command.rb
|
198
|
+
- lib/rspec/core/bisect/shell_runner.rb
|
199
|
+
- lib/rspec/core/bisect/utilities.rb
|
196
200
|
- lib/rspec/core/configuration.rb
|
197
201
|
- lib/rspec/core/configuration_options.rb
|
202
|
+
- lib/rspec/core/did_you_mean.rb
|
198
203
|
- lib/rspec/core/drb.rb
|
199
204
|
- lib/rspec/core/dsl.rb
|
200
205
|
- lib/rspec/core/example.rb
|
201
206
|
- lib/rspec/core/example_group.rb
|
207
|
+
- lib/rspec/core/example_status_persister.rb
|
202
208
|
- lib/rspec/core/filter_manager.rb
|
203
209
|
- lib/rspec/core/flat_map.rb
|
204
210
|
- lib/rspec/core/formatters.rb
|
211
|
+
- lib/rspec/core/formatters/base_bisect_formatter.rb
|
205
212
|
- lib/rspec/core/formatters/base_formatter.rb
|
206
213
|
- lib/rspec/core/formatters/base_text_formatter.rb
|
214
|
+
- lib/rspec/core/formatters/bisect_drb_formatter.rb
|
215
|
+
- lib/rspec/core/formatters/bisect_progress_formatter.rb
|
207
216
|
- lib/rspec/core/formatters/console_codes.rb
|
208
217
|
- lib/rspec/core/formatters/deprecation_formatter.rb
|
209
218
|
- lib/rspec/core/formatters/documentation_formatter.rb
|
219
|
+
- lib/rspec/core/formatters/exception_presenter.rb
|
220
|
+
- lib/rspec/core/formatters/failure_list_formatter.rb
|
221
|
+
- lib/rspec/core/formatters/fallback_message_formatter.rb
|
210
222
|
- lib/rspec/core/formatters/helpers.rb
|
211
223
|
- lib/rspec/core/formatters/html_formatter.rb
|
212
224
|
- lib/rspec/core/formatters/html_printer.rb
|
225
|
+
- lib/rspec/core/formatters/html_snippet_extractor.rb
|
213
226
|
- lib/rspec/core/formatters/json_formatter.rb
|
214
227
|
- lib/rspec/core/formatters/profile_formatter.rb
|
215
228
|
- lib/rspec/core/formatters/progress_formatter.rb
|
229
|
+
- lib/rspec/core/formatters/protocol.rb
|
216
230
|
- lib/rspec/core/formatters/snippet_extractor.rb
|
231
|
+
- lib/rspec/core/formatters/syntax_highlighter.rb
|
217
232
|
- lib/rspec/core/hooks.rb
|
233
|
+
- lib/rspec/core/invocations.rb
|
218
234
|
- lib/rspec/core/memoized_helpers.rb
|
219
235
|
- lib/rspec/core/metadata.rb
|
220
236
|
- lib/rspec/core/metadata_filter.rb
|
@@ -227,7 +243,9 @@ files:
|
|
227
243
|
- lib/rspec/core/notifications.rb
|
228
244
|
- lib/rspec/core/option_parser.rb
|
229
245
|
- lib/rspec/core/ordering.rb
|
246
|
+
- lib/rspec/core/output_wrapper.rb
|
230
247
|
- lib/rspec/core/pending.rb
|
248
|
+
- lib/rspec/core/profiler.rb
|
231
249
|
- lib/rspec/core/project_initializer.rb
|
232
250
|
- lib/rspec/core/project_initializer/.rspec
|
233
251
|
- lib/rspec/core/project_initializer/spec/spec_helper.rb
|
@@ -235,17 +253,25 @@ files:
|
|
235
253
|
- lib/rspec/core/reporter.rb
|
236
254
|
- lib/rspec/core/ruby_project.rb
|
237
255
|
- lib/rspec/core/runner.rb
|
256
|
+
- lib/rspec/core/sandbox.rb
|
257
|
+
- lib/rspec/core/set.rb
|
238
258
|
- lib/rspec/core/shared_context.rb
|
239
259
|
- lib/rspec/core/shared_example_group.rb
|
260
|
+
- lib/rspec/core/shell_escape.rb
|
240
261
|
- lib/rspec/core/test_unit_assertions_adapter.rb
|
241
262
|
- lib/rspec/core/version.rb
|
242
263
|
- lib/rspec/core/warnings.rb
|
243
264
|
- lib/rspec/core/world.rb
|
244
|
-
homepage:
|
265
|
+
homepage: https://github.com/rspec/rspec-core
|
245
266
|
licenses:
|
246
267
|
- MIT
|
247
|
-
metadata:
|
248
|
-
|
268
|
+
metadata:
|
269
|
+
bug_tracker_uri: https://github.com/rspec/rspec-core/issues
|
270
|
+
changelog_uri: https://github.com/rspec/rspec-core/blob/v3.12.2/Changelog.md
|
271
|
+
documentation_uri: https://rspec.info/documentation/
|
272
|
+
mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
|
273
|
+
source_code_uri: https://github.com/rspec/rspec-core
|
274
|
+
post_install_message:
|
249
275
|
rdoc_options:
|
250
276
|
- "--charset=UTF-8"
|
251
277
|
require_paths:
|
@@ -261,10 +287,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
287
|
- !ruby/object:Gem::Version
|
262
288
|
version: '0'
|
263
289
|
requirements: []
|
264
|
-
|
265
|
-
|
266
|
-
signing_key:
|
290
|
+
rubygems_version: 3.4.10
|
291
|
+
signing_key:
|
267
292
|
specification_version: 4
|
268
|
-
summary: rspec-core-3.
|
293
|
+
summary: rspec-core-3.12.2
|
269
294
|
test_files: []
|
270
|
-
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,336 +0,0 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Core
|
3
|
-
# @private
|
4
|
-
#
|
5
|
-
# Methods used internally by the backports.
|
6
|
-
#
|
7
|
-
# This code was (mostly) ported from the backports gem found at
|
8
|
-
# https://github.com/marcandre/backports which is subject to this license:
|
9
|
-
#
|
10
|
-
# =========================================================================
|
11
|
-
#
|
12
|
-
# Copyright (c) 2009 Marc-Andre Lafortune
|
13
|
-
#
|
14
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
15
|
-
# a copy of this software and associated documentation files (the
|
16
|
-
# "Software"), to deal in the Software without restriction, including
|
17
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
18
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
19
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
20
|
-
# the following conditions:
|
21
|
-
#
|
22
|
-
# The above copyright notice and this permission notice shall be
|
23
|
-
# included in all copies or substantial portions of the Software.
|
24
|
-
#
|
25
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
26
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
27
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
28
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
29
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
30
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
31
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
32
|
-
#
|
33
|
-
# =========================================================================
|
34
|
-
#
|
35
|
-
# The goal is to provide a random number generator in Ruby versions that do
|
36
|
-
# not have one. This was added to support localization of random spec
|
37
|
-
# ordering.
|
38
|
-
#
|
39
|
-
# These were in multiple files in backports, but merged into one here.
|
40
|
-
module Backports
|
41
|
-
# Helper method to coerce a value into a specific class.
|
42
|
-
# Raises a TypeError if the coercion fails or the returned value
|
43
|
-
# is not of the right class.
|
44
|
-
# (from Rubinius)
|
45
|
-
def self.coerce_to(obj, cls, meth)
|
46
|
-
return obj if obj.kind_of?(cls)
|
47
|
-
|
48
|
-
begin
|
49
|
-
ret = obj.__send__(meth)
|
50
|
-
rescue Exception => e
|
51
|
-
raise TypeError, "Coercion error: #{obj.inspect}.#{meth} => #{cls} failed:\n" \
|
52
|
-
"(#{e.message})"
|
53
|
-
end
|
54
|
-
raise TypeError, "Coercion error: obj.#{meth} did NOT return a #{cls} (was #{ret.class})" unless ret.kind_of? cls
|
55
|
-
ret
|
56
|
-
end
|
57
|
-
|
58
|
-
# @private
|
59
|
-
def self.coerce_to_int(obj)
|
60
|
-
coerce_to(obj, Integer, :to_int)
|
61
|
-
end
|
62
|
-
|
63
|
-
# Used internally to make it easy to deal with optional arguments
|
64
|
-
# (from Rubinius)
|
65
|
-
Undefined = Object.new
|
66
|
-
|
67
|
-
# @private
|
68
|
-
class Random
|
69
|
-
# @private
|
70
|
-
# An implementation of Mersenne Twister MT19937 in Ruby
|
71
|
-
class MT19937
|
72
|
-
STATE_SIZE = 624
|
73
|
-
LAST_STATE = STATE_SIZE - 1
|
74
|
-
PAD_32_BITS = 0xffffffff
|
75
|
-
|
76
|
-
# See seed=
|
77
|
-
def initialize(seed)
|
78
|
-
self.seed = seed
|
79
|
-
end
|
80
|
-
|
81
|
-
LAST_31_BITS = 0x7fffffff
|
82
|
-
OFFSET = 397
|
83
|
-
|
84
|
-
# Generates a completely new state out of the previous one.
|
85
|
-
def next_state
|
86
|
-
STATE_SIZE.times do |i|
|
87
|
-
mix = @state[i] & 0x80000000 | @state[i+1 - STATE_SIZE] & 0x7fffffff
|
88
|
-
@state[i] = @state[i+OFFSET - STATE_SIZE] ^ (mix >> 1)
|
89
|
-
@state[i] ^= 0x9908b0df if mix.odd?
|
90
|
-
end
|
91
|
-
@last_read = -1
|
92
|
-
end
|
93
|
-
|
94
|
-
# Seed must be either an Integer (only the first 32 bits will be used)
|
95
|
-
# or an Array of Integers (of which only the first 32 bits will be used)
|
96
|
-
#
|
97
|
-
# No conversion or type checking is done at this level
|
98
|
-
def seed=(seed)
|
99
|
-
case seed
|
100
|
-
when Integer
|
101
|
-
@state = Array.new(STATE_SIZE)
|
102
|
-
@state[0] = seed & PAD_32_BITS
|
103
|
-
(1..LAST_STATE).each do |i|
|
104
|
-
@state[i] = (1812433253 * (@state[i-1] ^ @state[i-1]>>30) + i)& PAD_32_BITS
|
105
|
-
end
|
106
|
-
@last_read = LAST_STATE
|
107
|
-
when Array
|
108
|
-
self.seed = 19650218
|
109
|
-
i=1
|
110
|
-
j=0
|
111
|
-
[STATE_SIZE, seed.size].max.times do
|
112
|
-
@state[i] = (@state[i] ^ (@state[i-1] ^ @state[i-1]>>30) * 1664525) + j + seed[j] & PAD_32_BITS
|
113
|
-
if (i+=1) >= STATE_SIZE
|
114
|
-
@state[0] = @state[-1]
|
115
|
-
i = 1
|
116
|
-
end
|
117
|
-
j = 0 if (j+=1) >= seed.size
|
118
|
-
end
|
119
|
-
(STATE_SIZE-1).times do
|
120
|
-
@state[i] = (@state[i] ^ (@state[i-1] ^ @state[i-1]>>30) * 1566083941) - i & PAD_32_BITS
|
121
|
-
if (i+=1) >= STATE_SIZE
|
122
|
-
@state[0] = @state[-1]
|
123
|
-
i = 1
|
124
|
-
end
|
125
|
-
end
|
126
|
-
@state[0] = 0x80000000
|
127
|
-
else
|
128
|
-
raise ArgumentError, "Seed must be an Integer or an Array"
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# Returns a random Integer from the range 0 ... (1 << 32)
|
133
|
-
def random_32_bits
|
134
|
-
next_state if @last_read >= LAST_STATE
|
135
|
-
@last_read += 1
|
136
|
-
y = @state[@last_read]
|
137
|
-
# Tempering
|
138
|
-
y ^= (y >> 11)
|
139
|
-
y ^= (y << 7) & 0x9d2c5680
|
140
|
-
y ^= (y << 15) & 0xefc60000
|
141
|
-
y ^= (y >> 18)
|
142
|
-
end
|
143
|
-
|
144
|
-
# Supplement the MT19937 class with methods to do
|
145
|
-
# conversions the same way as MRI.
|
146
|
-
# No argument checking is done here either.
|
147
|
-
|
148
|
-
FLOAT_FACTOR = 1.0/9007199254740992.0
|
149
|
-
# generates a random number on [0,1) with 53-bit resolution
|
150
|
-
def random_float
|
151
|
-
((random_32_bits >> 5) * 67108864.0 + (random_32_bits >> 6)) * FLOAT_FACTOR;
|
152
|
-
end
|
153
|
-
|
154
|
-
# Returns an integer within 0...upto
|
155
|
-
def random_integer(upto)
|
156
|
-
n = upto - 1
|
157
|
-
nb_full_32 = 0
|
158
|
-
while n > PAD_32_BITS
|
159
|
-
n >>= 32
|
160
|
-
nb_full_32 += 1
|
161
|
-
end
|
162
|
-
mask = mask_32_bits(n)
|
163
|
-
begin
|
164
|
-
rand = random_32_bits & mask
|
165
|
-
nb_full_32.times do
|
166
|
-
rand <<= 32
|
167
|
-
rand |= random_32_bits
|
168
|
-
end
|
169
|
-
end until rand < upto
|
170
|
-
rand
|
171
|
-
end
|
172
|
-
|
173
|
-
def random_bytes(nb)
|
174
|
-
nb_32_bits = (nb + 3) / 4
|
175
|
-
random = nb_32_bits.times.map { random_32_bits }
|
176
|
-
random.pack("L" * nb_32_bits)[0, nb]
|
177
|
-
end
|
178
|
-
|
179
|
-
def state_as_bignum
|
180
|
-
b = 0
|
181
|
-
@state.each_with_index do |val, i|
|
182
|
-
b |= val << (32 * i)
|
183
|
-
end
|
184
|
-
b
|
185
|
-
end
|
186
|
-
|
187
|
-
def left # It's actually the number of words left + 1, as per MRI...
|
188
|
-
MT19937::STATE_SIZE - @last_read
|
189
|
-
end
|
190
|
-
|
191
|
-
def marshal_dump
|
192
|
-
[state_as_bignum, left]
|
193
|
-
end
|
194
|
-
|
195
|
-
def marshal_load(ary)
|
196
|
-
b, left = ary
|
197
|
-
@last_read = MT19937::STATE_SIZE - left
|
198
|
-
@state = Array.new(STATE_SIZE)
|
199
|
-
STATE_SIZE.times do |i|
|
200
|
-
@state[i] = b & PAD_32_BITS
|
201
|
-
b >>= 32
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
# Convert an Integer seed of arbitrary size to either a single 32 bit integer, or an Array of 32 bit integers
|
206
|
-
def self.convert_seed(seed)
|
207
|
-
seed = seed.abs
|
208
|
-
long_values = []
|
209
|
-
begin
|
210
|
-
long_values << (seed & PAD_32_BITS)
|
211
|
-
seed >>= 32
|
212
|
-
end until seed == 0
|
213
|
-
|
214
|
-
long_values.pop if long_values[-1] == 1 && long_values.size > 1 # Done to allow any kind of sequence of integers
|
215
|
-
|
216
|
-
long_values.size > 1 ? long_values : long_values.first
|
217
|
-
end
|
218
|
-
|
219
|
-
def self.[](seed)
|
220
|
-
new(convert_seed(seed))
|
221
|
-
end
|
222
|
-
|
223
|
-
private
|
224
|
-
|
225
|
-
MASK_BY = [1,2,4,8,16]
|
226
|
-
def mask_32_bits(n)
|
227
|
-
MASK_BY.each do |shift|
|
228
|
-
n |= n >> shift
|
229
|
-
end
|
230
|
-
n
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
# @private
|
235
|
-
# Implementation corresponding to the actual Random class of Ruby
|
236
|
-
# The actual random generator (mersenne twister) is in MT19937.
|
237
|
-
# Ruby specific conversions are handled in bits_and_bytes.
|
238
|
-
# The high level stuff (argument checking) is done here.
|
239
|
-
module Implementation
|
240
|
-
attr_reader :seed
|
241
|
-
|
242
|
-
def initialize(seed = 0)
|
243
|
-
super()
|
244
|
-
seed_rand seed
|
245
|
-
end
|
246
|
-
|
247
|
-
def seed_rand(new_seed = 0)
|
248
|
-
new_seed = Backports.coerce_to_int(new_seed)
|
249
|
-
@seed = nil unless defined?(@seed)
|
250
|
-
old, @seed = @seed, new_seed.nonzero? || Random.new_seed
|
251
|
-
@mt = MT19937[ @seed ]
|
252
|
-
old
|
253
|
-
end
|
254
|
-
|
255
|
-
def rand(limit = Backports::Undefined)
|
256
|
-
case limit
|
257
|
-
when Backports::Undefined
|
258
|
-
@mt.random_float
|
259
|
-
when Float
|
260
|
-
limit * @mt.random_float unless limit <= 0
|
261
|
-
when Range
|
262
|
-
_rand_range(limit)
|
263
|
-
else
|
264
|
-
limit = Backports.coerce_to_int(limit)
|
265
|
-
@mt.random_integer(limit) unless limit <= 0
|
266
|
-
end || raise(ArgumentError, "invalid argument #{limit}")
|
267
|
-
end
|
268
|
-
|
269
|
-
def bytes(nb)
|
270
|
-
nb = Backports.coerce_to_int(nb)
|
271
|
-
raise ArgumentError, "negative size" if nb < 0
|
272
|
-
@mt.random_bytes(nb)
|
273
|
-
end
|
274
|
-
|
275
|
-
def ==(other)
|
276
|
-
other.is_a?(Random) &&
|
277
|
-
seed == other.seed &&
|
278
|
-
left == other.send(:left) &&
|
279
|
-
state == other.send(:state)
|
280
|
-
end
|
281
|
-
|
282
|
-
def marshal_dump
|
283
|
-
@mt.marshal_dump << @seed
|
284
|
-
end
|
285
|
-
|
286
|
-
def marshal_load(ary)
|
287
|
-
@seed = ary.pop
|
288
|
-
@mt = MT19937.allocate
|
289
|
-
@mt.marshal_load(ary)
|
290
|
-
end
|
291
|
-
|
292
|
-
private
|
293
|
-
|
294
|
-
def state
|
295
|
-
@mt.state_as_bignum
|
296
|
-
end
|
297
|
-
|
298
|
-
def left
|
299
|
-
@mt.left
|
300
|
-
end
|
301
|
-
|
302
|
-
def _rand_range(limit)
|
303
|
-
range = limit.end - limit.begin
|
304
|
-
if (!range.is_a?(Float)) && range.respond_to?(:to_int) && range = Backports.coerce_to_int(range)
|
305
|
-
range += 1 unless limit.exclude_end?
|
306
|
-
limit.begin + @mt.random_integer(range) unless range <= 0
|
307
|
-
elsif range = Backports.coerce_to(range, Float, :to_f)
|
308
|
-
if range < 0
|
309
|
-
nil
|
310
|
-
elsif limit.exclude_end?
|
311
|
-
limit.begin + @mt.random_float * range unless range <= 0
|
312
|
-
else
|
313
|
-
# cheat a bit... this will reduce the nb of random bits
|
314
|
-
loop do
|
315
|
-
r = @mt.random_float * range * 1.0001
|
316
|
-
break limit.begin + r unless r > range
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
def self.new_seed
|
324
|
-
(2 ** 62) + Kernel.rand(2 ** 62)
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
class Random
|
329
|
-
include Implementation
|
330
|
-
class << self
|
331
|
-
include Implementation
|
332
|
-
end
|
333
|
-
end
|
334
|
-
end
|
335
|
-
end
|
336
|
-
end
|