activesupport 4.2.11.1 → 6.0.3.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.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +399 -411
- data/MIT-LICENSE +2 -2
- data/README.rdoc +7 -7
- data/lib/active_support/actionable_error.rb +48 -0
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +34 -6
- data/lib/active_support/benchmarkable.rb +6 -4
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache/file_store.rb +58 -53
- data/lib/active_support/cache/mem_cache_store.rb +95 -91
- data/lib/active_support/cache/memory_store.rb +39 -36
- data/lib/active_support/cache/null_store.rb +11 -7
- data/lib/active_support/cache/redis_cache_store.rb +493 -0
- data/lib/active_support/cache/strategy/local_cache.rb +75 -42
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
- data/lib/active_support/cache.rb +331 -217
- data/lib/active_support/callbacks.rb +650 -592
- data/lib/active_support/concern.rb +35 -6
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
- data/lib/active_support/concurrency/share_lock.rb +226 -0
- data/lib/active_support/configurable.rb +13 -14
- data/lib/active_support/core_ext/array/access.rb +41 -1
- data/lib/active_support/core_ext/array/conversions.rb +24 -20
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +11 -18
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -6
- data/lib/active_support/core_ext/array/wrap.rb +7 -4
- data/lib/active_support/core_ext/array.rb +9 -6
- data/lib/active_support/core_ext/benchmark.rb +3 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
- data/lib/active_support/core_ext/big_decimal.rb +3 -1
- data/lib/active_support/core_ext/class/attribute.rb +45 -31
- data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
- data/lib/active_support/core_ext/class/subclasses.rb +20 -6
- data/lib/active_support/core_ext/class.rb +4 -3
- data/lib/active_support/core_ext/date/acts_like.rb +3 -1
- data/lib/active_support/core_ext/date/blank.rb +14 -0
- data/lib/active_support/core_ext/date/calculations.rb +17 -14
- data/lib/active_support/core_ext/date/conversions.rb +25 -23
- data/lib/active_support/core_ext/date/zones.rb +4 -2
- data/lib/active_support/core_ext/date.rb +6 -4
- data/lib/active_support/core_ext/date_and_time/calculations.rb +154 -65
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +4 -3
- data/lib/active_support/core_ext/date_and_time/zones.rb +12 -13
- data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
- data/lib/active_support/core_ext/date_time/blank.rb +14 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +37 -19
- data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
- data/lib/active_support/core_ext/date_time/conversions.rb +16 -13
- data/lib/active_support/core_ext/date_time.rb +7 -5
- data/lib/active_support/core_ext/digest/uuid.rb +7 -5
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +114 -22
- data/lib/active_support/core_ext/file/atomic.rb +38 -31
- data/lib/active_support/core_ext/file.rb +3 -1
- data/lib/active_support/core_ext/hash/compact.rb +4 -23
- data/lib/active_support/core_ext/hash/conversions.rb +62 -41
- data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +12 -9
- data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
- data/lib/active_support/core_ext/hash/keys.rb +19 -42
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +5 -27
- data/lib/active_support/core_ext/hash/transform_values.rb +4 -22
- data/lib/active_support/core_ext/hash.rb +10 -9
- data/lib/active_support/core_ext/integer/inflections.rb +3 -1
- data/lib/active_support/core_ext/integer/multiple.rb +3 -1
- data/lib/active_support/core_ext/integer/time.rb +11 -18
- data/lib/active_support/core_ext/integer.rb +5 -3
- data/lib/active_support/core_ext/kernel/concern.rb +5 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +5 -5
- data/lib/active_support/core_ext/load_error.rb +3 -22
- data/lib/active_support/core_ext/marshal.rb +8 -8
- data/lib/active_support/core_ext/module/aliasing.rb +6 -44
- data/lib/active_support/core_ext/module/anonymous.rb +12 -1
- data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
- data/lib/active_support/core_ext/module/attribute_accessors.rb +46 -46
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +144 -0
- data/lib/active_support/core_ext/module/concerning.rb +11 -12
- data/lib/active_support/core_ext/module/delegation.rb +133 -30
- data/lib/active_support/core_ext/module/deprecation.rb +4 -2
- data/lib/active_support/core_ext/module/introspection.rb +44 -19
- data/lib/active_support/core_ext/module/reachable.rb +5 -7
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +8 -3
- data/lib/active_support/core_ext/module.rb +13 -11
- data/lib/active_support/core_ext/name_error.rb +22 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +129 -136
- data/lib/active_support/core_ext/numeric/inquiry.rb +5 -0
- data/lib/active_support/core_ext/numeric/time.rb +35 -23
- data/lib/active_support/core_ext/numeric.rb +5 -3
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +27 -3
- data/lib/active_support/core_ext/object/conversions.rb +6 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
- data/lib/active_support/core_ext/object/duplicable.rb +13 -93
- data/lib/active_support/core_ext/object/inclusion.rb +5 -3
- data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
- data/lib/active_support/core_ext/object/json.rb +51 -20
- data/lib/active_support/core_ext/object/to_param.rb +3 -1
- data/lib/active_support/core_ext/object/to_query.rb +10 -5
- data/lib/active_support/core_ext/object/try.rb +81 -23
- data/lib/active_support/core_ext/object/with_options.rb +16 -3
- data/lib/active_support/core_ext/object.rb +14 -13
- data/lib/active_support/core_ext/range/compare_range.rb +76 -0
- data/lib/active_support/core_ext/range/conversions.rb +37 -15
- data/lib/active_support/core_ext/range/each.rb +18 -17
- data/lib/active_support/core_ext/range/include_range.rb +7 -21
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
- data/lib/active_support/core_ext/range/overlaps.rb +2 -0
- data/lib/active_support/core_ext/range.rb +7 -4
- data/lib/active_support/core_ext/regexp.rb +2 -0
- data/lib/active_support/core_ext/securerandom.rb +45 -0
- data/lib/active_support/core_ext/string/access.rb +16 -6
- data/lib/active_support/core_ext/string/behavior.rb +3 -1
- data/lib/active_support/core_ext/string/conversions.rb +7 -4
- data/lib/active_support/core_ext/string/exclude.rb +2 -0
- data/lib/active_support/core_ext/string/filters.rb +48 -6
- data/lib/active_support/core_ext/string/indent.rb +6 -4
- data/lib/active_support/core_ext/string/inflections.rb +66 -24
- data/lib/active_support/core_ext/string/inquiry.rb +3 -1
- data/lib/active_support/core_ext/string/multibyte.rb +16 -7
- data/lib/active_support/core_ext/string/output_safety.rb +93 -40
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +6 -5
- data/lib/active_support/core_ext/string/zones.rb +4 -2
- data/lib/active_support/core_ext/string.rb +15 -13
- data/lib/active_support/core_ext/time/acts_like.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +115 -52
- data/lib/active_support/core_ext/time/compatibility.rb +4 -2
- data/lib/active_support/core_ext/time/conversions.rb +20 -13
- data/lib/active_support/core_ext/time/zones.rb +41 -7
- data/lib/active_support/core_ext/time.rb +7 -6
- data/lib/active_support/core_ext/uri.rb +6 -7
- data/lib/active_support/core_ext.rb +3 -1
- data/lib/active_support/current_attributes.rb +203 -0
- data/lib/active_support/dependencies/autoload.rb +2 -0
- data/lib/active_support/dependencies/interlock.rb +57 -0
- data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
- data/lib/active_support/dependencies.rb +208 -166
- data/lib/active_support/deprecation/behaviors.rb +44 -11
- data/lib/active_support/deprecation/constant_accessor.rb +52 -0
- data/lib/active_support/deprecation/instance_delegator.rb +17 -2
- data/lib/active_support/deprecation/method_wrappers.rb +61 -21
- data/lib/active_support/deprecation/proxy_wrappers.rb +81 -30
- data/lib/active_support/deprecation/reporting.rb +32 -12
- data/lib/active_support/deprecation.rb +12 -9
- data/lib/active_support/descendants_tracker.rb +57 -9
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration/iso8601_parser.rb +123 -0
- data/lib/active_support/duration/iso8601_serializer.rb +53 -0
- data/lib/active_support/duration.rb +315 -40
- data/lib/active_support/encrypted_configuration.rb +45 -0
- data/lib/active_support/encrypted_file.rb +100 -0
- data/lib/active_support/evented_file_update_checker.rb +234 -0
- data/lib/active_support/execution_wrapper.rb +129 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +62 -37
- data/lib/active_support/gem_version.rb +6 -4
- data/lib/active_support/gzip.rb +7 -5
- data/lib/active_support/hash_with_indifferent_access.rb +129 -30
- data/lib/active_support/i18n.rb +9 -6
- data/lib/active_support/i18n_railtie.rb +50 -14
- data/lib/active_support/inflections.rb +13 -11
- data/lib/active_support/inflector/inflections.rb +58 -13
- data/lib/active_support/inflector/methods.rb +159 -145
- data/lib/active_support/inflector/transliterate.rb +84 -34
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/json/decoding.rb +32 -30
- data/lib/active_support/json/encoding.rb +17 -60
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/key_generator.rb +11 -43
- data/lib/active_support/lazy_load_hooks.rb +53 -20
- data/lib/active_support/locale/en.rb +33 -0
- data/lib/active_support/locale/en.yml +2 -0
- data/lib/active_support/log_subscriber/test_helper.rb +14 -12
- data/lib/active_support/log_subscriber.rb +44 -19
- data/lib/active_support/logger.rb +9 -23
- data/lib/active_support/logger_silence.rb +32 -14
- data/lib/active_support/logger_thread_safe_level.rb +32 -8
- data/lib/active_support/message_encryptor.rb +166 -53
- data/lib/active_support/message_verifier.rb +149 -16
- data/lib/active_support/messages/metadata.rb +72 -0
- data/lib/active_support/messages/rotation_configuration.rb +22 -0
- data/lib/active_support/messages/rotator.rb +56 -0
- data/lib/active_support/multibyte/chars.rb +56 -63
- data/lib/active_support/multibyte/unicode.rb +56 -290
- data/lib/active_support/multibyte.rb +4 -2
- data/lib/active_support/notifications/fanout.rb +109 -22
- data/lib/active_support/notifications/instrumenter.rb +107 -16
- data/lib/active_support/notifications.rb +51 -10
- data/lib/active_support/number_helper/number_converter.rb +16 -15
- data/lib/active_support/number_helper/number_to_currency_converter.rb +14 -15
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +11 -4
- data/lib/active_support/number_helper/number_to_human_converter.rb +13 -10
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +11 -9
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +15 -5
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +25 -57
- data/lib/active_support/number_helper/rounding_helper.rb +66 -0
- data/lib/active_support/number_helper.rb +105 -68
- data/lib/active_support/option_merger.rb +24 -4
- data/lib/active_support/ordered_hash.rb +7 -5
- data/lib/active_support/ordered_options.rb +27 -5
- data/lib/active_support/parameter_filter.rb +128 -0
- data/lib/active_support/per_thread_registry.rb +9 -4
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +10 -8
- data/lib/active_support/railtie.rb +43 -9
- data/lib/active_support/reloader.rb +130 -0
- data/lib/active_support/rescuable.rb +108 -53
- data/lib/active_support/security_utils.rb +15 -11
- data/lib/active_support/string_inquirer.rb +11 -4
- data/lib/active_support/subscriber.rb +74 -30
- data/lib/active_support/tagged_logging.rb +25 -13
- data/lib/active_support/test_case.rb +107 -44
- data/lib/active_support/testing/assertions.rb +151 -20
- data/lib/active_support/testing/autorun.rb +4 -2
- data/lib/active_support/testing/constant_lookup.rb +2 -1
- data/lib/active_support/testing/declarative.rb +3 -1
- data/lib/active_support/testing/deprecation.rb +13 -10
- data/lib/active_support/testing/file_fixtures.rb +38 -0
- data/lib/active_support/testing/isolation.rb +35 -26
- data/lib/active_support/testing/method_call_assertions.rb +70 -0
- data/lib/active_support/testing/parallelization.rb +134 -0
- data/lib/active_support/testing/setup_and_teardown.rb +13 -8
- data/lib/active_support/testing/stream.rb +43 -0
- data/lib/active_support/testing/tagged_logging.rb +3 -1
- data/lib/active_support/testing/time_helpers.rb +84 -20
- data/lib/active_support/time.rb +14 -12
- data/lib/active_support/time_with_zone.rb +179 -39
- data/lib/active_support/values/time_zone.rb +203 -63
- data/lib/active_support/version.rb +3 -1
- data/lib/active_support/xml_mini/jdom.rb +116 -115
- data/lib/active_support/xml_mini/libxml.rb +16 -13
- data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
- data/lib/active_support/xml_mini/nokogiri.rb +14 -12
- data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
- data/lib/active_support/xml_mini/rexml.rb +11 -9
- data/lib/active_support/xml_mini.rb +38 -46
- data/lib/active_support.rb +13 -11
- metadata +84 -26
- data/lib/active_support/concurrency/latch.rb +0 -27
- data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
- data/lib/active_support/core_ext/date_time/zones.rb +0 -6
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
- data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
- data/lib/active_support/core_ext/object/itself.rb +0 -15
- data/lib/active_support/core_ext/struct.rb +0 -6
- data/lib/active_support/core_ext/thread.rb +0 -86
- data/lib/active_support/core_ext/time/marshal.rb +0 -30
- data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveSupport
|
2
4
|
module Testing
|
3
5
|
module Declarative
|
@@ -9,7 +11,7 @@ module ActiveSupport
|
|
9
11
|
# ...
|
10
12
|
# end
|
11
13
|
def test(name, &block)
|
12
|
-
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
14
|
+
test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym
|
13
15
|
defined = method_defined? test_name
|
14
16
|
raise "#{test_name} is already defined in #{self}" if defined
|
15
17
|
if block_given?
|
@@ -1,34 +1,37 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/deprecation"
|
2
4
|
|
3
5
|
module ActiveSupport
|
4
6
|
module Testing
|
5
7
|
module Deprecation #:nodoc:
|
6
|
-
def assert_deprecated(match = nil, &block)
|
7
|
-
result, warnings = collect_deprecations(&block)
|
8
|
+
def assert_deprecated(match = nil, deprecator = nil, &block)
|
9
|
+
result, warnings = collect_deprecations(deprecator, &block)
|
8
10
|
assert !warnings.empty?, "Expected a deprecation warning within the block but received none"
|
9
11
|
if match
|
10
12
|
match = Regexp.new(Regexp.escape(match)) unless match.is_a?(Regexp)
|
11
|
-
assert warnings.any? { |w| w
|
13
|
+
assert warnings.any? { |w| match.match?(w) }, "No deprecation warning matched #{match}: #{warnings.join(', ')}"
|
12
14
|
end
|
13
15
|
result
|
14
16
|
end
|
15
17
|
|
16
|
-
def assert_not_deprecated(&block)
|
17
|
-
result, deprecations = collect_deprecations(&block)
|
18
|
+
def assert_not_deprecated(deprecator = nil, &block)
|
19
|
+
result, deprecations = collect_deprecations(deprecator, &block)
|
18
20
|
assert deprecations.empty?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n #{deprecations * "\n "}"
|
19
21
|
result
|
20
22
|
end
|
21
23
|
|
22
|
-
def collect_deprecations
|
23
|
-
|
24
|
+
def collect_deprecations(deprecator = nil)
|
25
|
+
deprecator ||= ActiveSupport::Deprecation
|
26
|
+
old_behavior = deprecator.behavior
|
24
27
|
deprecations = []
|
25
|
-
|
28
|
+
deprecator.behavior = Proc.new do |message, callstack|
|
26
29
|
deprecations << message
|
27
30
|
end
|
28
31
|
result = yield
|
29
32
|
[result, deprecations]
|
30
33
|
ensure
|
31
|
-
|
34
|
+
deprecator.behavior = old_behavior
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
module Testing
|
7
|
+
# Adds simple access to sample files called file fixtures.
|
8
|
+
# File fixtures are normal files stored in
|
9
|
+
# <tt>ActiveSupport::TestCase.file_fixture_path</tt>.
|
10
|
+
#
|
11
|
+
# File fixtures are represented as +Pathname+ objects.
|
12
|
+
# This makes it easy to extract specific information:
|
13
|
+
#
|
14
|
+
# file_fixture("example.txt").read # get the file's content
|
15
|
+
# file_fixture("example.mp3").size # get the file size
|
16
|
+
module FileFixtures
|
17
|
+
extend ActiveSupport::Concern
|
18
|
+
|
19
|
+
included do
|
20
|
+
class_attribute :file_fixture_path, instance_writer: false
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns a +Pathname+ to the fixture file named +fixture_name+.
|
24
|
+
#
|
25
|
+
# Raises +ArgumentError+ if +fixture_name+ can't be found.
|
26
|
+
def file_fixture(fixture_name)
|
27
|
+
path = Pathname.new(File.join(file_fixture_path, fixture_name))
|
28
|
+
|
29
|
+
if path.exist?
|
30
|
+
path
|
31
|
+
else
|
32
|
+
msg = "the directory '%s' does not contain a file named '%s'"
|
33
|
+
raise ArgumentError, msg % [file_fixture_path, fixture_name]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveSupport
|
4
4
|
module Testing
|
5
5
|
module Isolation
|
6
|
-
require
|
6
|
+
require "thread"
|
7
7
|
|
8
8
|
def self.included(klass) #:nodoc:
|
9
9
|
klass.class_eval do
|
@@ -12,18 +12,7 @@ module ActiveSupport
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.forking_env?
|
15
|
-
!ENV["NO_FORK"] && (
|
16
|
-
end
|
17
|
-
|
18
|
-
@@class_setup_mutex = Mutex.new
|
19
|
-
|
20
|
-
def _run_class_setup # class setup method should only happen in parent
|
21
|
-
@@class_setup_mutex.synchronize do
|
22
|
-
unless defined?(@@ran_class_setup) || ENV['ISOLATION_TEST']
|
23
|
-
self.class.setup if self.class.respond_to?(:setup)
|
24
|
-
@@ran_class_setup = true
|
25
|
-
end
|
26
|
-
end
|
15
|
+
!ENV["NO_FORK"] && Process.respond_to?(:fork)
|
27
16
|
end
|
28
17
|
|
29
18
|
def run
|
@@ -43,14 +32,31 @@ module ActiveSupport
|
|
43
32
|
pid = fork do
|
44
33
|
read.close
|
45
34
|
yield
|
46
|
-
|
35
|
+
begin
|
36
|
+
if error?
|
37
|
+
failures.map! { |e|
|
38
|
+
begin
|
39
|
+
Marshal.dump e
|
40
|
+
e
|
41
|
+
rescue TypeError
|
42
|
+
ex = Exception.new e.message
|
43
|
+
ex.set_backtrace e.backtrace
|
44
|
+
Minitest::UnexpectedError.new ex
|
45
|
+
end
|
46
|
+
}
|
47
|
+
end
|
48
|
+
test_result = defined?(Minitest::Result) ? Minitest::Result.from(self) : dup
|
49
|
+
result = Marshal.dump(test_result)
|
50
|
+
end
|
51
|
+
|
52
|
+
write.puts [result].pack("m")
|
47
53
|
exit!
|
48
54
|
end
|
49
55
|
|
50
56
|
write.close
|
51
57
|
result = read.read
|
52
58
|
Process.wait2(pid)
|
53
|
-
|
59
|
+
result.unpack1("m")
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
@@ -64,24 +70,27 @@ module ActiveSupport
|
|
64
70
|
|
65
71
|
if ENV["ISOLATION_TEST"]
|
66
72
|
yield
|
73
|
+
test_result = defined?(Minitest::Result) ? Minitest::Result.from(self) : dup
|
67
74
|
File.open(ENV["ISOLATION_OUTPUT"], "w") do |file|
|
68
|
-
file.puts [Marshal.dump(
|
75
|
+
file.puts [Marshal.dump(test_result)].pack("m")
|
69
76
|
end
|
70
77
|
exit!
|
71
78
|
else
|
72
79
|
Tempfile.open("isolation") do |tmpfile|
|
73
80
|
env = {
|
74
|
-
ISOLATION_TEST
|
75
|
-
ISOLATION_OUTPUT
|
81
|
+
"ISOLATION_TEST" => self.class.name,
|
82
|
+
"ISOLATION_OUTPUT" => tmpfile.path
|
76
83
|
}
|
77
84
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
85
|
+
test_opts = "-n#{self.class.name}##{name}"
|
86
|
+
|
87
|
+
load_path_args = []
|
88
|
+
$-I.each do |p|
|
89
|
+
load_path_args << "-I"
|
90
|
+
load_path_args << File.expand_path(p)
|
91
|
+
end
|
82
92
|
|
83
|
-
|
84
|
-
child = IO.popen([env, command])
|
93
|
+
child = IO.popen([env, Gem.ruby, *load_path_args, $0, *ORIG_ARGV, test_opts])
|
85
94
|
|
86
95
|
begin
|
87
96
|
Process.wait(child.pid)
|
@@ -89,7 +98,7 @@ module ActiveSupport
|
|
89
98
|
nil
|
90
99
|
end
|
91
100
|
|
92
|
-
return tmpfile.read.
|
101
|
+
return tmpfile.read.unpack1("m")
|
93
102
|
end
|
94
103
|
end
|
95
104
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "minitest/mock"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
module Testing
|
7
|
+
module MethodCallAssertions # :nodoc:
|
8
|
+
private
|
9
|
+
def assert_called(object, method_name, message = nil, times: 1, returns: nil)
|
10
|
+
times_called = 0
|
11
|
+
|
12
|
+
object.stub(method_name, proc { times_called += 1; returns }) { yield }
|
13
|
+
|
14
|
+
error = "Expected #{method_name} to be called #{times} times, " \
|
15
|
+
"but was called #{times_called} times"
|
16
|
+
error = "#{message}.\n#{error}" if message
|
17
|
+
assert_equal times, times_called, error
|
18
|
+
end
|
19
|
+
|
20
|
+
def assert_called_with(object, method_name, args, returns: nil)
|
21
|
+
mock = Minitest::Mock.new
|
22
|
+
|
23
|
+
if args.all? { |arg| arg.is_a?(Array) }
|
24
|
+
args.each { |arg| mock.expect(:call, returns, arg) }
|
25
|
+
else
|
26
|
+
mock.expect(:call, returns, args)
|
27
|
+
end
|
28
|
+
|
29
|
+
object.stub(method_name, mock) { yield }
|
30
|
+
|
31
|
+
mock.verify
|
32
|
+
end
|
33
|
+
|
34
|
+
def assert_not_called(object, method_name, message = nil, &block)
|
35
|
+
assert_called(object, method_name, message, times: 0, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_called_on_instance_of(klass, method_name, message = nil, times: 1, returns: nil)
|
39
|
+
times_called = 0
|
40
|
+
klass.define_method("stubbed_#{method_name}") do |*|
|
41
|
+
times_called += 1
|
42
|
+
|
43
|
+
returns
|
44
|
+
end
|
45
|
+
|
46
|
+
klass.alias_method "original_#{method_name}", method_name
|
47
|
+
klass.alias_method method_name, "stubbed_#{method_name}"
|
48
|
+
|
49
|
+
yield
|
50
|
+
|
51
|
+
error = "Expected #{method_name} to be called #{times} times, but was called #{times_called} times"
|
52
|
+
error = "#{message}.\n#{error}" if message
|
53
|
+
|
54
|
+
assert_equal times, times_called, error
|
55
|
+
ensure
|
56
|
+
klass.alias_method method_name, "original_#{method_name}"
|
57
|
+
klass.undef_method "original_#{method_name}"
|
58
|
+
klass.undef_method "stubbed_#{method_name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def assert_not_called_on_instance_of(klass, method_name, message = nil, &block)
|
62
|
+
assert_called_on_instance_of(klass, method_name, message, times: 0, &block)
|
63
|
+
end
|
64
|
+
|
65
|
+
def stub_any_instance(klass, instance: klass.new)
|
66
|
+
klass.stub(:new, instance) { yield instance }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "drb"
|
4
|
+
require "drb/unix" unless Gem.win_platform?
|
5
|
+
require "active_support/core_ext/module/attribute_accessors"
|
6
|
+
|
7
|
+
module ActiveSupport
|
8
|
+
module Testing
|
9
|
+
class Parallelization # :nodoc:
|
10
|
+
class Server
|
11
|
+
include DRb::DRbUndumped
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@queue = Queue.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def record(reporter, result)
|
18
|
+
raise DRb::DRbConnError if result.is_a?(DRb::DRbUnknown)
|
19
|
+
|
20
|
+
reporter.synchronize do
|
21
|
+
reporter.record(result)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def <<(o)
|
26
|
+
o[2] = DRbObject.new(o[2]) if o
|
27
|
+
@queue << o
|
28
|
+
end
|
29
|
+
|
30
|
+
def length
|
31
|
+
@queue.length
|
32
|
+
end
|
33
|
+
|
34
|
+
def pop; @queue.pop; end
|
35
|
+
end
|
36
|
+
|
37
|
+
@@after_fork_hooks = []
|
38
|
+
|
39
|
+
def self.after_fork_hook(&blk)
|
40
|
+
@@after_fork_hooks << blk
|
41
|
+
end
|
42
|
+
|
43
|
+
cattr_reader :after_fork_hooks
|
44
|
+
|
45
|
+
@@run_cleanup_hooks = []
|
46
|
+
|
47
|
+
def self.run_cleanup_hook(&blk)
|
48
|
+
@@run_cleanup_hooks << blk
|
49
|
+
end
|
50
|
+
|
51
|
+
cattr_reader :run_cleanup_hooks
|
52
|
+
|
53
|
+
def initialize(queue_size)
|
54
|
+
@queue_size = queue_size
|
55
|
+
@queue = Server.new
|
56
|
+
@pool = []
|
57
|
+
|
58
|
+
@url = DRb.start_service("drbunix:", @queue).uri
|
59
|
+
end
|
60
|
+
|
61
|
+
def after_fork(worker)
|
62
|
+
self.class.after_fork_hooks.each do |cb|
|
63
|
+
cb.call(worker)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def run_cleanup(worker)
|
68
|
+
self.class.run_cleanup_hooks.each do |cb|
|
69
|
+
cb.call(worker)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def start
|
74
|
+
@pool = @queue_size.times.map do |worker|
|
75
|
+
fork do
|
76
|
+
DRb.stop_service
|
77
|
+
|
78
|
+
begin
|
79
|
+
after_fork(worker)
|
80
|
+
rescue => setup_exception; end
|
81
|
+
|
82
|
+
queue = DRbObject.new_with_uri(@url)
|
83
|
+
|
84
|
+
while job = queue.pop
|
85
|
+
klass = job[0]
|
86
|
+
method = job[1]
|
87
|
+
reporter = job[2]
|
88
|
+
result = klass.with_info_handler reporter do
|
89
|
+
Minitest.run_one_method(klass, method)
|
90
|
+
end
|
91
|
+
|
92
|
+
add_setup_exception(result, setup_exception) if setup_exception
|
93
|
+
|
94
|
+
begin
|
95
|
+
queue.record(reporter, result)
|
96
|
+
rescue DRb::DRbConnError
|
97
|
+
result.failures.map! do |failure|
|
98
|
+
if failure.respond_to?(:error)
|
99
|
+
# minitest >5.14.0
|
100
|
+
error = DRb::DRbRemoteError.new(failure.error)
|
101
|
+
else
|
102
|
+
error = DRb::DRbRemoteError.new(failure.exception)
|
103
|
+
end
|
104
|
+
Minitest::UnexpectedError.new(error)
|
105
|
+
end
|
106
|
+
queue.record(reporter, result)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
ensure
|
110
|
+
run_cleanup(worker)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def <<(work)
|
116
|
+
@queue << work
|
117
|
+
end
|
118
|
+
|
119
|
+
def shutdown
|
120
|
+
@queue_size.times { @queue << nil }
|
121
|
+
@pool.each { |pid| Process.waitpid pid }
|
122
|
+
|
123
|
+
if @queue.length > 0
|
124
|
+
raise "Queue not empty, but all workers have finished. This probably means that a worker crashed and #{@queue.length} tests were missed."
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
def add_setup_exception(result, setup_exception)
|
130
|
+
result.failures.prepend Minitest::UnexpectedError.new(setup_exception)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/callbacks"
|
3
4
|
|
4
5
|
module ActiveSupport
|
5
6
|
module Testing
|
@@ -17,11 +18,10 @@ module ActiveSupport
|
|
17
18
|
# end
|
18
19
|
# end
|
19
20
|
module SetupAndTeardown
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
define_callbacks :setup, :teardown
|
21
|
+
def self.prepended(klass)
|
22
|
+
klass.include ActiveSupport::Callbacks
|
23
|
+
klass.define_callbacks :setup, :teardown
|
24
|
+
klass.extend ClassMethods
|
25
25
|
end
|
26
26
|
|
27
27
|
module ClassMethods
|
@@ -42,7 +42,12 @@ module ActiveSupport
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def after_teardown # :nodoc:
|
45
|
-
|
45
|
+
begin
|
46
|
+
run_callbacks :teardown
|
47
|
+
rescue => e
|
48
|
+
self.failures << Minitest::UnexpectedError.new(e)
|
49
|
+
end
|
50
|
+
|
46
51
|
super
|
47
52
|
end
|
48
53
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Testing
|
5
|
+
module Stream #:nodoc:
|
6
|
+
private
|
7
|
+
def silence_stream(stream)
|
8
|
+
old_stream = stream.dup
|
9
|
+
stream.reopen(IO::NULL)
|
10
|
+
stream.sync = true
|
11
|
+
yield
|
12
|
+
ensure
|
13
|
+
stream.reopen(old_stream)
|
14
|
+
old_stream.close
|
15
|
+
end
|
16
|
+
|
17
|
+
def quietly
|
18
|
+
silence_stream(STDOUT) do
|
19
|
+
silence_stream(STDERR) do
|
20
|
+
yield
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def capture(stream)
|
26
|
+
stream = stream.to_s
|
27
|
+
captured_stream = Tempfile.new(stream)
|
28
|
+
stream_io = eval("$#{stream}")
|
29
|
+
origin_stream = stream_io.dup
|
30
|
+
stream_io.reopen(captured_stream)
|
31
|
+
|
32
|
+
yield
|
33
|
+
|
34
|
+
stream_io.rewind
|
35
|
+
captured_stream.read
|
36
|
+
ensure
|
37
|
+
captured_stream.close
|
38
|
+
captured_stream.unlink
|
39
|
+
stream_io.reopen(origin_stream)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveSupport
|
2
4
|
module Testing
|
3
5
|
# Logs a "PostsControllerTest: test name" heading before each test to
|
@@ -8,7 +10,7 @@ module ActiveSupport
|
|
8
10
|
def before_setup
|
9
11
|
if tagged_logger && tagged_logger.info?
|
10
12
|
heading = "#{self.class}: #{name}"
|
11
|
-
divider =
|
13
|
+
divider = "-" * heading.size
|
12
14
|
tagged_logger.info divider
|
13
15
|
tagged_logger.info heading
|
14
16
|
tagged_logger.info divider
|