Skip to content

Instantly share code, notes, and snippets.

@benmanns
Created March 14, 2018 22:49
Show Gist options
  • Save benmanns/066e591b4e0962d4661dd14b51307d5c to your computer and use it in GitHub Desktop.
Save benmanns/066e591b4e0962d4661dd14b51307d5c to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SymbolArray, :config do
subject(:cop) { described_class.new(config) }
before do
# Reset data which is shared by all instances of SymbolArray
described_class.largest_brackets = -Float::INFINITY
end
let(:other_cops) do
{
'Style/PercentLiteralDelimiters' => {
'PreferredDelimiters' => {
'default' => '()'
}
}
}
end
context 'when EnforcedStyle is percent' do
let(:cop_config) do
{ 'MinSize' => 0,
'EnforcedStyle' => 'percent' }
end
it 'autocorrects arrays of symbols with new line' do
new_source = begin
autocorrect_source("[:one,\n:two, :three,\n:four]")
rescue ArgumentError
autocorrect_source(cop, "[:one,\n:two, :three,\n:four]")
end
expect(new_source).to match(/%i\(one ?\ntwo three ?\nfour\)/)
end
it 'autocorrects arrays of symbols with new line with multiple on first line' do
new_source = begin
autocorrect_source("[:one, :two,\n:three,\n:four]")
rescue ArgumentError
autocorrect_source(cop, "[:one, :two,\n:three,\n:four]")
end
expect(new_source).to match(/%i\(one two ?\nthree ?\nfour\)/)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment