Class: RuboCop::Cop::Rails::RedundantTravelBack
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::RedundantTravelBack
- Extended by:
- AutoCorrector, TargetRailsVersion
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/rails/redundant_travel_back.rb
Overview
Checks for redundant ‘travel_back` calls. Since Rails 5.2, `travel_back` is automatically called at the end of the test.
Constant Summary collapse
- MSG =
'Redundant `travel_back` detected.'
- RESTRICT_ON_SEND =
%i[travel_back].freeze
Constants included from TargetRailsVersion
TargetRailsVersion::TARGET_GEM_NAME, TargetRailsVersion::USES_REQUIRES_GEM_API
Instance Method Summary collapse
Methods included from TargetRailsVersion
minimum_target_rails_version, support_target_rails_version?
Instance Method Details
#on_send(node) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubocop/cop/rails/redundant_travel_back.rb', line 43 def on_send(node) return unless node.each_ancestor(:def, :block).any? do |ancestor| method_name = ancestor.def_type? ? :teardown : :after ancestor.method?(method_name) end add_offense(node) do |corrector| corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true)) end end |