rspec-core 2.99.0 → 3.0.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 +8 -8
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +1 -0
- data/Changelog.md +339 -1
- data/License.txt +1 -0
- data/README.md +19 -37
- data/exe/rspec +2 -23
- data/lib/rspec/core/backport_random.rb +336 -0
- data/lib/rspec/core/backtrace_formatter.rb +70 -0
- data/lib/rspec/core/configuration.rb +479 -577
- data/lib/rspec/core/configuration_options.rb +71 -54
- data/lib/rspec/core/drb.rb +111 -0
- data/lib/rspec/core/dsl.rb +86 -18
- data/lib/rspec/core/example.rb +267 -119
- data/lib/rspec/core/example_group.rb +381 -393
- data/lib/rspec/core/filter_manager.rb +133 -114
- data/lib/rspec/core/flat_map.rb +18 -0
- data/lib/rspec/core/formatters/base_formatter.rb +51 -125
- data/lib/rspec/core/formatters/base_text_formatter.rb +34 -286
- data/lib/rspec/core/formatters/console_codes.rb +24 -1
- data/lib/rspec/core/formatters/deprecation_formatter.rb +25 -26
- data/lib/rspec/core/formatters/documentation_formatter.rb +27 -25
- data/lib/rspec/core/formatters/helpers.rb +14 -36
- data/lib/rspec/core/formatters/html_formatter.rb +58 -65
- data/lib/rspec/core/formatters/html_printer.rb +12 -18
- data/lib/rspec/core/formatters/json_formatter.rb +54 -31
- data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +11 -15
- data/lib/rspec/core/formatters/snippet_extractor.rb +22 -11
- data/lib/rspec/core/formatters.rb +90 -43
- data/lib/rspec/core/hooks.rb +325 -270
- data/lib/rspec/core/memoized_helpers.rb +45 -156
- data/lib/rspec/core/metadata.rb +284 -236
- data/lib/rspec/core/metadata_filter.rb +86 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
- data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
- data/lib/rspec/core/mocking_adapters/null.rb +12 -0
- data/lib/rspec/core/mocking_adapters/rr.rb +29 -0
- data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
- data/lib/rspec/core/notifications.rb +511 -0
- data/lib/rspec/core/option_parser.rb +49 -74
- data/lib/rspec/core/ordering.rb +156 -0
- data/lib/rspec/core/pending.rb +94 -96
- data/lib/rspec/core/project_initializer/.rspec +3 -0
- data/lib/rspec/core/project_initializer/spec/spec_helper.rb +78 -0
- data/lib/rspec/core/project_initializer.rb +24 -64
- data/lib/rspec/core/rake_task.rb +44 -130
- data/lib/rspec/core/reporter.rb +76 -59
- data/lib/rspec/core/ruby_project.rb +2 -1
- data/lib/rspec/core/runner.rb +117 -52
- data/lib/rspec/core/shared_context.rb +10 -10
- data/lib/rspec/core/shared_example_group.rb +108 -121
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +40 -0
- data/lib/rspec/core/world.rb +66 -10
- data/lib/rspec/core.rb +64 -104
- data.tar.gz.sig +3 -0
- metadata +75 -322
- metadata.gz.sig +1 -0
- data/exe/autospec +0 -13
- data/features/Autotest.md +0 -38
- data/features/README.md +0 -17
- data/features/Upgrade.md +0 -364
- data/features/command_line/README.md +0 -28
- data/features/command_line/example_name_option.feature +0 -97
- data/features/command_line/exit_status.feature +0 -82
- data/features/command_line/format_option.feature +0 -75
- data/features/command_line/init.feature +0 -18
- data/features/command_line/line_number_appended_to_path.feature +0 -140
- data/features/command_line/line_number_option.feature +0 -53
- data/features/command_line/order.feature +0 -26
- data/features/command_line/pattern_option.feature +0 -49
- data/features/command_line/rake_task.feature +0 -122
- data/features/command_line/require_option.feature +0 -43
- data/features/command_line/ruby.feature +0 -22
- data/features/command_line/tag.feature +0 -98
- data/features/command_line/warnings_option.feature +0 -29
- data/features/configuration/alias_example_to.feature +0 -48
- data/features/configuration/backtrace_clean_patterns.feature +0 -102
- data/features/configuration/custom_settings.feature +0 -84
- data/features/configuration/default_path.feature +0 -38
- data/features/configuration/deprecation_stream.feature +0 -58
- data/features/configuration/fail_fast.feature +0 -77
- data/features/configuration/failure_exit_code.feature +0 -36
- data/features/configuration/order_and_seed.feature +0 -3
- data/features/configuration/output_stream.feature +0 -24
- data/features/configuration/pattern.feature +0 -38
- data/features/configuration/profile.feature +0 -220
- data/features/configuration/read_options_from_file.feature +0 -90
- data/features/configuration/run_all_when_everything_filtered.feature +0 -76
- data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
- data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
- data/features/example_groups/basic_structure.feature +0 -55
- data/features/example_groups/shared_context.feature +0 -74
- data/features/example_groups/shared_examples.feature +0 -294
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -197
- data/features/filtering/exclusion_filters.feature +0 -138
- data/features/filtering/if_and_unless.feature +0 -168
- data/features/filtering/inclusion_filters.feature +0 -105
- data/features/formatters/configurable_colors.feature +0 -31
- data/features/formatters/custom_formatter.feature +0 -36
- data/features/formatters/json_formatter.feature +0 -30
- data/features/formatters/text_formatter.feature +0 -46
- data/features/helper_methods/arbitrary_methods.feature +0 -40
- data/features/helper_methods/let.feature +0 -50
- data/features/helper_methods/modules.feature +0 -149
- data/features/hooks/around_hooks.feature +0 -343
- data/features/hooks/before_and_after_hooks.feature +0 -427
- data/features/hooks/filtering.feature +0 -234
- data/features/metadata/current_example.feature +0 -56
- data/features/metadata/described_class.feature +0 -17
- data/features/metadata/user_defined.feature +0 -113
- data/features/mock_framework_integration/use_any_framework.feature +0 -106
- data/features/mock_framework_integration/use_flexmock.feature +0 -96
- data/features/mock_framework_integration/use_mocha.feature +0 -97
- data/features/mock_framework_integration/use_rr.feature +0 -98
- data/features/mock_framework_integration/use_rspec.feature +0 -97
- data/features/pending/pending_examples.feature +0 -229
- data/features/spec_files/arbitrary_file_suffix.feature +0 -13
- data/features/step_definitions/additional_cli_steps.rb +0 -49
- data/features/subject/attribute_of_subject.feature +0 -124
- data/features/subject/explicit_subject.feature +0 -101
- data/features/subject/implicit_subject.feature +0 -63
- data/features/subject/one_liner_syntax.feature +0 -71
- data/features/support/env.rb +0 -14
- data/features/support/rubinius.rb +0 -6
- data/lib/autotest/discover.rb +0 -10
- data/lib/autotest/rspec2.rb +0 -77
- data/lib/rspec/core/backtrace_cleaner.rb +0 -46
- data/lib/rspec/core/backward_compatibility.rb +0 -55
- data/lib/rspec/core/caller_filter.rb +0 -60
- data/lib/rspec/core/command_line.rb +0 -47
- data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
- data/lib/rspec/core/deprecation.rb +0 -26
- data/lib/rspec/core/drb_command_line.rb +0 -26
- data/lib/rspec/core/drb_options.rb +0 -87
- data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
- data/lib/rspec/core/extensions/kernel.rb +0 -9
- data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
- data/lib/rspec/core/extensions/ordered.rb +0 -27
- data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
- data/lib/rspec/core/metadata_hash_builder.rb +0 -97
- data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
- data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
- data/lib/rspec/core/mocking/with_rr.rb +0 -27
- data/lib/rspec/core/mocking/with_rspec.rb +0 -27
- data/lib/rspec/core/shared_example_group/collection.rb +0 -45
- data/spec/autotest/discover_spec.rb +0 -49
- data/spec/autotest/failed_results_re_spec.rb +0 -45
- data/spec/autotest/rspec_spec.rb +0 -133
- data/spec/command_line/order_spec.rb +0 -204
- data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
- data/spec/rspec/core/caller_filter_spec.rb +0 -58
- data/spec/rspec/core/command_line_spec.rb +0 -127
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -417
- data/spec/rspec/core/configuration_spec.rb +0 -2072
- data/spec/rspec/core/deprecation_spec.rb +0 -27
- data/spec/rspec/core/deprecations_spec.rb +0 -59
- data/spec/rspec/core/drb_command_line_spec.rb +0 -102
- data/spec/rspec/core/drb_options_spec.rb +0 -193
- data/spec/rspec/core/dsl_spec.rb +0 -25
- data/spec/rspec/core/example_group_spec.rb +0 -1337
- data/spec/rspec/core/example_spec.rb +0 -502
- data/spec/rspec/core/filter_manager_spec.rb +0 -246
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -108
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -524
- data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -263
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -89
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
- data/spec/rspec/core/formatters/html_formatted.html +0 -397
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -131
- data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -115
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
- data/spec/rspec/core/formatters/text_mate_formatted.html +0 -397
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -269
- data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
- data/spec/rspec/core/memoized_helpers_spec.rb +0 -776
- data/spec/rspec/core/metadata_spec.rb +0 -514
- data/spec/rspec/core/option_parser_spec.rb +0 -297
- data/spec/rspec/core/pending_example_spec.rb +0 -260
- data/spec/rspec/core/pending_spec.rb +0 -27
- data/spec/rspec/core/project_initializer_spec.rb +0 -130
- data/spec/rspec/core/rake_task_spec.rb +0 -202
- data/spec/rspec/core/reporter_spec.rb +0 -167
- data/spec/rspec/core/resources/a_bar.rb +0 -0
- data/spec/rspec/core/resources/a_foo.rb +0 -0
- data/spec/rspec/core/resources/a_spec.rb +0 -1
- data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
- data/spec/rspec/core/resources/formatter_specs.rb +0 -60
- data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
- data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
- data/spec/rspec/core/ruby_project_spec.rb +0 -26
- data/spec/rspec/core/runner_spec.rb +0 -82
- data/spec/rspec/core/shared_context_spec.rb +0 -114
- data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -70
- data/spec/rspec/core/shared_example_group_spec.rb +0 -138
- data/spec/rspec/core/world_spec.rb +0 -142
- data/spec/rspec/core_spec.rb +0 -108
- data/spec/spec_helper.rb +0 -135
- data/spec/support/config_options_helper.rb +0 -15
- data/spec/support/helper_methods.rb +0 -55
- data/spec/support/in_sub_process.rb +0 -37
- data/spec/support/isolate_load_path_mutation.rb +0 -6
- data/spec/support/isolated_directory.rb +0 -10
- data/spec/support/isolated_home_directory.rb +0 -16
- data/spec/support/matchers.rb +0 -65
- data/spec/support/mathn_integration_support.rb +0 -12
- data/spec/support/sandboxed_mock_space.rb +0 -116
- data/spec/support/shared_example_groups.rb +0 -42
- data/spec/support/silence_dsl_deprecations.rb +0 -32
- data/spec/support/spec_files.rb +0 -44
|
@@ -0,0 +1,336 @@
|
|
|
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
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module RSpec
|
|
2
|
+
module Core
|
|
3
|
+
# @private
|
|
4
|
+
class BacktraceFormatter
|
|
5
|
+
# @private
|
|
6
|
+
attr_accessor :exclusion_patterns, :inclusion_patterns
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@full_backtrace = false
|
|
10
|
+
|
|
11
|
+
patterns = [
|
|
12
|
+
"/lib\d*/ruby/",
|
|
13
|
+
"org/jruby/",
|
|
14
|
+
"bin/",
|
|
15
|
+
"/gems/",
|
|
16
|
+
].map { |s| Regexp.new(s.gsub("/", File::SEPARATOR)) }
|
|
17
|
+
|
|
18
|
+
@system_exclusion_patterns = [Regexp.union(RSpec::CallerFilter::IGNORE_REGEX, *patterns)]
|
|
19
|
+
@exclusion_patterns = [] + @system_exclusion_patterns
|
|
20
|
+
@inclusion_patterns = [Regexp.new(Dir.getwd)]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def full_backtrace=(full_backtrace)
|
|
24
|
+
@full_backtrace = full_backtrace
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def full_backtrace?
|
|
28
|
+
@full_backtrace || @exclusion_patterns.empty?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def format_backtrace(backtrace, options = {})
|
|
32
|
+
return backtrace if options[:full_backtrace]
|
|
33
|
+
|
|
34
|
+
backtrace.map { |l| backtrace_line(l) }.compact.
|
|
35
|
+
tap do |filtered|
|
|
36
|
+
if filtered.empty?
|
|
37
|
+
filtered.concat backtrace
|
|
38
|
+
filtered << ""
|
|
39
|
+
filtered << " Showing full backtrace because every line was filtered out."
|
|
40
|
+
filtered << " See docs for RSpec::Configuration#backtrace_exclusion_patterns and"
|
|
41
|
+
filtered << " RSpec::Configuration#backtrace_inclusion_patterns for more information."
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def backtrace_line(line)
|
|
47
|
+
RSpec::Core::Metadata::relative_path(line) unless exclude?(line)
|
|
48
|
+
rescue SecurityError
|
|
49
|
+
nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def exclude?(line)
|
|
53
|
+
return false if @full_backtrace
|
|
54
|
+
matches_an_exclusion_pattern?(line) &&
|
|
55
|
+
doesnt_match_inclusion_pattern_unless_system_exclusion?(line)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def matches_an_exclusion_pattern?(line)
|
|
61
|
+
@exclusion_patterns.any? { |p| line =~ p }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def doesnt_match_inclusion_pattern_unless_system_exclusion?(line)
|
|
65
|
+
@system_exclusion_patterns.any? { |p| line =~ p } || @inclusion_patterns.none? { |p| p =~ line }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|