Sha256: 2b7ee87bfb8dbe52f361ba77b8660991f234e88da3a896155570b24b0f8514c0

Contents?: true

Size: 1.3 KB

Versions: 13

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Rails
      # This cop checks for redundant `travel_back` calls.
      # Since Rails 5.2, `travel_back` is automatically called at the end of the test.
      #
      # @example
      #
      #   # bad
      #   def teardown
      #     do_something
      #     travel_back
      #   end
      #
      #   # good
      #   def teardown
      #     do_something
      #   end
      #
      #   # bad
      #   after do
      #     do_something
      #     travel_back
      #   end
      #
      #   # good
      #   after do
      #     do_something
      #   end
      #
      class RedundantTravelBack < Base
        include RangeHelp
        extend AutoCorrector
        extend TargetRailsVersion

        minimum_target_rails_version 5.2

        MSG = 'Redundant `travel_back` detected.'
        RESTRICT_ON_SEND = %i[travel_back].freeze

        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
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rails-2.14.2/lib/rubocop/cop/rails/redundant_travel_back.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rails-2.14.2/lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.14.2 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.14.1 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.14.0 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.13.2 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.13.1 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.13.0 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.12.4 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.12.3 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.12.2 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.12.1 lib/rubocop/cop/rails/redundant_travel_back.rb
rubocop-rails-2.12.0 lib/rubocop/cop/rails/redundant_travel_back.rb