lib/rubocop/cop/rspec/example_length.rb in rubocop-rspec-2.2.0 vs lib/rubocop/cop/rspec/example_length.rb in rubocop-rspec-2.3.0
- old
+ new
@@ -23,32 +23,46 @@
# it do
# service = described_class.new
# result = service.call
# expect(result).to be(true)
# end
+ #
+ # You can set literals you want to fold with `CountAsOne`.
+ # Available are: 'array', 'hash', and 'heredoc'. Each literal
+ # will be counted as one line regardless of its actual size.
+ #
+ # @example CountAsOne: ['array', 'heredoc']
+ #
+ # it do
+ # array = [ # +1
+ # 1,
+ # 2
+ # ]
+ #
+ # hash = { # +3
+ # key: 'value'
+ # }
+ #
+ # msg = <<~HEREDOC # +1
+ # Heredoc
+ # content.
+ # HEREDOC
+ # end # 5 points
class ExampleLength < Base
include CodeLength
- MSG = 'Example has too many lines [%<total>d/%<max>d].'
+ LABEL = 'Example'
def on_block(node)
return unless example?(node)
- length = code_length(node)
-
- return unless length > max_length
-
- add_offense(node, message: message(length))
+ check_code_length(node)
end
private
- def code_length(node)
- node.source.lines[1..-2].count { |line| !irrelevant_line(line) }
- end
-
- def message(length)
- format(MSG, total: length, max: max_length)
+ def cop_label
+ LABEL
end
end
end
end
end