1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Performance::RangeInclude do
subject(:cop) { described_class.new }
%i[include? member?].each do |method|
it "autocorrects (a..b).#{method} without parens" do
new_source = autocorrect_source("(a..b).#{method} 1")
expect(new_source).to eq '(a..b).cover? 1'
end
it "autocorrects (a...b).#{method} without parens" do
new_source = autocorrect_source("(a...b).#{method} 1")
expect(new_source).to eq '(a...b).cover? 1'
end
it "autocorrects (a..b).#{method} with parens" do
new_source = autocorrect_source("(a..b).#{method}(1)")
expect(new_source).to eq '(a..b).cover?(1)'
end
it "autocorrects (a...b).#{method} with parens" do
new_source = autocorrect_source("(a...b).#{method}(1)")
expect(new_source).to eq '(a...b).cover?(1)'
end
end
it 'formats the error message correctly for (a..b).include? 1' do
expect_offense(<<~RUBY)
(a..b).include? 1
^^^^^^^^ Use `Range#cover?` instead of `Range#include?`.
RUBY
end
it 'formats the error message correctly for (a..b).member? 1' do
expect_offense(<<~RUBY)
(a..b).member? 1
^^^^^^^ Use `Range#cover?` instead of `Range#member?`.
RUBY
end
end
|