activesupport 3.2.22.5 → 4.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.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +364 -135
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +6 -4
  5. data/lib/active_support/backtrace_cleaner.rb +33 -25
  6. data/lib/active_support/basic_object.rb +7 -17
  7. data/lib/active_support/benchmarkable.rb +19 -15
  8. data/lib/active_support/buffered_logger.rb +9 -113
  9. data/lib/active_support/cache/file_store.rb +14 -14
  10. data/lib/active_support/cache/mem_cache_store.rb +24 -30
  11. data/lib/active_support/cache/memory_store.rb +2 -0
  12. data/lib/active_support/cache/strategy/local_cache.rb +48 -37
  13. data/lib/active_support/cache.rb +228 -183
  14. data/lib/active_support/callbacks.rb +201 -253
  15. data/lib/active_support/concern.rb +16 -23
  16. data/lib/active_support/concurrency/latch.rb +27 -0
  17. data/lib/active_support/configurable.rb +69 -12
  18. data/lib/active_support/core_ext/array/access.rb +17 -9
  19. data/lib/active_support/core_ext/array/conversions.rb +115 -55
  20. data/lib/active_support/core_ext/array/extract_options.rb +2 -2
  21. data/lib/active_support/core_ext/array/grouping.rb +21 -22
  22. data/lib/active_support/core_ext/array/uniq_by.rb +12 -9
  23. data/lib/active_support/core_ext/array/wrap.rb +13 -16
  24. data/lib/active_support/core_ext/array.rb +0 -1
  25. data/lib/active_support/core_ext/benchmark.rb +7 -0
  26. data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -24
  27. data/lib/active_support/core_ext/class/attribute.rb +40 -32
  28. data/lib/active_support/core_ext/class/attribute_accessors.rb +14 -12
  29. data/lib/active_support/core_ext/class/delegating_attributes.rb +15 -19
  30. data/lib/active_support/core_ext/class/subclasses.rb +11 -5
  31. data/lib/active_support/core_ext/date/calculations.rb +44 -187
  32. data/lib/active_support/core_ext/date/conversions.rb +16 -38
  33. data/lib/active_support/core_ext/date/zones.rb +25 -2
  34. data/lib/active_support/core_ext/date.rb +5 -0
  35. data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
  36. data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
  37. data/lib/active_support/core_ext/date_time/calculations.rb +77 -62
  38. data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
  39. data/lib/active_support/core_ext/date_time/zones.rb +11 -8
  40. data/lib/active_support/core_ext/date_time.rb +4 -0
  41. data/lib/active_support/core_ext/enumerable.rb +26 -73
  42. data/lib/active_support/core_ext/file/atomic.rb +27 -11
  43. data/lib/active_support/core_ext/file.rb +0 -1
  44. data/lib/active_support/core_ext/hash/conversions.rb +145 -79
  45. data/lib/active_support/core_ext/hash/deep_merge.rb +14 -8
  46. data/lib/active_support/core_ext/hash/diff.rb +5 -4
  47. data/lib/active_support/core_ext/hash/except.rb +1 -9
  48. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -5
  49. data/lib/active_support/core_ext/hash/keys.rb +108 -24
  50. data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
  51. data/lib/active_support/core_ext/hash/slice.rb +12 -12
  52. data/lib/active_support/core_ext/hash.rb +0 -1
  53. data/lib/active_support/core_ext/integer/inflections.rb +13 -1
  54. data/lib/active_support/core_ext/integer/time.rb +17 -12
  55. data/lib/active_support/core_ext/kernel/debugger.rb +2 -2
  56. data/lib/active_support/core_ext/kernel/reporting.rb +36 -22
  57. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
  58. data/lib/active_support/core_ext/load_error.rb +7 -5
  59. data/lib/active_support/core_ext/logger.rb +7 -23
  60. data/lib/active_support/core_ext/marshal.rb +21 -0
  61. data/lib/active_support/core_ext/module/aliasing.rb +8 -9
  62. data/lib/active_support/core_ext/module/anonymous.rb +2 -7
  63. data/lib/active_support/core_ext/module/attr_internal.rb +0 -1
  64. data/lib/active_support/core_ext/module/attribute_accessors.rb +12 -10
  65. data/lib/active_support/core_ext/module/delegation.rb +92 -49
  66. data/lib/active_support/core_ext/module/deprecation.rb +19 -3
  67. data/lib/active_support/core_ext/module/introspection.rb +17 -27
  68. data/lib/active_support/core_ext/module/qualified_const.rb +8 -20
  69. data/lib/active_support/core_ext/module/remove_method.rb +1 -5
  70. data/lib/active_support/core_ext/module.rb +1 -3
  71. data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
  72. data/lib/active_support/core_ext/numeric/time.rb +6 -6
  73. data/lib/active_support/core_ext/numeric.rb +1 -0
  74. data/lib/active_support/core_ext/object/acts_like.rb +4 -4
  75. data/lib/active_support/core_ext/object/blank.rb +7 -23
  76. data/lib/active_support/core_ext/object/deep_dup.rb +46 -0
  77. data/lib/active_support/core_ext/object/duplicable.rb +1 -30
  78. data/lib/active_support/core_ext/object/inclusion.rb +8 -7
  79. data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
  80. data/lib/active_support/core_ext/object/to_json.rb +8 -0
  81. data/lib/active_support/core_ext/object/to_param.rb +5 -2
  82. data/lib/active_support/core_ext/object/try.rb +46 -25
  83. data/lib/active_support/core_ext/object/with_options.rb +7 -8
  84. data/lib/active_support/core_ext/object.rb +1 -0
  85. data/lib/active_support/core_ext/proc.rb +3 -0
  86. data/lib/active_support/core_ext/range/conversions.rb +0 -2
  87. data/lib/active_support/core_ext/range/include_range.rb +3 -1
  88. data/lib/active_support/core_ext/range/overlaps.rb +1 -1
  89. data/lib/active_support/core_ext/range.rb +0 -2
  90. data/lib/active_support/core_ext/string/access.rb +95 -90
  91. data/lib/active_support/core_ext/string/conversions.rb +27 -38
  92. data/lib/active_support/core_ext/string/encoding.rb +6 -9
  93. data/lib/active_support/core_ext/string/filters.rb +24 -18
  94. data/lib/active_support/core_ext/string/indent.rb +43 -0
  95. data/lib/active_support/core_ext/string/inflections.rb +70 -60
  96. data/lib/active_support/core_ext/string/inquiry.rb +2 -2
  97. data/lib/active_support/core_ext/string/multibyte.rb +41 -64
  98. data/lib/active_support/core_ext/string/output_safety.rb +59 -51
  99. data/lib/active_support/core_ext/string/zones.rb +13 -0
  100. data/lib/active_support/core_ext/string.rb +2 -3
  101. data/lib/active_support/core_ext/struct.rb +6 -0
  102. data/lib/active_support/core_ext/thread.rb +74 -0
  103. data/lib/active_support/core_ext/time/calculations.rb +108 -184
  104. data/lib/active_support/core_ext/time/conversions.rb +27 -51
  105. data/lib/active_support/core_ext/time/marshal.rb +0 -27
  106. data/lib/active_support/core_ext/time/zones.rb +27 -17
  107. data/lib/active_support/core_ext/time.rb +5 -0
  108. data/lib/active_support/core_ext/uri.rb +13 -17
  109. data/lib/active_support/core_ext.rb +3 -2
  110. data/lib/active_support/dependencies/autoload.rb +47 -20
  111. data/lib/active_support/dependencies.rb +160 -141
  112. data/lib/active_support/deprecation/behaviors.rb +44 -30
  113. data/lib/active_support/deprecation/instance_delegator.rb +24 -0
  114. data/lib/active_support/deprecation/method_wrappers.rb +33 -18
  115. data/lib/active_support/deprecation/proxy_wrappers.rb +58 -13
  116. data/lib/active_support/deprecation/reporting.rb +40 -11
  117. data/lib/active_support/deprecation.rb +39 -14
  118. data/lib/active_support/descendants_tracker.rb +34 -19
  119. data/lib/active_support/duration.rb +6 -8
  120. data/lib/active_support/file_update_checker.rb +63 -47
  121. data/lib/active_support/gzip.rb +11 -5
  122. data/lib/active_support/hash_with_indifferent_access.rb +127 -42
  123. data/lib/active_support/i18n.rb +4 -0
  124. data/lib/active_support/i18n_railtie.rb +5 -22
  125. data/lib/active_support/inflections.rb +14 -12
  126. data/lib/active_support/inflector/inflections.rb +108 -71
  127. data/lib/active_support/inflector/methods.rb +181 -160
  128. data/lib/active_support/inflector/transliterate.rb +16 -17
  129. data/lib/active_support/json/decoding.rb +18 -17
  130. data/lib/active_support/json/encoding.rb +93 -39
  131. data/lib/active_support/json/variable.rb +10 -1
  132. data/lib/active_support/key_generator.rb +75 -0
  133. data/lib/active_support/lazy_load_hooks.rb +21 -19
  134. data/lib/active_support/locale/en.yml +100 -3
  135. data/lib/active_support/log_subscriber/test_helper.rb +18 -15
  136. data/lib/active_support/log_subscriber.rb +35 -52
  137. data/lib/active_support/logger.rb +57 -0
  138. data/lib/active_support/logger_silence.rb +24 -0
  139. data/lib/active_support/message_encryptor.rb +38 -35
  140. data/lib/active_support/message_verifier.rb +9 -15
  141. data/lib/active_support/multibyte/chars.rb +80 -333
  142. data/lib/active_support/multibyte/unicode.rb +74 -64
  143. data/lib/active_support/multibyte.rb +5 -28
  144. data/lib/active_support/notifications/fanout.rb +112 -18
  145. data/lib/active_support/notifications/instrumenter.rb +33 -14
  146. data/lib/active_support/notifications.rb +79 -26
  147. data/lib/active_support/number_helper.rb +637 -0
  148. data/lib/active_support/ordered_hash.rb +8 -190
  149. data/lib/active_support/ordered_options.rb +21 -23
  150. data/lib/active_support/per_thread_registry.rb +52 -0
  151. data/lib/active_support/proxy_object.rb +13 -0
  152. data/lib/active_support/rails.rb +27 -0
  153. data/lib/active_support/railtie.rb +12 -32
  154. data/lib/active_support/rescuable.rb +9 -4
  155. data/lib/active_support/string_inquirer.rb +13 -8
  156. data/lib/active_support/subscriber.rb +93 -0
  157. data/lib/active_support/tagged_logging.rb +51 -73
  158. data/lib/active_support/test_case.rb +46 -17
  159. data/lib/active_support/testing/assertions.rb +56 -26
  160. data/lib/active_support/testing/autorun.rb +5 -0
  161. data/lib/active_support/testing/constant_lookup.rb +54 -0
  162. data/lib/active_support/testing/declarative.rb +1 -1
  163. data/lib/active_support/testing/deprecation.rb +0 -19
  164. data/lib/active_support/testing/isolation.rb +29 -58
  165. data/lib/active_support/testing/pending.rb +5 -43
  166. data/lib/active_support/testing/setup_and_teardown.rb +6 -92
  167. data/lib/active_support/testing/tagged_logging.rb +25 -0
  168. data/lib/active_support/time.rb +6 -21
  169. data/lib/active_support/time_with_zone.rb +80 -43
  170. data/lib/active_support/values/time_zone.rb +81 -60
  171. data/lib/active_support/values/unicode_tables.dat +0 -0
  172. data/lib/active_support/version.rb +7 -6
  173. data/lib/active_support/xml_mini/jdom.rb +9 -11
  174. data/lib/active_support/xml_mini/libxml.rb +1 -2
  175. data/lib/active_support/xml_mini/libxmlsax.rb +2 -3
  176. data/lib/active_support/xml_mini/nokogiri.rb +1 -2
  177. data/lib/active_support/xml_mini/nokogirisax.rb +2 -3
  178. data/lib/active_support/xml_mini/rexml.rb +6 -8
  179. data/lib/active_support/xml_mini.rb +35 -17
  180. data/lib/active_support.rb +8 -21
  181. metadata +104 -72
  182. data/lib/active_support/base64.rb +0 -54
  183. data/lib/active_support/core_ext/array/random_access.rb +0 -30
  184. data/lib/active_support/core_ext/date/freeze.rb +0 -33
  185. data/lib/active_support/core_ext/exception.rb +0 -3
  186. data/lib/active_support/core_ext/file/path.rb +0 -5
  187. data/lib/active_support/core_ext/float/rounding.rb +0 -19
  188. data/lib/active_support/core_ext/float.rb +0 -1
  189. data/lib/active_support/core_ext/hash/deep_dup.rb +0 -18
  190. data/lib/active_support/core_ext/io.rb +0 -15
  191. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  192. data/lib/active_support/core_ext/module/synchronization.rb +0 -45
  193. data/lib/active_support/core_ext/process/daemon.rb +0 -23
  194. data/lib/active_support/core_ext/process.rb +0 -1
  195. data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
  196. data/lib/active_support/core_ext/range/cover.rb +0 -3
  197. data/lib/active_support/core_ext/rexml.rb +0 -46
  198. data/lib/active_support/core_ext/string/interpolation.rb +0 -2
  199. data/lib/active_support/core_ext/string/xchar.rb +0 -18
  200. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
  201. data/lib/active_support/memoizable.rb +0 -116
  202. data/lib/active_support/multibyte/exceptions.rb +0 -8
  203. data/lib/active_support/multibyte/utils.rb +0 -60
  204. data/lib/active_support/ruby/shim.rb +0 -22
  205. data/lib/active_support/security_utils.rb +0 -27
  206. data/lib/active_support/testing/mochaing.rb +0 -7
  207. data/lib/active_support/testing/performance/jruby.rb +0 -115
  208. data/lib/active_support/testing/performance/rubinius.rb +0 -113
  209. data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
  210. data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
  211. data/lib/active_support/testing/performance/ruby.rb +0 -152
  212. data/lib/active_support/testing/performance.rb +0 -317
  213. data/lib/active_support/time/autoload.rb +0 -5
  214. 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 class to provide tagging capabilities. Examples:
