diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/rubocop/cop/performance/readlines_each_spec.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) | |
download | gitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/rubocop/cop/performance/readlines_each_spec.rb')
-rw-r--r-- | spec/rubocop/cop/performance/readlines_each_spec.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/spec/rubocop/cop/performance/readlines_each_spec.rb b/spec/rubocop/cop/performance/readlines_each_spec.rb index c19426606f6..5a30107722a 100644 --- a/spec/rubocop/cop/performance/readlines_each_spec.rb +++ b/spec/rubocop/cop/performance/readlines_each_spec.rb @@ -5,19 +5,21 @@ require 'rubocop' require_relative '../../../../rubocop/cop/performance/readlines_each' RSpec.describe RuboCop::Cop::Performance::ReadlinesEach do - include CopHelper - subject(:cop) { described_class.new } let(:message) { 'Avoid `IO.readlines.each`, since it reads contents into memory in full. Use `IO.each_line` or `IO.each` instead.' } shared_examples_for(:class_read) do |klass| context "and it is called as a class method on #{klass}" do - # We can't use `expect_offense` here because indentation changes based on `klass` it 'flags it as an offense' do - inspect_source "#{klass}.readlines(file_path).each { |line| puts line }" + leading_readline = "#{klass}.readlines(file_path)." + padding = " " * leading_readline.length + node = "#{leading_readline}each { |line| puts line }" - expect(cop.offenses.map(&:cop_name)).to contain_exactly('Performance/ReadlinesEach') + expect_offense(<<~CODE, node: node) + %{node} + #{padding}^^^^ Avoid `IO.readlines.each`, since it reads contents into memory in full. [...] + CODE end end @@ -62,9 +64,14 @@ RSpec.describe RuboCop::Cop::Performance::ReadlinesEach do end it 'autocorrects `readlines.each` to `each_line`' do - expect(autocorrect_source('obj.readlines.each { |line| line }')).to( - eq('obj.each_line { |line| line }') - ) + expect_offense(<<~CODE) + obj.readlines.each { |line| line } + ^^^^ Avoid `IO.readlines.each`, since it reads contents into memory in full. [...] + CODE + + expect_correction(<<~CODE) + obj.each_line { |line| line } + CODE end end |