Sha256: 3244baf00ec36dbddee85d30b396d89f01527e06b3f2c2368a654e9b4e0a46ff
Contents?: true
Size: 1.24 KB
Versions: 8
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RSpec # Checks for long examples. # # A long example is usually more difficult to understand. Consider # extracting out some behaviour, e.g. with a `let` block, or a helper # method. # # @example # # bad # it do # service = described_class.new # more_setup # more_setup # result = service.call # expect(result).to be(true) # end # # # good # it do # service = described_class.new # result = service.call # expect(result).to be(true) # end class ExampleLength < Cop include CodeLength MSG = 'Example has too many lines [%d/%d].'.freeze def on_block(node) return unless example?(node) length = code_length(node) return unless length > max_length add_offense(node, :expression, message(length)) end private def code_length(node) node.source.lines[1..-2].count { |line| !irrelevant_line(line) } end def message(length) format(MSG, length, max_length) end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems