activesupport 3.1.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +798 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +13 -7
- data/lib/active_support/array_inquirer.rb +44 -0
- data/lib/active_support/backtrace_cleaner.rb +38 -34
- data/lib/active_support/benchmarkable.rb +17 -28
- data/lib/active_support/cache/file_store.rb +85 -70
- data/lib/active_support/cache/mem_cache_store.rb +75 -66
- data/lib/active_support/cache/memory_store.rb +31 -23
- data/lib/active_support/cache/null_store.rb +41 -0
- data/lib/active_support/cache/strategy/local_cache.rb +73 -70
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +44 -0
- data/lib/active_support/cache.rb +360 -294
- data/lib/active_support/callbacks.rb +563 -393
- data/lib/active_support/concern.rb +42 -34
- data/lib/active_support/concurrency/latch.rb +19 -0
- data/lib/active_support/concurrency/share_lock.rb +186 -0
- data/lib/active_support/configurable.rb +70 -12
- data/lib/active_support/core_ext/array/access.rb +53 -9
- data/lib/active_support/core_ext/array/conversions.rb +109 -62
- data/lib/active_support/core_ext/array/extract_options.rb +2 -2
- data/lib/active_support/core_ext/array/grouping.rb +39 -32
- data/lib/active_support/core_ext/array/inquiry.rb +17 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +7 -0
- data/lib/active_support/core_ext/array/wrap.rb +16 -18
- data/lib/active_support/core_ext/array.rb +2 -2
- data/lib/active_support/core_ext/benchmark.rb +7 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -36
- data/lib/active_support/core_ext/class/attribute.rb +47 -34
- data/lib/active_support/core_ext/class/attribute_accessors.rb +4 -79
- data/lib/active_support/core_ext/class/subclasses.rb +12 -7
- data/lib/active_support/core_ext/class.rb +0 -3
- data/lib/active_support/core_ext/date/blank.rb +12 -0
- data/lib/active_support/core_ext/date/calculations.rb +57 -167
- data/lib/active_support/core_ext/date/conversions.rb +31 -42
- data/lib/active_support/core_ext/date/zones.rb +2 -10
- data/lib/active_support/core_ext/date.rb +5 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +335 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +1 -0
- data/lib/active_support/core_ext/date_time/blank.rb +12 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +132 -65
- data/lib/active_support/core_ext/date_time/compatibility.rb +5 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +36 -34
- data/lib/active_support/core_ext/date_time.rb +5 -0
- data/lib/active_support/core_ext/digest/uuid.rb +51 -0
- data/lib/active_support/core_ext/enumerable.rb +81 -74
- data/lib/active_support/core_ext/file/atomic.rb +53 -26
- data/lib/active_support/core_ext/file.rb +0 -1
- data/lib/active_support/core_ext/hash/compact.rb +20 -0
- data/lib/active_support/core_ext/hash/conversions.rb +175 -70
- data/lib/active_support/core_ext/hash/deep_merge.rb +30 -8
- data/lib/active_support/core_ext/hash/except.rb +11 -12
- data/lib/active_support/core_ext/hash/indifferent_access.rb +7 -8
- data/lib/active_support/core_ext/hash/keys.rb +147 -24
- data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
- data/lib/active_support/core_ext/hash/slice.rb +22 -14
- data/lib/active_support/core_ext/hash/transform_values.rb +29 -0
- data/lib/active_support/core_ext/hash.rb +2 -2
- data/lib/active_support/core_ext/integer/inflections.rb +13 -1
- data/lib/active_support/core_ext/integer/multiple.rb +4 -0
- data/lib/active_support/core_ext/integer/time.rb +12 -22
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -2
- data/lib/active_support/core_ext/kernel/concern.rb +12 -0
- data/lib/active_support/core_ext/kernel/debugger.rb +2 -15
- data/lib/active_support/core_ext/kernel/reporting.rb +12 -62
- data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
- data/lib/active_support/core_ext/kernel.rb +2 -3
- data/lib/active_support/core_ext/load_error.rb +14 -7
- data/lib/active_support/core_ext/marshal.rb +22 -0
- data/lib/active_support/core_ext/module/aliasing.rb +16 -12
- data/lib/active_support/core_ext/module/anonymous.rb +12 -8
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -5
- data/lib/active_support/core_ext/module/attribute_accessors.rb +165 -13
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +141 -0
- data/lib/active_support/core_ext/module/concerning.rb +135 -0
- data/lib/active_support/core_ext/module/delegation.rb +141 -68
- data/lib/active_support/core_ext/module/deprecation.rb +17 -3
- data/lib/active_support/core_ext/module/introspection.rb +9 -31
- data/lib/active_support/core_ext/module/method_transplanting.rb +3 -0
- data/lib/active_support/core_ext/module/qualified_const.rb +70 -0
- data/lib/active_support/core_ext/module/reachable.rb +1 -3
- data/lib/active_support/core_ext/module/remove_method.rb +24 -5
- data/lib/active_support/core_ext/module.rb +3 -3
- data/lib/active_support/core_ext/name_error.rb +15 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +20 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
- data/lib/active_support/core_ext/numeric/inquiry.rb +26 -0
- data/lib/active_support/core_ext/numeric/time.rb +31 -36
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/object/acts_like.rb +4 -4
- data/lib/active_support/core_ext/object/blank.rb +52 -18
- data/lib/active_support/core_ext/object/deep_dup.rb +53 -0
- data/lib/active_support/core_ext/object/duplicable.rb +12 -20
- data/lib/active_support/core_ext/object/inclusion.rb +13 -1
- data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
- data/lib/active_support/core_ext/object/json.rb +205 -0
- data/lib/active_support/core_ext/object/to_param.rb +1 -55
- data/lib/active_support/core_ext/object/to_query.rb +66 -9
- data/lib/active_support/core_ext/object/try.rb +124 -33
- data/lib/active_support/core_ext/object/with_options.rb +37 -11
- data/lib/active_support/core_ext/object.rb +2 -1
- data/lib/active_support/core_ext/range/conversions.rb +17 -7
- data/lib/active_support/core_ext/range/each.rb +21 -0
- data/lib/active_support/core_ext/range/include_range.rb +20 -18
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/range.rb +1 -2
- data/lib/active_support/core_ext/securerandom.rb +23 -0
- data/lib/active_support/core_ext/string/access.rb +95 -90
- data/lib/active_support/core_ext/string/behavior.rb +1 -1
- data/lib/active_support/core_ext/string/conversions.rb +41 -38
- data/lib/active_support/core_ext/string/exclude.rb +6 -1
- data/lib/active_support/core_ext/string/filters.rb +70 -17
- data/lib/active_support/core_ext/string/indent.rb +43 -0
- data/lib/active_support/core_ext/string/inflections.rb +139 -59
- data/lib/active_support/core_ext/string/inquiry.rb +2 -2
- data/lib/active_support/core_ext/string/multibyte.rb +46 -65
- data/lib/active_support/core_ext/string/output_safety.rb +153 -56
- data/lib/active_support/core_ext/string/strip.rb +3 -6
- data/lib/active_support/core_ext/string/zones.rb +14 -0
- data/lib/active_support/core_ext/string.rb +2 -3
- data/lib/active_support/core_ext/struct.rb +3 -0
- data/lib/active_support/core_ext/time/calculations.rb +173 -173
- data/lib/active_support/core_ext/time/compatibility.rb +5 -0
- data/lib/active_support/core_ext/time/conversions.rb +33 -29
- data/lib/active_support/core_ext/time/marshal.rb +2 -56
- data/lib/active_support/core_ext/time/zones.rb +57 -32
- data/lib/active_support/core_ext/time.rb +5 -0
- data/lib/active_support/core_ext/uri.rb +13 -19
- data/lib/active_support/core_ext.rb +3 -2
- data/lib/active_support/dependencies/autoload.rb +47 -20
- data/lib/active_support/dependencies/interlock.rb +51 -0
- data/lib/active_support/dependencies.rb +315 -265
- data/lib/active_support/deprecation/behaviors.rb +71 -30
- data/lib/active_support/deprecation/instance_delegator.rb +24 -0
- data/lib/active_support/deprecation/method_wrappers.rb +59 -18
- data/lib/active_support/deprecation/proxy_wrappers.rb +82 -14
- data/lib/active_support/deprecation/reporting.rb +61 -14
- data/lib/active_support/deprecation.rb +38 -13
- data/lib/active_support/descendants_tracker.rb +34 -19
- data/lib/active_support/duration/iso8601_parser.rb +122 -0
- data/lib/active_support/duration/iso8601_serializer.rb +51 -0
- data/lib/active_support/duration.rb +85 -14
- data/lib/active_support/evented_file_update_checker.rb +194 -0
- data/lib/active_support/execution_wrapper.rb +117 -0
- data/lib/active_support/executor.rb +6 -0
- data/lib/active_support/file_update_checker.rb +138 -17
- data/lib/active_support/gem_version.rb +15 -0
- data/lib/active_support/gzip.rb +11 -5
- data/lib/active_support/hash_with_indifferent_access.rb +199 -49
- data/lib/active_support/i18n.rb +6 -2
- data/lib/active_support/i18n_railtie.rb +40 -21
- data/lib/active_support/inflections.rb +22 -13
- data/lib/active_support/inflector/inflections.rb +175 -144
- data/lib/active_support/inflector/methods.rb +328 -91
- data/lib/active_support/inflector/transliterate.rb +51 -37
- data/lib/active_support/json/decoding.rb +31 -22
- data/lib/active_support/json/encoding.rb +88 -248
- data/lib/active_support/key_generator.rb +71 -0
- data/lib/active_support/lazy_load_hooks.rb +27 -25
- data/lib/active_support/locale/en.yml +102 -3
- data/lib/active_support/log_subscriber/test_helper.rb +24 -21
- data/lib/active_support/log_subscriber.rb +36 -49
- data/lib/active_support/logger.rb +106 -0
- data/lib/active_support/logger_silence.rb +28 -0
- data/lib/active_support/logger_thread_safe_level.rb +31 -0
- data/lib/active_support/message_encryptor.rb +72 -36
- data/lib/active_support/message_verifier.rb +96 -24
- data/lib/active_support/multibyte/chars.rb +88 -333
- data/lib/active_support/multibyte/unicode.rb +156 -136
- data/lib/active_support/multibyte.rb +5 -28
- data/lib/active_support/notifications/fanout.rb +115 -19
- data/lib/active_support/notifications/instrumenter.rb +52 -15
- data/lib/active_support/notifications.rb +168 -33
- data/lib/active_support/number_helper/number_converter.rb +182 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +44 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +28 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +68 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +62 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +12 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +58 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +92 -0
- data/lib/active_support/number_helper.rb +368 -0
- data/lib/active_support/option_merger.rb +1 -1
- data/lib/active_support/ordered_hash.rb +18 -183
- data/lib/active_support/ordered_options.rb +44 -24
- data/lib/active_support/per_thread_registry.rb +58 -0
- data/lib/active_support/proxy_object.rb +13 -0
- data/lib/active_support/rails.rb +27 -0
- data/lib/active_support/railtie.rb +25 -34
- data/lib/active_support/reloader.rb +129 -0
- data/lib/active_support/rescuable.rb +98 -48
- data/lib/active_support/security_utils.rb +27 -0
- data/lib/active_support/string_inquirer.rb +14 -9
- data/lib/active_support/subscriber.rb +120 -0
- data/lib/active_support/tagged_logging.rb +78 -0
- data/lib/active_support/test_case.rb +69 -17
- data/lib/active_support/testing/assertions.rb +43 -41
- data/lib/active_support/testing/autorun.rb +12 -0
- data/lib/active_support/testing/constant_lookup.rb +50 -0
- data/lib/active_support/testing/declarative.rb +7 -21
- data/lib/active_support/testing/deprecation.rb +14 -33
- data/lib/active_support/testing/file_fixtures.rb +34 -0
- data/lib/active_support/testing/isolation.rb +53 -95
- data/lib/active_support/testing/method_call_assertions.rb +41 -0
- data/lib/active_support/testing/setup_and_teardown.rb +21 -82
- data/lib/active_support/testing/stream.rb +42 -0
- data/lib/active_support/testing/tagged_logging.rb +25 -0
- data/lib/active_support/testing/time_helpers.rb +134 -0
- data/lib/active_support/time.rb +6 -23
- data/lib/active_support/time_with_zone.rb +239 -92
- data/lib/active_support/values/time_zone.rb +236 -160
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +5 -7
- data/lib/active_support/xml_mini/jdom.rb +19 -13
- data/lib/active_support/xml_mini/libxml.rb +3 -4
- data/lib/active_support/xml_mini/libxmlsax.rb +2 -3
- data/lib/active_support/xml_mini/nokogiri.rb +3 -4
- data/lib/active_support/xml_mini/nokogirisax.rb +2 -3
- data/lib/active_support/xml_mini/rexml.rb +8 -10
- data/lib/active_support/xml_mini.rb +66 -34
- data/lib/active_support.rb +40 -23
- metadata +185 -134
- data/CHANGELOG +0 -1534
- data/lib/active_support/base64.rb +0 -42
- data/lib/active_support/basic_object.rb +0 -21
- data/lib/active_support/buffered_logger.rb +0 -137
- data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
- data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
- data/lib/active_support/core_ext/array/random_access.rb +0 -30
- data/lib/active_support/core_ext/array/uniq_by.rb +0 -16
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -178
- data/lib/active_support/core_ext/date/freeze.rb +0 -31
- data/lib/active_support/core_ext/date_time/zones.rb +0 -21
- data/lib/active_support/core_ext/exception.rb +0 -3
- data/lib/active_support/core_ext/file/path.rb +0 -5
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- data/lib/active_support/core_ext/float.rb +0 -1
- data/lib/active_support/core_ext/hash/deep_dup.rb +0 -11
- data/lib/active_support/core_ext/hash/diff.rb +0 -13
- data/lib/active_support/core_ext/kernel/requires.rb +0 -28
- data/lib/active_support/core_ext/logger.rb +0 -81
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
- data/lib/active_support/core_ext/module/method_names.rb +0 -14
- data/lib/active_support/core_ext/module/synchronization.rb +0 -43
- data/lib/active_support/core_ext/object/to_json.rb +0 -19
- data/lib/active_support/core_ext/proc.rb +0 -14
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- data/lib/active_support/core_ext/process.rb +0 -1
- data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
- data/lib/active_support/core_ext/range/cover.rb +0 -3
- data/lib/active_support/core_ext/rexml.rb +0 -46
- data/lib/active_support/core_ext/string/encoding.rb +0 -11
- data/lib/active_support/core_ext/string/interpolation.rb +0 -2
- data/lib/active_support/core_ext/string/xchar.rb +0 -18
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
- data/lib/active_support/file_watcher.rb +0 -36
- data/lib/active_support/json/variable.rb +0 -9
- data/lib/active_support/memoizable.rb +0 -105
- data/lib/active_support/multibyte/exceptions.rb +0 -8
- data/lib/active_support/multibyte/utils.rb +0 -60
- data/lib/active_support/ruby/shim.rb +0 -22
- data/lib/active_support/secure_random.rb +0 -6
- data/lib/active_support/testing/mochaing.rb +0 -7
- data/lib/active_support/testing/pending.rb +0 -52
- data/lib/active_support/testing/performance/jruby.rb +0 -115
- data/lib/active_support/testing/performance/rubinius.rb +0 -113
- data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
- data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
- data/lib/active_support/testing/performance/ruby.rb +0 -152
- data/lib/active_support/testing/performance.rb +0 -317
- data/lib/active_support/time/autoload.rb +0 -5
- data/lib/active_support/whiny_nil.rb +0 -60
@@ -1,97 +1,99 @@
|
|
1
|
-
require 'active_support/core_ext/array/wrap'
|
2
1
|
require 'active_support/core_ext/object/blank'
|
3
2
|
|
4
3
|
module ActiveSupport
|
5
4
|
module Testing
|
6
5
|
module Assertions
|
7
|
-
#
|
8
|
-
# in
|
6
|
+
# Asserts that an expression is not truthy. Passes if <tt>object</tt> is
|
7
|
+
# +nil+ or +false+. "Truthy" means "considered true in a conditional"
|
8
|
+
# like <tt>if foo</tt>.
|
9
|
+
#
|
10
|
+
# assert_not nil # => true
|
11
|
+
# assert_not false # => true
|
12
|
+
# assert_not 'foo' # => Expected "foo" to be nil or false
|
13
|
+
#
|
14
|
+
# An error message can be specified.
|
15
|
+
#
|
16
|
+
# assert_not foo, 'foo should be false'
|
17
|
+
def assert_not(object, message = nil)
|
18
|
+
message ||= "Expected #{mu_pp(object)} to be nil or false"
|
19
|
+
assert !object, message
|
20
|
+
end
|
21
|
+
|
22
|
+
# Test numeric difference between the return value of an expression as a
|
23
|
+
# result of what is evaluated in the yielded block.
|
9
24
|
#
|
10
25
|
# assert_difference 'Article.count' do
|
11
|
-
# post :create, :article
|
26
|
+
# post :create, params: { article: {...} }
|
12
27
|
# end
|
13
28
|
#
|
14
29
|
# An arbitrary expression is passed in and evaluated.
|
15
30
|
#
|
16
|
-
# assert_difference '
|
17
|
-
# post :create, :comment
|
31
|
+
# assert_difference 'Article.last.comments(:reload).size' do
|
32
|
+
# post :create, params: { comment: {...} }
|
18
33
|
# end
|
19
34
|
#
|
20
|
-
# An arbitrary positive or negative difference can be specified.
|
35
|
+
# An arbitrary positive or negative difference can be specified.
|
36
|
+
# The default is <tt>1</tt>.
|
21
37
|
#
|
22
38
|
# assert_difference 'Article.count', -1 do
|
23
|
-
# post :delete, :id
|
39
|
+
# post :delete, params: { id: ... }
|
24
40
|
# end
|
25
41
|
#
|
26
42
|
# An array of expressions can also be passed in and evaluated.
|
27
43
|
#
|
28
|
-
# assert_difference [ 'Article.count', 'Post.count' ],
|
29
|
-
# post :create, :article
|
44
|
+
# assert_difference [ 'Article.count', 'Post.count' ], 2 do
|
45
|
+
# post :create, params: { article: {...} }
|
30
46
|
# end
|
31
47
|
#
|
32
48
|
# A lambda or a list of lambdas can be passed in and evaluated:
|
33
49
|
#
|
34
|
-
# assert_difference
|
35
|
-
# post :create, :article
|
50
|
+
# assert_difference ->{ Article.count }, 2 do
|
51
|
+
# post :create, params: { article: {...} }
|
36
52
|
# end
|
37
53
|
#
|
38
54
|
# assert_difference [->{ Article.count }, ->{ Post.count }], 2 do
|
39
|
-
# post :create, :article
|
55
|
+
# post :create, params: { article: {...} }
|
40
56
|
# end
|
41
57
|
#
|
42
|
-
#
|
58
|
+
# An error message can be specified.
|
43
59
|
#
|
44
|
-
# assert_difference 'Article.count', -1,
|
45
|
-
# post :delete, :id
|
60
|
+
# assert_difference 'Article.count', -1, 'An Article should be destroyed' do
|
61
|
+
# post :delete, params: { id: ... }
|
46
62
|
# end
|
47
63
|
def assert_difference(expression, difference = 1, message = nil, &block)
|
48
|
-
expressions = Array
|
64
|
+
expressions = Array(expression)
|
49
65
|
|
50
66
|
exps = expressions.map { |e|
|
51
67
|
e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
|
52
68
|
}
|
53
|
-
before = exps.map
|
69
|
+
before = exps.map(&:call)
|
54
70
|
|
55
|
-
yield
|
71
|
+
retval = yield
|
56
72
|
|
57
73
|
expressions.zip(exps).each_with_index do |(code, e), i|
|
58
74
|
error = "#{code.inspect} didn't change by #{difference}"
|
59
75
|
error = "#{message}.\n#{error}" if message
|
60
76
|
assert_equal(before[i] + difference, e.call, error)
|
61
77
|
end
|
78
|
+
|
79
|
+
retval
|
62
80
|
end
|
63
81
|
|
64
|
-
# Assertion that the numeric result of evaluating an expression is not
|
65
|
-
# invoking the passed in block.
|
82
|
+
# Assertion that the numeric result of evaluating an expression is not
|
83
|
+
# changed before and after invoking the passed in block.
|
66
84
|
#
|
67
85
|
# assert_no_difference 'Article.count' do
|
68
|
-
# post :create, :article
|
86
|
+
# post :create, params: { article: invalid_attributes }
|
69
87
|
# end
|
70
88
|
#
|
71
|
-
#
|
89
|
+
# An error message can be specified.
|
72
90
|
#
|
73
|
-
# assert_no_difference 'Article.count',
|
74
|
-
# post :create, :article
|
91
|
+
# assert_no_difference 'Article.count', 'An Article should not be created' do
|
92
|
+
# post :create, params: { article: invalid_attributes }
|
75
93
|
# end
|
76
94
|
def assert_no_difference(expression, message = nil, &block)
|
77
95
|
assert_difference expression, 0, message, &block
|
78
96
|
end
|
79
|
-
|
80
|
-
# Test if an expression is blank. Passes if object.blank? is true.
|
81
|
-
#
|
82
|
-
# assert_blank [] # => true
|
83
|
-
def assert_blank(object, message=nil)
|
84
|
-
message ||= "#{object.inspect} is not blank"
|
85
|
-
assert object.blank?, message
|
86
|
-
end
|
87
|
-
|
88
|
-
# Test if an expression is not blank. Passes if object.present? is true.
|
89
|
-
#
|
90
|
-
# assert_present {:data => 'x' } # => true
|
91
|
-
def assert_present(object, message=nil)
|
92
|
-
message ||= "#{object.inspect} is blank"
|
93
|
-
assert object.present?, message
|
94
|
-
end
|
95
97
|
end
|
96
98
|
end
|
97
99
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
require "active_support/inflector"
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
module Testing
|
6
|
+
# Resolves a constant from a minitest spec name.
|
7
|
+
#
|
8
|
+
# Given the following spec-style test:
|
9
|
+
#
|
10
|
+
# describe WidgetsController, :index do
|
11
|
+
# describe "authenticated user" do
|
12
|
+
# describe "returns widgets" do
|
13
|
+
# it "has a controller that exists" do
|
14
|
+
# assert_kind_of WidgetsController, @controller
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# The test will have the following name:
|
21
|
+
#
|
22
|
+
# "WidgetsController::index::authenticated user::returns widgets"
|
23
|
+
#
|
24
|
+
# The constant WidgetsController can be resolved from the name.
|
25
|
+
# The following code will resolve the constant:
|
26
|
+
#
|
27
|
+
# controller = determine_constant_from_test_name(name) do |constant|
|
28
|
+
# Class === constant && constant < ::ActionController::Metal
|
29
|
+
# end
|
30
|
+
module ConstantLookup
|
31
|
+
extend ::ActiveSupport::Concern
|
32
|
+
|
33
|
+
module ClassMethods # :nodoc:
|
34
|
+
def determine_constant_from_test_name(test_name)
|
35
|
+
names = test_name.split "::"
|
36
|
+
while names.size > 0 do
|
37
|
+
names.last.sub!(/Test$/, "")
|
38
|
+
begin
|
39
|
+
constant = names.join("::").safe_constantize
|
40
|
+
break(constant) if yield(constant)
|
41
|
+
ensure
|
42
|
+
names.pop
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,30 +1,16 @@
|
|
1
1
|
module ActiveSupport
|
2
2
|
module Testing
|
3
3
|
module Declarative
|
4
|
-
|
5
|
-
def self.extended(klass)
|
6
|
-
klass.class_eval do
|
7
|
-
|
8
|
-
unless method_defined?(:describe)
|
9
|
-
def self.describe(text)
|
10
|
-
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
11
|
-
def self.name
|
12
|
-
"#{text}"
|
13
|
-
end
|
14
|
-
RUBY_EVAL
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
4
|
unless defined?(Spec)
|
22
|
-
# test
|
23
|
-
#
|
24
|
-
#
|
5
|
+
# Helper to define a test method using a String. Under the hood, it replaces
|
6
|
+
# spaces with underscores and defines the test method.
|
7
|
+
#
|
8
|
+
# test "verify something" do
|
9
|
+
# ...
|
10
|
+
# end
|
25
11
|
def test(name, &block)
|
26
12
|
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
27
|
-
defined =
|
13
|
+
defined = method_defined? test_name
|
28
14
|
raise "#{test_name} is already defined in #{self}" if defined
|
29
15
|
if block_given?
|
30
16
|
define_method(test_name, &block)
|
@@ -3,8 +3,8 @@ require 'active_support/deprecation'
|
|
3
3
|
module ActiveSupport
|
4
4
|
module Testing
|
5
5
|
module Deprecation #:nodoc:
|
6
|
-
def assert_deprecated(match = nil, &block)
|
7
|
-
result, warnings = collect_deprecations(&block)
|
6
|
+
def assert_deprecated(match = nil, deprecator = nil, &block)
|
7
|
+
result, warnings = collect_deprecations(deprecator, &block)
|
8
8
|
assert !warnings.empty?, "Expected a deprecation warning within the block but received none"
|
9
9
|
if match
|
10
10
|
match = Regexp.new(Regexp.escape(match)) unless match.is_a?(Regexp)
|
@@ -13,42 +13,23 @@ module ActiveSupport
|
|
13
13
|
result
|
14
14
|
end
|
15
15
|
|
16
|
-
def assert_not_deprecated(&block)
|
17
|
-
result, deprecations = collect_deprecations(&block)
|
16
|
+
def assert_not_deprecated(deprecator = nil, &block)
|
17
|
+
result, deprecations = collect_deprecations(deprecator, &block)
|
18
18
|
assert deprecations.empty?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n #{deprecations * "\n "}"
|
19
19
|
result
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
result = yield
|
30
|
-
[result, deprecations]
|
31
|
-
ensure
|
32
|
-
ActiveSupport::Deprecation.behavior = old_behavior
|
22
|
+
def collect_deprecations(deprecator = nil)
|
23
|
+
deprecator ||= ActiveSupport::Deprecation
|
24
|
+
old_behavior = deprecator.behavior
|
25
|
+
deprecations = []
|
26
|
+
deprecator.behavior = Proc.new do |message, callstack|
|
27
|
+
deprecations << message
|
33
28
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
begin
|
39
|
-
require 'test/unit/error'
|
40
|
-
rescue LoadError
|
41
|
-
# Using miniunit, ignore.
|
42
|
-
else
|
43
|
-
module Test
|
44
|
-
module Unit
|
45
|
-
class Error #:nodoc:
|
46
|
-
# Silence warnings when reporting test errors.
|
47
|
-
def message_with_silenced_deprecation
|
48
|
-
ActiveSupport::Deprecation.silence { message_without_silenced_deprecation }
|
49
|
-
end
|
50
|
-
alias_method :message_without_silenced_deprecation, :message
|
51
|
-
alias_method :message, :message_with_silenced_deprecation
|
29
|
+
result = yield
|
30
|
+
[result, deprecations]
|
31
|
+
ensure
|
32
|
+
deprecator.behavior = old_behavior
|
52
33
|
end
|
53
34
|
end
|
54
35
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
module Testing
|
3
|
+
# Adds simple access to sample files called file fixtures.
|
4
|
+
# File fixtures are normal files stored in
|
5
|
+
# <tt>ActiveSupport::TestCase.file_fixture_path</tt>.
|
6
|
+
#
|
7
|
+
# File fixtures are represented as +Pathname+ objects.
|
8
|
+
# This makes it easy to extract specific information:
|
9
|
+
#
|
10
|
+
# file_fixture("example.txt").read # get the file's content
|
11
|
+
# file_fixture("example.mp3").size # get the file size
|
12
|
+
module FileFixtures
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
included do
|
16
|
+
class_attribute :file_fixture_path, instance_writer: false
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns a +Pathname+ to the fixture file named +fixture_name+.
|
20
|
+
#
|
21
|
+
# Raises +ArgumentError+ if +fixture_name+ can't be found.
|
22
|
+
def file_fixture(fixture_name)
|
23
|
+
path = Pathname.new(File.join(file_fixture_path, fixture_name))
|
24
|
+
|
25
|
+
if path.exist?
|
26
|
+
path
|
27
|
+
else
|
28
|
+
msg = "the directory '%s' does not contain a file named '%s'"
|
29
|
+
raise ArgumentError, msg % [file_fixture_path, fixture_name]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,104 +1,63 @@
|
|
1
|
-
require 'rbconfig'
|
2
1
|
module ActiveSupport
|
3
2
|
module Testing
|
4
|
-
|
5
|
-
|
6
|
-
attr_reader :message, :backtrace
|
7
|
-
|
8
|
-
def initialize(exception)
|
9
|
-
@message = "caught #{exception.class.name}: #{exception.message}"
|
10
|
-
@backtrace = exception.backtrace
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class ProxyTestResult
|
15
|
-
def initialize
|
16
|
-
@calls = []
|
17
|
-
end
|
18
|
-
|
19
|
-
def add_error(e)
|
20
|
-
e = Test::Unit::Error.new(e.test_name, RemoteError.new(e.exception))
|
21
|
-
@calls << [:add_error, e]
|
22
|
-
end
|
3
|
+
module Isolation
|
4
|
+
require 'thread'
|
23
5
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
6
|
+
def self.included(klass) #:nodoc:
|
7
|
+
klass.class_eval do
|
8
|
+
parallelize_me!
|
27
9
|
end
|
28
10
|
end
|
29
11
|
|
30
|
-
def method_missing(name, *args)
|
31
|
-
@calls << [name, args]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
module Isolation
|
36
12
|
def self.forking_env?
|
37
|
-
!ENV["NO_FORK"] && (
|
13
|
+
!ENV["NO_FORK"] && Process.respond_to?(:fork)
|
38
14
|
end
|
39
15
|
|
40
|
-
|
41
|
-
if defined?(::MiniTest) && base < ::MiniTest::Unit::TestCase
|
42
|
-
base.send :include, MiniTest
|
43
|
-
elsif defined?(Test::Unit)
|
44
|
-
base.send :include, TestUnit
|
45
|
-
end
|
46
|
-
end
|
16
|
+
@@class_setup_mutex = Mutex.new
|
47
17
|
|
48
18
|
def _run_class_setup # class setup method should only happen in parent
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
module TestUnit
|
56
|
-
def run(result)
|
57
|
-
_run_class_setup
|
58
|
-
|
59
|
-
yield(Test::Unit::TestCase::STARTED, name)
|
60
|
-
|
61
|
-
@_result = result
|
62
|
-
|
63
|
-
serialized = run_in_isolation do |proxy|
|
64
|
-
begin
|
65
|
-
super(proxy) { }
|
66
|
-
rescue Exception => e
|
67
|
-
proxy.add_error(Test::Unit::Error.new(name, e))
|
68
|
-
end
|
19
|
+
@@class_setup_mutex.synchronize do
|
20
|
+
unless defined?(@@ran_class_setup) || ENV['ISOLATION_TEST']
|
21
|
+
self.class.setup if self.class.respond_to?(:setup)
|
22
|
+
@@ran_class_setup = true
|
69
23
|
end
|
70
|
-
|
71
|
-
retval, proxy = Marshal.load(serialized)
|
72
|
-
proxy.__replay__(@_result)
|
73
|
-
|
74
|
-
yield(Test::Unit::TestCase::FINISHED, name)
|
75
|
-
retval
|
76
24
|
end
|
77
25
|
end
|
78
26
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
serialized = run_in_isolation do |isolated_runner|
|
84
|
-
super(isolated_runner)
|
85
|
-
end
|
86
|
-
|
87
|
-
retval, proxy = Marshal.load(serialized)
|
88
|
-
proxy.__replay__(runner)
|
89
|
-
retval
|
27
|
+
def run
|
28
|
+
serialized = run_in_isolation do
|
29
|
+
super
|
90
30
|
end
|
31
|
+
|
32
|
+
Marshal.load(serialized)
|
91
33
|
end
|
92
34
|
|
93
35
|
module Forking
|
94
36
|
def run_in_isolation(&blk)
|
95
37
|
read, write = IO.pipe
|
38
|
+
read.binmode
|
39
|
+
write.binmode
|
96
40
|
|
97
41
|
pid = fork do
|
98
42
|
read.close
|
99
|
-
|
100
|
-
|
101
|
-
|
43
|
+
yield
|
44
|
+
begin
|
45
|
+
if error?
|
46
|
+
failures.map! { |e|
|
47
|
+
begin
|
48
|
+
Marshal.dump e
|
49
|
+
e
|
50
|
+
rescue TypeError
|
51
|
+
ex = Exception.new e.message
|
52
|
+
ex.set_backtrace e.backtrace
|
53
|
+
Minitest::UnexpectedError.new ex
|
54
|
+
end
|
55
|
+
}
|
56
|
+
end
|
57
|
+
result = Marshal.dump(self.dup)
|
58
|
+
end
|
59
|
+
|
60
|
+
write.puts [result].pack("m")
|
102
61
|
exit!
|
103
62
|
end
|
104
63
|
|
@@ -118,22 +77,31 @@ module ActiveSupport
|
|
118
77
|
require "tempfile"
|
119
78
|
|
120
79
|
if ENV["ISOLATION_TEST"]
|
121
|
-
|
122
|
-
retval = yield proxy
|
80
|
+
yield
|
123
81
|
File.open(ENV["ISOLATION_OUTPUT"], "w") do |file|
|
124
|
-
file.puts [Marshal.dump(
|
82
|
+
file.puts [Marshal.dump(self.dup)].pack("m")
|
125
83
|
end
|
126
84
|
exit!
|
127
85
|
else
|
128
86
|
Tempfile.open("isolation") do |tmpfile|
|
129
|
-
|
130
|
-
|
87
|
+
env = {
|
88
|
+
'ISOLATION_TEST' => self.class.name,
|
89
|
+
'ISOLATION_OUTPUT' => tmpfile.path
|
90
|
+
}
|
131
91
|
|
132
92
|
load_paths = $-I.map {|p| "-I\"#{File.expand_path(p)}\"" }.join(" ")
|
133
|
-
|
93
|
+
orig_args = ORIG_ARGV.join(" ")
|
94
|
+
test_opts = "-n#{self.class.name}##{self.name}"
|
95
|
+
command = "#{Gem.ruby} #{load_paths} #{$0} '#{orig_args}' #{test_opts}"
|
96
|
+
|
97
|
+
# IO.popen lets us pass env in a cross-platform way
|
98
|
+
child = IO.popen(env, command)
|
134
99
|
|
135
|
-
|
136
|
-
|
100
|
+
begin
|
101
|
+
Process.wait(child.pid)
|
102
|
+
rescue Errno::ECHILD # The child process may exit before we wait
|
103
|
+
nil
|
104
|
+
end
|
137
105
|
|
138
106
|
return tmpfile.read.unpack("m")[0]
|
139
107
|
end
|
@@ -145,13 +113,3 @@ module ActiveSupport
|
|
145
113
|
end
|
146
114
|
end
|
147
115
|
end
|
148
|
-
|
149
|
-
# Only in subprocess for windows / jruby.
|
150
|
-
if ENV['ISOLATION_TEST']
|
151
|
-
require "test/unit/collector/objectspace"
|
152
|
-
class Test::Unit::Collector::ObjectSpace
|
153
|
-
def include?(test)
|
154
|
-
super && test.method_name == ENV['ISOLATION_TEST']
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'minitest/mock'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Testing
|
5
|
+
module MethodCallAssertions # :nodoc:
|
6
|
+
private
|
7
|
+
def assert_called(object, method_name, message = nil, times: 1, returns: nil)
|
8
|
+
times_called = 0
|
9
|
+
|
10
|
+
object.stub(method_name, proc { times_called += 1; returns }) { yield }
|
11
|
+
|
12
|
+
error = "Expected #{method_name} to be called #{times} times, " \
|
13
|
+
"but was called #{times_called} times"
|
14
|
+
error = "#{message}.\n#{error}" if message
|
15
|
+
assert_equal times, times_called, error
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_called_with(object, method_name, args = [], returns: nil)
|
19
|
+
mock = Minitest::Mock.new
|
20
|
+
|
21
|
+
if args.all? { |arg| arg.is_a?(Array) }
|
22
|
+
args.each { |arg| mock.expect(:call, returns, arg) }
|
23
|
+
else
|
24
|
+
mock.expect(:call, returns, args)
|
25
|
+
end
|
26
|
+
|
27
|
+
object.stub(method_name, mock) { yield }
|
28
|
+
|
29
|
+
mock.verify
|
30
|
+
end
|
31
|
+
|
32
|
+
def assert_not_called(object, method_name, message = nil, &block)
|
33
|
+
assert_called(object, method_name, message, times: 0, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_any_instance(klass, instance: klass.new)
|
37
|
+
klass.stub(:new, instance) { yield instance }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|