Skip to content

Commit 5562241

Browse files
bquorningkoic
authored andcommitted
Move autocorrection specs into a describe block
It's harder to read specs when "no offense" examples, "offense message" examples and autocorrection examples are mixed together.
1 parent aad26f6 commit 5562241

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

spec/rubocop/cop/rails/validation_spec.rb

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
RSpec.describe RuboCop::Cop::Rails::Validation do
44
subject(:cop) { described_class.new }
55

6+
it 'accepts new style validations' do
7+
expect_no_offenses('validates :name')
8+
end
9+
610
described_class::DENYLIST.each_with_index do |validation, number|
711
it "registers an offense for #{validation}" do
812
inspect_source("#{validation} :name")
@@ -16,36 +20,34 @@
1620
end
1721
end
1822

19-
described_class::TYPES.each do |parameter|
20-
it "autocorrect validates_#{parameter}_of" do
23+
describe 'autocorrect' do
24+
described_class::TYPES.each do |parameter|
25+
it "corrects validates_#{parameter}_of" do
26+
new_source = autocorrect_source(
27+
"validates_#{parameter}_of :full_name, :birth_date"
28+
)
29+
expect(new_source).to eq(
30+
"validates :full_name, :birth_date, #{parameter}: true"
31+
)
32+
end
33+
end
34+
35+
it 'corrects validates_numericality_of with options' do
2136
new_source = autocorrect_source(
22-
"validates_#{parameter}_of :full_name, :birth_date"
37+
'validates_numericality_of :age, minimum: 0, maximum: 122'
2338
)
2439
expect(new_source).to eq(
25-
"validates :full_name, :birth_date, #{parameter}: true"
40+
'validates :age, numericality: { minimum: 0, maximum: 122 }'
2641
)
2742
end
28-
end
29-
30-
it 'accepts new style validations' do
31-
expect_no_offenses('validates :name')
32-
end
3343

34-
it 'autocorrect validates_length_of' do
35-
new_source = autocorrect_source(
36-
'validates_numericality_of :age, minimum: 0, maximum: 122'
37-
)
38-
expect(new_source).to eq(
39-
'validates :age, numericality: { minimum: 0, maximum: 122 }'
40-
)
41-
end
42-
43-
it 'autocorrect validates_numericality_of with options in braces' do
44-
new_source = autocorrect_source(
45-
'validates_numericality_of :age, { minimum: 0, maximum: 122 }'
46-
)
47-
expect(new_source).to eq(
48-
'validates :age, numericality: { minimum: 0, maximum: 122 }'
49-
)
44+
it 'autocorrect validates_numericality_of with options in braces' do
45+
new_source = autocorrect_source(
46+
'validates_numericality_of :age, { minimum: 0, maximum: 122 }'
47+
)
48+
expect(new_source).to eq(
49+
'validates :age, numericality: { minimum: 0, maximum: 122 }'
50+
)
51+
end
5052
end
5153
end

0 commit comments

Comments
 (0)