Skip to content

Commit 82ba67f

Browse files
committed
Fix bug caused when factory block is empty
1 parent 1e16af9 commit 82ba67f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/rubocop/cop/rspec/factory_bot/association_style.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def children_of_factory_block(node)
141141
block = node.parent
142142
return [] unless block
143143
return [] unless block.block_type?
144+
return [] unless block.body
144145

145146
if block.body.begin_type?
146147
block.body.children

spec/rubocop/cop/rspec/factory_bot/association_style_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ def inspected_source_filename
1212
context 'when EnforcedStyle is :implicit' do
1313
let(:enforced_style) { :implicit }
1414

15+
context 'when factory block is empty' do
16+
it 'does not register an offense' do
17+
expect_no_offenses(<<~RUBY)
18+
factory :user do
19+
end
20+
RUBY
21+
end
22+
end
23+
24+
context 'with when factory has no block' do
25+
it 'does not register an offense' do
26+
expect_no_offenses(<<~RUBY)
27+
factory :user
28+
RUBY
29+
end
30+
end
31+
1532
context 'when implicit style is used' do
1633
it 'does not register an offense' do
1734
expect_no_offenses(<<~RUBY)

0 commit comments

Comments
 (0)