6
+ # Wraps any standard Logger object to provide tagging capabilities.
7
7
  #
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"
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 it easy to stamp log lines
14
- # with subdomains, request ids, and anything else to aid debugging of multi-user production applications.
15
- class TaggedLogging
16
- def initialize(logger)
17
- @logger = logger
18
- end
19
-
20
- def tagged(*tags)
21
- new_tags = push_tags(*tags)
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
- def push_tags(*tags)
28
- tags.flatten.reject(&:blank?).tap do |new_tags|
29
- current_tags.concat new_tags
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
- def pop_tags(size = 1)
34
- current_tags.pop size
35
- end
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
- def clear_tags!
38
- current_tags.clear
39
- end
36
+ def pop_tags(size = 1)
37
+ current_tags.pop size
38
+ end
40
39
 
41
- def silence(temporary_level = Logger::ERROR, &block)
42
- @logger.silence(temporary_level, &block)
43
- end
44
- deprecate :silence
40
+ def clear_tags!
41
+ current_tags.clear
42
+ end
45
43
 
46
- def add(severity, message = nil, progname = nil, &block)
47
- if message.nil?
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
- %w( fatal error warn info debug unknown ).each do |severity|
59
- eval <<-EOM, nil, __FILE__, __LINE__ + 1
60
- def #{severity}(progname = nil, &block)
61
- add(Logger::#{severity.upcase}, nil, progname, &block)
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 flush
67
- clear_tags!
68
- @logger.flush if @logger.respond_to?(:flush)
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
- def method_missing(method, *args)
72
- @logger.send(method, *args)
73
- end
64
+ delegate :push_tags, :pop_tags, :clear_tags!, to: :formatter
74
65
 
75
- if RUBY_VERSION < '1.9'
76
- def respond_to?(*args)
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
- private
86
- def tags_text
87
- tags = current_tags
88
- if tags.any?
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
- begin
2
- require 'test/unit/testcase'
3
- rescue LoadError => e
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/mochaing'
10
+ require 'active_support/testing/constant_lookup'
13
11
  require 'active_support/core_ext/kernel/reporting'
12
+ require 'active_support/deprecation'
14
13
 
15
- module ActiveSupport
16
- class TestCase < ::Test::Unit::TestCase
17
- if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions
18
- Assertion = MiniTest::Assertion
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
- undef :default_test
25
- end
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
- # Test numeric difference between the return value of an expression as a result of what is evaluated
8
- # in the yielded block.
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, :article => {...}
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, :comment => {...}
32
+ # post :create, comment: {...}
18
33
  # end
19
34
  #
20
- # An arbitrary positive or negative difference can be specified. The default is +1.
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, 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' ], +2 do
29
- # post :create, :article => {...}
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 lambda { Article.count }, 2 do
35
- # post :create, :article => {...}
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, :article => {...}
55
+ # post :create, article: {...}
40
56
  # end
41
57
  #
42
- # A error message can be specified.
58
+ # An error message can be specified.
43
59
  #
44
- # assert_difference 'Article.count', -1, "An Article should be destroyed" do
45
- # post :delete, :id => ...
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.wrap expression
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 changed before and after
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, :article => invalid_attributes
84
+ # post :create, article: invalid_attributes
69
85
  # end
70
86
  #
71
- # A error message can be specified.
87
+ # An error message can be specified.
72
88
  #
73
- # assert_no_difference 'Article.count', "An Article should not be created" do
74
- # post :create, :article => invalid_attributes
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? is true.
96
+ # Test if an expression is blank. Passes if <tt>object.blank?</tt>
97
+ # is +true+.
81
98
  #
82
- # assert_blank [] # => true
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? is true.
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 {:data => 'x' } # => true
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,5 @@
1
+ gem 'minitest'
2
+
3
+ require 'minitest/unit'
4
+
5
+ MiniTest::Unit.autorun
@@ -0,0 +1,54 @@
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 NoMethodError # subclass of NameError
42
+ raise
43
+ rescue NameError
44
+ # Constant wasn't found, move on
45
+ ensure
46
+ names.pop
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -2,7 +2,7 @@ module ActiveSupport
2
2
  module Testing
3
3
  module Declarative
4
4
 
5
- def self.extended(klass)
5
+ def self.extended(klass) #:nodoc:
6
6
  klass.class_eval do
7
7
 
8
8
  unless method_defined?(:describe)
@@ -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
@@ -1,4 +1,6 @@
1
1
  require 'rbconfig'
2
+ require 'minitest/parallel_each'
3
+
2
4
  module ActiveSupport
3
5
  module Testing
4
6
  class RemoteError < StandardError
@@ -38,64 +40,48 @@ module ActiveSupport
38
40
  def method_missing(name, *args)
39
41
  @calls << [name, args]
40
42
  end
43
+
44
+ def info_signal
45
+ Signal.list['INFO']
46
+ end
41
47
  end
42
48
 
43
49
  module Isolation
44
- def self.forking_env?
45
- !ENV["NO_FORK"] && ((RbConfig::CONFIG['host_os'] !~ /mswin|mingw/) && (RUBY_PLATFORM !~ /java/))
46
- end
50
+ require 'thread'
47
51
 
48
- def self.included(base)
49
- if defined?(::MiniTest) && base < ::MiniTest::Unit::TestCase
50
- base.send :include, MiniTest
51
- elsif defined?(Test::Unit)
52
- base.send :include, TestUnit
53
- end
52
+ def self.included(klass) #:nodoc:
53
+ klass.extend(Module.new {
54
+ def test_methods
55
+ ParallelEach.new super
56
+ end
57
+ })
54
58
  end
55
59
 
56
- def _run_class_setup # class setup method should only happen in parent
57
- unless defined?(@@ran_class_setup) || ENV['ISOLATION_TEST']
58
- self.class.setup if self.class.respond_to?(:setup)
59
- @@ran_class_setup = true
60
- end
60
+ def self.forking_env?
61
+ !ENV["NO_FORK"] && ((RbConfig::CONFIG['host_os'] !~ /mswin|mingw/) && (RUBY_PLATFORM !~ /java/))
61
62
  end
62
63
 
63
- module TestUnit
64
- def run(result)
65
- _run_class_setup
66
-
67
- yield(Test::Unit::TestCase::STARTED, name)
68
-
69
- @_result = result
64
+ @@class_setup_mutex = Mutex.new
70
65
 
71
- serialized = run_in_isolation do |proxy|
72
- begin
73
- super(proxy) { }
74
- rescue Exception => e
75
- proxy.add_error(Test::Unit::Error.new(name, e))
76
- end
66
+ def _run_class_setup # class setup method should only happen in parent
67
+ @@class_setup_mutex.synchronize do
68
+ unless defined?(@@ran_class_setup) || ENV['ISOLATION_TEST']
69
+ self.class.setup if self.class.respond_to?(:setup)
70
+ @@ran_class_setup = true
77
71
  end
78
-
79
- retval, proxy = Marshal.load(serialized)
80
- proxy.__replay__(@_result)
81
-
82
- yield(Test::Unit::TestCase::FINISHED, name)
83
- retval
84
72
  end
85
73
  end
86
74
 
87
- module MiniTest
88
- def run(runner)
89
- _run_class_setup
75
+ def run(runner)
76
+ _run_class_setup
90
77
 
91
- serialized = run_in_isolation do |isolated_runner|
92
- super(isolated_runner)
93
- end
94
-
95
- retval, proxy = Marshal.load(serialized)
96
- proxy.__replay__(runner)
97
- retval
78
+ serialized = run_in_isolation do |isolated_runner|
79
+ super(isolated_runner)
98
80
  end
81
+
82
+ retval, proxy = Marshal.load(serialized)
83
+ proxy.__replay__(runner)
84
+ retval
99
85
  end
100
86
 
101
87
  module Forking
@@ -153,18 +139,3 @@ module ActiveSupport
153
139
  end
154
140
  end
155
141
  end
156
-
157
- # Only in subprocess for windows / jruby.
158
- if ENV['ISOLATION_TEST']
159
- begin
160
- require "test/unit/collector/objectspace"
161
- rescue LoadError => e
162
- raise LoadError, "Please add test-unit gem to your Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})", e.backtrace
163
- end
164
-
165
- class Test::Unit::Collector::ObjectSpace
166
- def include?(test)
167
- super && test.method_name == ENV['ISOLATION_TEST']
168
- end
169
- end
170
- end
@@ -1,52 +1,14 @@
1
- # Some code from jeremymcanally's "pending"
2
- # https://github.com/jeremymcanally/pending/tree/master
1
+ require 'active_support/deprecation'
3
2
 
4
3
  module ActiveSupport
5
4
  module Testing
6
- module Pending
7
-
8
- unless defined?(Spec)
9
-
10
- @@pending_cases = []
11
- @@at_exit = false
12
-
5
+ module Pending # :nodoc:
6
+ unless defined?(Spec)
13
7
  def pending(description = "", &block)
14
- if defined?(::MiniTest)
15
- skip(description.blank? ? nil : description)
16
- else
17
- if description.is_a?(Symbol)
18
- is_pending = $tags[description]
19
- return block.call unless is_pending
20
- end
21
-
22
- if block_given?
23
- failed = false
24
-
25
- begin
26
- block.call
27
- rescue Exception
28
- failed = true
29
- end
30
-
31
- flunk("<#{description}> did not fail.") unless failed
32
- end
33
-
34
- caller[0] =~ (/(.*):(.*):in `(.*)'/)
35
- @@pending_cases << "#{$3} at #{$1}, line #{$2}"
36
- print "P"
37
-
38
- @@at_exit ||= begin
39
- at_exit do
40
- puts "\nPending Cases:"
41
- @@pending_cases.each do |test_case|
42
- puts test_case
43
- end
44
- end
45
- end
46
- end
8
+ ActiveSupport::Deprecation.warn("#pending is deprecated and will be removed in Rails 4.1, please use #skip instead.")
9
+ skip(description.blank? ? nil : description)
47
10
  end
48
11
  end
49
-
50
12
  end
51
13
  end
52
14
  end