activesupport 3.2.22.5 → 4.0.0.beta1
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 +4 -4
- data/CHANGELOG.md +325 -136
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -2
- data/lib/active_support.rb +8 -21
- data/lib/active_support/backtrace_cleaner.rb +33 -25
- data/lib/active_support/basic_object.rb +7 -17
- data/lib/active_support/benchmarkable.rb +19 -15
- data/lib/active_support/buffered_logger.rb +9 -113
- data/lib/active_support/cache.rb +203 -171
- data/lib/active_support/cache/file_store.rb +12 -12
- data/lib/active_support/cache/mem_cache_store.rb +24 -30
- data/lib/active_support/cache/memory_store.rb +2 -0
- data/lib/active_support/callbacks.rb +195 -247
- data/lib/active_support/concern.rb +16 -23
- data/lib/active_support/concurrency/latch.rb +27 -0
- data/lib/active_support/configurable.rb +69 -12
- data/lib/active_support/core_ext.rb +1 -0
- data/lib/active_support/core_ext/array.rb +0 -1
- data/lib/active_support/core_ext/array/access.rb +17 -9
- data/lib/active_support/core_ext/array/conversions.rb +113 -55
- data/lib/active_support/core_ext/array/extract_options.rb +2 -2
- data/lib/active_support/core_ext/array/grouping.rb +21 -22
- data/lib/active_support/core_ext/array/uniq_by.rb +12 -9
- data/lib/active_support/core_ext/array/wrap.rb +11 -14
- data/lib/active_support/core_ext/big_decimal/conversions.rb +7 -24
- data/lib/active_support/core_ext/class/attribute.rb +12 -8
- data/lib/active_support/core_ext/class/attribute_accessors.rb +14 -12
- data/lib/active_support/core_ext/class/delegating_attributes.rb +15 -19
- data/lib/active_support/core_ext/class/subclasses.rb +11 -5
- data/lib/active_support/core_ext/date.rb +6 -0
- data/lib/active_support/core_ext/date/calculations.rb +34 -188
- data/lib/active_support/core_ext/date/conversions.rb +16 -38
- data/lib/active_support/core_ext/date/infinite_comparable.rb +5 -0
- data/lib/active_support/core_ext/date/zones.rb +25 -2
- data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
- data/lib/active_support/core_ext/date_time.rb +5 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
- data/lib/active_support/core_ext/date_time/calculations.rb +73 -65
- data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
- data/lib/active_support/core_ext/date_time/infinite_comparable.rb +5 -0
- data/lib/active_support/core_ext/date_time/zones.rb +11 -8
- data/lib/active_support/core_ext/enumerable.rb +26 -73
- data/lib/active_support/core_ext/file.rb +0 -1
- data/lib/active_support/core_ext/file/atomic.rb +27 -11
- data/lib/active_support/core_ext/hash.rb +0 -1
- data/lib/active_support/core_ext/hash/conversions.rb +145 -79
- data/lib/active_support/core_ext/hash/deep_merge.rb +14 -8
- data/lib/active_support/core_ext/hash/diff.rb +5 -4
- data/lib/active_support/core_ext/hash/except.rb +1 -9
- data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -5
- data/lib/active_support/core_ext/hash/keys.rb +108 -24
- data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
- data/lib/active_support/core_ext/hash/slice.rb +12 -12
- data/lib/active_support/core_ext/infinite_comparable.rb +35 -0
- data/lib/active_support/core_ext/integer/inflections.rb +13 -1
- data/lib/active_support/core_ext/integer/time.rb +17 -12
- data/lib/active_support/core_ext/kernel/debugger.rb +2 -2
- data/lib/active_support/core_ext/kernel/reporting.rb +36 -22
- data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
- data/lib/active_support/core_ext/load_error.rb +7 -5
- data/lib/active_support/core_ext/logger.rb +7 -23
- data/lib/active_support/core_ext/marshal.rb +19 -0
- data/lib/active_support/core_ext/module.rb +1 -3
- data/lib/active_support/core_ext/module/aliasing.rb +8 -9
- data/lib/active_support/core_ext/module/anonymous.rb +2 -7
- data/lib/active_support/core_ext/module/attr_internal.rb +0 -1
- data/lib/active_support/core_ext/module/attribute_accessors.rb +12 -10
- data/lib/active_support/core_ext/module/delegation.rb +57 -40
- data/lib/active_support/core_ext/module/deprecation.rb +19 -3
- data/lib/active_support/core_ext/module/introspection.rb +17 -27
- data/lib/active_support/core_ext/module/qualified_const.rb +8 -20
- data/lib/active_support/core_ext/module/remove_method.rb +1 -5
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
- data/lib/active_support/core_ext/numeric/infinite_comparable.rb +9 -0
- data/lib/active_support/core_ext/numeric/time.rb +6 -6
- data/lib/active_support/core_ext/object.rb +1 -0
- data/lib/active_support/core_ext/object/acts_like.rb +4 -4
- data/lib/active_support/core_ext/object/blank.rb +7 -23
- data/lib/active_support/core_ext/object/deep_dup.rb +46 -0
- data/lib/active_support/core_ext/object/duplicable.rb +1 -30
- data/lib/active_support/core_ext/object/inclusion.rb +6 -6
- data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
- data/lib/active_support/core_ext/object/to_json.rb +8 -0
- data/lib/active_support/core_ext/object/to_param.rb +5 -2
- data/lib/active_support/core_ext/object/try.rb +46 -25
- data/lib/active_support/core_ext/object/with_options.rb +7 -8
- data/lib/active_support/core_ext/proc.rb +3 -0
- data/lib/active_support/core_ext/range.rb +0 -2
- data/lib/active_support/core_ext/range/conversions.rb +0 -2
- data/lib/active_support/core_ext/range/include_range.rb +1 -1
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/string.rb +2 -2
- data/lib/active_support/core_ext/string/access.rb +95 -90
- data/lib/active_support/core_ext/string/conversions.rb +29 -38
- data/lib/active_support/core_ext/string/encoding.rb +6 -9
- data/lib/active_support/core_ext/string/filters.rb +24 -18
- data/lib/active_support/core_ext/string/indent.rb +43 -0
- data/lib/active_support/core_ext/string/inflections.rb +70 -60
- data/lib/active_support/core_ext/string/inquiry.rb +2 -2
- data/lib/active_support/core_ext/string/multibyte.rb +41 -64
- data/lib/active_support/core_ext/string/output_safety.rb +59 -51
- data/lib/active_support/core_ext/string/zones.rb +13 -0
- data/lib/active_support/core_ext/struct.rb +6 -0
- data/lib/active_support/core_ext/thread.rb +74 -0
- data/lib/active_support/core_ext/time.rb +6 -0
- data/lib/active_support/core_ext/time/calculations.rb +105 -193
- data/lib/active_support/core_ext/time/conversions.rb +27 -51
- data/lib/active_support/core_ext/time/infinite_comparable.rb +5 -0
- data/lib/active_support/core_ext/time/marshal.rb +0 -27
- data/lib/active_support/core_ext/time/zones.rb +27 -17
- data/lib/active_support/core_ext/uri.rb +13 -17
- data/lib/active_support/dependencies.rb +160 -141
- data/lib/active_support/dependencies/autoload.rb +47 -20
- data/lib/active_support/deprecation.rb +39 -14
- data/lib/active_support/deprecation/behaviors.rb +44 -30
- data/lib/active_support/deprecation/instance_delegator.rb +24 -0
- data/lib/active_support/deprecation/method_wrappers.rb +33 -18
- data/lib/active_support/deprecation/proxy_wrappers.rb +58 -13
- data/lib/active_support/deprecation/reporting.rb +40 -11
- data/lib/active_support/descendants_tracker.rb +34 -19
- data/lib/active_support/duration.rb +6 -8
- data/lib/active_support/file_update_checker.rb +63 -47
- data/lib/active_support/gzip.rb +11 -5
- data/lib/active_support/hash_with_indifferent_access.rb +112 -37
- data/lib/active_support/i18n.rb +4 -0
- data/lib/active_support/i18n_railtie.rb +5 -22
- data/lib/active_support/inflections.rb +14 -12
- data/lib/active_support/inflector/inflections.rb +108 -71
- data/lib/active_support/inflector/methods.rb +181 -160
- data/lib/active_support/inflector/transliterate.rb +16 -17
- data/lib/active_support/json/decoding.rb +18 -17
- data/lib/active_support/json/encoding.rb +93 -39
- data/lib/active_support/json/variable.rb +10 -1
- data/lib/active_support/key_generator.rb +75 -0
- data/lib/active_support/lazy_load_hooks.rb +21 -19
- data/lib/active_support/locale/en.yml +100 -3
- data/lib/active_support/log_subscriber.rb +56 -36
- data/lib/active_support/log_subscriber/test_helper.rb +18 -15
- data/lib/active_support/logger.rb +57 -0
- data/lib/active_support/logger_silence.rb +24 -0
- data/lib/active_support/message_encryptor.rb +32 -29
- data/lib/active_support/message_verifier.rb +8 -14
- data/lib/active_support/multibyte.rb +5 -28
- data/lib/active_support/multibyte/chars.rb +80 -333
- data/lib/active_support/multibyte/unicode.rb +74 -64
- data/lib/active_support/notifications.rb +57 -25
- data/lib/active_support/notifications/fanout.rb +105 -18
- data/lib/active_support/notifications/instrumenter.rb +32 -13
- data/lib/active_support/number_helper.rb +636 -0
- data/lib/active_support/ordered_hash.rb +8 -190
- data/lib/active_support/ordered_options.rb +21 -23
- data/lib/active_support/proxy_object.rb +13 -0
- data/lib/active_support/rails.rb +27 -0
- data/lib/active_support/railtie.rb +12 -32
- data/lib/active_support/rescuable.rb +9 -4
- data/lib/active_support/string_inquirer.rb +13 -8
- data/lib/active_support/tagged_logging.rb +51 -73
- data/lib/active_support/test_case.rb +46 -17
- data/lib/active_support/testing/assertions.rb +56 -26
- data/lib/active_support/testing/autorun.rb +5 -0
- data/lib/active_support/testing/constant_lookup.rb +52 -0
- data/lib/active_support/testing/declarative.rb +1 -1
- data/lib/active_support/testing/deprecation.rb +0 -19
- data/lib/active_support/testing/isolation.rb +25 -58
- data/lib/active_support/testing/pending.rb +5 -43
- data/lib/active_support/testing/setup_and_teardown.rb +6 -92
- data/lib/active_support/testing/tagged_logging.rb +25 -0
- data/lib/active_support/time.rb +6 -21
- data/lib/active_support/time_with_zone.rb +78 -43
- data/lib/active_support/values/time_zone.rb +77 -58
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +4 -4
- data/lib/active_support/xml_mini.rb +35 -17
- data/lib/active_support/xml_mini/jdom.rb +9 -17
- data/lib/active_support/xml_mini/libxml.rb +1 -2
- data/lib/active_support/xml_mini/libxmlsax.rb +1 -2
- data/lib/active_support/xml_mini/nokogiri.rb +1 -2
- data/lib/active_support/xml_mini/nokogirisax.rb +1 -2
- data/lib/active_support/xml_mini/rexml.rb +6 -8
- metadata +107 -77
- data/lib/active_support/base64.rb +0 -54
- data/lib/active_support/core_ext/array/random_access.rb +0 -30
- data/lib/active_support/core_ext/date/freeze.rb +0 -33
- 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.rb +0 -1
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- data/lib/active_support/core_ext/hash/deep_dup.rb +0 -18
- data/lib/active_support/core_ext/io.rb +0 -15
- data/lib/active_support/core_ext/module/method_names.rb +0 -14
- data/lib/active_support/core_ext/module/synchronization.rb +0 -45
- data/lib/active_support/core_ext/process.rb +0 -1
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- 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/interpolation.rb +0 -2
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
- data/lib/active_support/memoizable.rb +0 -116
- 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/security_utils.rb +0 -27
- data/lib/active_support/testing/mochaing.rb +0 -7
- data/lib/active_support/testing/performance.rb +0 -317
- 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.rb +0 -152
- 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/time/autoload.rb +0 -5
- data/lib/active_support/whiny_nil.rb +0 -24
@@ -1,97 +1,75 @@
|
|
1
1
|
require 'active_support/core_ext/object/blank'
|
2
|
-
require 'active_support/deprecation'
|
3
2
|
require 'logger'
|
3
|
+
require 'active_support/logger'
|
4
4
|
|
5
5
|
module ActiveSupport
|
6
|
-
# Wraps any standard Logger
|
6
|
+
# Wraps any standard Logger object to provide tagging capabilities.
|
7
7
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
8
|
+
# logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
|
9
|
+
# logger.tagged('BCX') { logger.info 'Stuff' } # Logs "[BCX] Stuff"
|
10
|
+
# logger.tagged('BCX', "Jason") { logger.info 'Stuff' } # Logs "[BCX] [Jason] Stuff"
|
11
|
+
# logger.tagged('BCX') { logger.tagged('Jason') { logger.info 'Stuff' } } # Logs "[BCX] [Jason] Stuff"
|
12
12
|
#
|
13
|
-
# This is used by the default Rails.logger as configured by Railties to make
|
14
|
-
# with subdomains, request ids, and anything else
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
yield self
|
23
|
-
ensure
|
24
|
-
pop_tags(new_tags.size)
|
25
|
-
end
|
13
|
+
# This is used by the default Rails.logger as configured by Railties to make
|
14
|
+
# it easy to stamp log lines with subdomains, request ids, and anything else
|
15
|
+
# to aid debugging of multi-user production applications.
|
16
|
+
module TaggedLogging
|
17
|
+
module Formatter # :nodoc:
|
18
|
+
# This method is invoked when a log event occurs.
|
19
|
+
def call(severity, timestamp, progname, msg)
|
20
|
+
super(severity, timestamp, progname, "#{tags_text}#{msg}")
|
21
|
+
end
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
def tagged(*tags)
|
24
|
+
new_tags = push_tags(*tags)
|
25
|
+
yield self
|
26
|
+
ensure
|
27
|
+
pop_tags(new_tags.size)
|
30
28
|
end
|
31
|
-
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
def push_tags(*tags)
|
31
|
+
tags.flatten.reject(&:blank?).tap do |new_tags|
|
32
|
+
current_tags.concat new_tags
|
33
|
+
end
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def pop_tags(size = 1)
|
37
|
+
current_tags.pop size
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
deprecate :silence
|
40
|
+
def clear_tags!
|
41
|
+
current_tags.clear
|
42
|
+
end
|
45
43
|
|
46
|
-
|
47
|
-
|
48
|
-
if block_given?
|
49
|
-
message = block.call
|
50
|
-
else
|
51
|
-
message = progname
|
52
|
-
progname = nil #No instance variable for this like Logger
|
53
|
-
end
|
44
|
+
def current_tags
|
45
|
+
Thread.current[:activesupport_tagged_logging_tags] ||= []
|
54
46
|
end
|
55
|
-
@logger.add(severity, "#{tags_text}#{message}", progname)
|
56
|
-
end
|
57
47
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
48
|
+
private
|
49
|
+
def tags_text
|
50
|
+
tags = current_tags
|
51
|
+
if tags.any?
|
52
|
+
tags.collect { |tag| "[#{tag}] " }.join
|
53
|
+
end
|
62
54
|
end
|
63
|
-
EOM
|
64
55
|
end
|
65
56
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
57
|
+
def self.new(logger)
|
58
|
+
# Ensure we set a default formatter so we aren't extending nil!
|
59
|
+
logger.formatter ||= ActiveSupport::Logger::SimpleFormatter.new
|
60
|
+
logger.formatter.extend Formatter
|
61
|
+
logger.extend(self)
|
69
62
|
end
|
70
63
|
|
71
|
-
|
72
|
-
@logger.send(method, *args)
|
73
|
-
end
|
64
|
+
delegate :push_tags, :pop_tags, :clear_tags!, to: :formatter
|
74
65
|
|
75
|
-
|
76
|
-
|
77
|
-
super || @logger.respond_to?(*args)
|
78
|
-
end
|
79
|
-
else
|
80
|
-
def respond_to_missing?(*args)
|
81
|
-
@logger.respond_to? *args
|
82
|
-
end
|
66
|
+
def tagged(*tags)
|
67
|
+
formatter.tagged(*tags) { yield self }
|
83
68
|
end
|
84
69
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
tags.collect { |tag| "[#{tag}] " }.join
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def current_tags
|
94
|
-
Thread.current[:activesupport_tagged_logging_tags] ||= []
|
95
|
-
end
|
70
|
+
def flush
|
71
|
+
clear_tags!
|
72
|
+
super if defined?(super)
|
73
|
+
end
|
96
74
|
end
|
97
75
|
end
|
@@ -1,38 +1,67 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
raise LoadError, "Please add test-unit gem to your Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})", e.backtrace
|
5
|
-
end
|
1
|
+
gem 'minitest' # make sure we get the gem, not stdlib
|
2
|
+
require 'minitest/unit'
|
3
|
+
require 'active_support/testing/tagged_logging'
|
6
4
|
require 'active_support/testing/setup_and_teardown'
|
7
5
|
require 'active_support/testing/assertions'
|
8
6
|
require 'active_support/testing/deprecation'
|
9
|
-
require 'active_support/testing/declarative'
|
10
7
|
require 'active_support/testing/pending'
|
8
|
+
require 'active_support/testing/declarative'
|
11
9
|
require 'active_support/testing/isolation'
|
12
|
-
require 'active_support/testing/
|
10
|
+
require 'active_support/testing/constant_lookup'
|
13
11
|
require 'active_support/core_ext/kernel/reporting'
|
12
|
+
require 'active_support/deprecation'
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
alias_method :method_name, :name if method_defined? :name
|
20
|
-
alias_method :method_name, :__name__ if method_defined? :__name__
|
21
|
-
else
|
22
|
-
Assertion = Test::Unit::AssertionFailedError
|
14
|
+
begin
|
15
|
+
silence_warnings { require 'mocha/setup' }
|
16
|
+
rescue LoadError
|
17
|
+
end
|
23
18
|
|
24
|
-
|
25
|
-
|
19
|
+
module ActiveSupport
|
20
|
+
class TestCase < ::MiniTest::Unit::TestCase
|
21
|
+
Assertion = MiniTest::Assertion
|
22
|
+
alias_method :method_name, :__name__
|
26
23
|
|
27
24
|
$tags = {}
|
28
25
|
def self.for_tag(tag)
|
29
26
|
yield if $tags[tag]
|
30
27
|
end
|
31
28
|
|
29
|
+
# FIXME: we have tests that depend on run order, we should fix that and
|
30
|
+
# remove this method.
|
31
|
+
def self.test_order # :nodoc:
|
32
|
+
:sorted
|
33
|
+
end
|
34
|
+
|
35
|
+
include ActiveSupport::Testing::TaggedLogging
|
32
36
|
include ActiveSupport::Testing::SetupAndTeardown
|
33
37
|
include ActiveSupport::Testing::Assertions
|
34
38
|
include ActiveSupport::Testing::Deprecation
|
35
39
|
include ActiveSupport::Testing::Pending
|
36
40
|
extend ActiveSupport::Testing::Declarative
|
41
|
+
|
42
|
+
# test/unit backwards compatibility methods
|
43
|
+
alias :assert_raise :assert_raises
|
44
|
+
alias :assert_not_empty :refute_empty
|
45
|
+
alias :assert_not_equal :refute_equal
|
46
|
+
alias :assert_not_in_delta :refute_in_delta
|
47
|
+
alias :assert_not_in_epsilon :refute_in_epsilon
|
48
|
+
alias :assert_not_includes :refute_includes
|
49
|
+
alias :assert_not_instance_of :refute_instance_of
|
50
|
+
alias :assert_not_kind_of :refute_kind_of
|
51
|
+
alias :assert_no_match :refute_match
|
52
|
+
alias :assert_not_nil :refute_nil
|
53
|
+
alias :assert_not_operator :refute_operator
|
54
|
+
alias :assert_not_predicate :refute_predicate
|
55
|
+
alias :assert_not_respond_to :refute_respond_to
|
56
|
+
alias :assert_not_same :refute_same
|
57
|
+
|
58
|
+
# Fails if the block raises an exception.
|
59
|
+
#
|
60
|
+
# assert_nothing_raised do
|
61
|
+
# ...
|
62
|
+
# end
|
63
|
+
def assert_nothing_raised(*args)
|
64
|
+
yield
|
65
|
+
end
|
37
66
|
end
|
38
67
|
end
|
@@ -1,51 +1,67 @@
|
|
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
|
+
# Assert 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' # => 'foo' is not 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, :
|
26
|
+
# post :create, article: {...}
|
12
27
|
# end
|
13
28
|
#
|
14
29
|
# An arbitrary expression is passed in and evaluated.
|
15
30
|
#
|
16
31
|
# assert_difference 'assigns(:article).comments(:reload).size' do
|
17
|
-
# post :create, :
|
32
|
+
# post :create, 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, :
|
39
|
+
# post :delete, 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, :
|
44
|
+
# assert_difference [ 'Article.count', 'Post.count' ], 2 do
|
45
|
+
# post :create, 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, :
|
50
|
+
# assert_difference ->{ Article.count }, 2 do
|
51
|
+
# post :create, article: {...}
|
36
52
|
# end
|
37
53
|
#
|
38
54
|
# assert_difference [->{ Article.count }, ->{ Post.count }], 2 do
|
39
|
-
# post :create, :
|
55
|
+
# post :create, 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, :
|
60
|
+
# assert_difference 'Article.count', -1, 'An Article should be destroyed' do
|
61
|
+
# post :delete, 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) }
|
@@ -61,34 +77,48 @@ module ActiveSupport
|
|
61
77
|
end
|
62
78
|
end
|
63
79
|
|
64
|
-
# Assertion that the numeric result of evaluating an expression is not
|
65
|
-
# invoking the passed in block.
|
80
|
+
# Assertion that the numeric result of evaluating an expression is not
|
81
|
+
# changed before and after invoking the passed in block.
|
66
82
|
#
|
67
83
|
# assert_no_difference 'Article.count' do
|
68
|
-
# post :create, :
|
84
|
+
# post :create, article: invalid_attributes
|
69
85
|
# end
|
70
86
|
#
|
71
|
-
#
|
87
|
+
# An error message can be specified.
|
72
88
|
#
|
73
|
-
# assert_no_difference 'Article.count',
|
74
|
-
# post :create, :
|
89
|
+
# assert_no_difference 'Article.count', 'An Article should not be created' do
|
90
|
+
# post :create, article: invalid_attributes
|
75
91
|
# end
|
76
92
|
def assert_no_difference(expression, message = nil, &block)
|
77
93
|
assert_difference expression, 0, message, &block
|
78
94
|
end
|
79
95
|
|
80
|
-
# Test if an expression is blank. Passes if object.blank
|
96
|
+
# Test if an expression is blank. Passes if <tt>object.blank?</tt>
|
97
|
+
# is +true+.
|
81
98
|
#
|
82
|
-
# assert_blank []
|
99
|
+
# assert_blank [] # => true
|
100
|
+
# assert_blank [[]] # => [[]] is not blank
|
101
|
+
#
|
102
|
+
# An error message can be specified.
|
103
|
+
#
|
104
|
+
# assert_blank [], 'this should be blank'
|
83
105
|
def assert_blank(object, message=nil)
|
106
|
+
ActiveSupport::Deprecation.warn('"assert_blank" is deprecated. Please use "assert object.blank?" instead')
|
84
107
|
message ||= "#{object.inspect} is not blank"
|
85
108
|
assert object.blank?, message
|
86
109
|
end
|
87
110
|
|
88
|
-
# Test if an expression is not blank. Passes if object.present
|
111
|
+
# Test if an expression is not blank. Passes if <tt>object.present?</tt>
|
112
|
+
# is +true+.
|
113
|
+
#
|
114
|
+
# assert_present({ data: 'x' }) # => true
|
115
|
+
# assert_present({}) # => {} is blank
|
116
|
+
#
|
117
|
+
# An error message can be specified.
|
89
118
|
#
|
90
|
-
# assert_present
|
119
|
+
# assert_present({ data: 'x' }, 'this should not be blank')
|
91
120
|
def assert_present(object, message=nil)
|
121
|
+
ActiveSupport::Deprecation.warn('"assert_present" is deprecated. Please use "assert object.present?" instead')
|
92
122
|
message ||= "#{object.inspect} is blank"
|
93
123
|
assert object.present?, message
|
94
124
|
end
|
@@ -0,0 +1,52 @@
|
|
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("::").constantize
|
40
|
+
break(constant) if yield(constant)
|
41
|
+
rescue NameError
|
42
|
+
# Constant wasn't found, move on
|
43
|
+
ensure
|
44
|
+
names.pop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -34,22 +34,3 @@ module ActiveSupport
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
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
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|