Module: ActiveSupport::DeprecationTestHelper
- Defined in:
- lib/active_support/deprecation_test_helper.rb,
lib/active_support/deprecation_test_helper/version.rb
Constant Summary collapse
- CONFIGURABLE_TEST_FRAMEWORKS =
[:rspec, :minitest].freeze
- VERSION =
"0.2.0"
Class Method Summary collapse
- .after_all_callback ⇒ Object
- .allow_warning(message_or_regex) ⇒ Object
- .configure(test_framework) ⇒ Object
- .reset ⇒ Object
- .track_warning(warning) ⇒ Object
- .unexpected_warnings_message ⇒ Object
Instance Method Summary collapse
Class Method Details
.after_all_callback ⇒ Object
37 38 39 |
# File 'lib/active_support/deprecation_test_helper.rb', line 37 def after_all_callback -> { unexpected_warnings.any? and warn } end |
.allow_warning(message_or_regex) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/active_support/deprecation_test_helper.rb', line 30 def allow_warning() unless .is_a?(String) || .is_a?(Regexp) raise ArgumentError, "Expected message_or_regex to be a String or a Regexp but was a #{.class.name}" end allowed_warnings << end |
.configure(test_framework) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/active_support/deprecation_test_helper.rb', line 12 def configure(test_framework) test_framework.in?(CONFIGURABLE_TEST_FRAMEWORKS) or raise "Unexpected test framework encountered. Supported frameworks are #{CONFIGURABLE_TEST_FRAMEWORKS.join(' ')}" ActiveSupport::Deprecation.include(self) case test_framework when :rspec RSpec.configuration.after(:suite) { ActiveSupport::DeprecationTestHelper.after_all_callback.call } when :minitest Minitest.after_run(&after_all_callback) end end |
.reset ⇒ Object
25 26 27 28 |
# File 'lib/active_support/deprecation_test_helper.rb', line 25 def reset @allowed_warnings = Set.new @unexpected_warnings = Set.new end |
.track_warning(warning) ⇒ Object
49 50 51 52 53 |
# File 'lib/active_support/deprecation_test_helper.rb', line 49 def track_warning(warning) if warning && !expected_warning?(warning) unexpected_warnings << warning end end |
.unexpected_warnings_message ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/active_support/deprecation_test_helper.rb', line 41 def <<~EOS.chomp ===== #{(['Unexpected Deprecation Warnings Encountered'] + unexpected_warnings.to_a).join("\n ")} ===== EOS end |
Instance Method Details
#behavior ⇒ Object
70 71 72 |
# File 'lib/active_support/deprecation_test_helper.rb', line 70 def behavior [::ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:silence]] end |
#deprecation_warning(*_args) ⇒ Object
66 67 68 |
# File 'lib/active_support/deprecation_test_helper.rb', line 66 def deprecation_warning(*_args) super.tap { |warning| ActiveSupport::DeprecationTestHelper.track_warning(warning) } end |