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

Instance Method Summary collapse

Class Method Details

.after_all_callbackObject



37
38
39
# File 'lib/active_support/deprecation_test_helper.rb', line 37

def after_all_callback
  -> { unexpected_warnings.any? and warn unexpected_warnings_message }
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(message_or_regex)
  unless message_or_regex.is_a?(String) || message_or_regex.is_a?(Regexp)
    raise ArgumentError, "Expected message_or_regex to be a String or a Regexp but was a #{message_or_regex.class.name}"
  end
  allowed_warnings << message_or_regex
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

.resetObject



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_messageObject



41
42
43
44
45
46
47
# File 'lib/active_support/deprecation_test_helper.rb', line 41

def unexpected_warnings_message
  <<~EOS.chomp
    =====
    #{(['Unexpected Deprecation Warnings Encountered'] + unexpected_warnings.to_a).join("\n  ")}
    =====
  EOS
end

Instance Method Details

#behaviorObject



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