Skip to content

Pass model spec location as caller to lint factories shared examples

What does this MR do and why?

This enables the use of the correct model spec location as opposed to this very shared examples location during RSpec retry.

Closes #474262 (closed)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Make a factory invalid. For example:
diff --git a/spec/factories/award_emoji.rb b/spec/factories/award_emoji.rb
index d0b525e165da..567f0afd264d 100644
--- a/spec/factories/award_emoji.rb
+++ b/spec/factories/award_emoji.rb
@@ -2,7 +2,7 @@
 
 FactoryBot.define do
   factory :award_emoji do
-    name { "thumbsup" }
+    name { nil }
     user
     awardable factory: :issue
 
  1. Run corresponding model specs and observe example failures pointing to the model spec location:
bin/rspec spec/models/award_emoji_spec.rb

...

Finished in 1 minute 43.08 seconds (files took 30.55 seconds to load)
49 examples, 15 failures, 2 pending

Failed examples:

rspec ./spec/models/award_emoji_spec.rb:24 # AwardEmoji validations scoped uniqueness validation rejects duplicate award emoji
rspec ./spec/models/award_emoji_spec.rb:38 # AwardEmoji validations scoped uniqueness validation allows duplicate award emoji for ghost users
rspec ./spec/models/award_emoji_spec.rb:53 # AwardEmoji validations scoped uniqueness validation when importing allows duplicate award emoji
rspec ./spec/models/award_emoji_spec.rb:204 # AwardEmoji bumping updated at calls bump_updated_at on the note when saved
rspec ./spec/models/award_emoji_spec.rb:220 # AwardEmoji bumping updated at on another awardable does not error out when saved
rspec ./spec/models/award_emoji_spec.rb:189 # AwardEmoji broadcasting updates on another awardable does not broadcast updates on the issue when destroyed
rspec ./spec/models/award_emoji_spec.rb:182 # AwardEmoji broadcasting updates on another awardable does not broadcast updates on the issue when saved
rspec ./spec/models/award_emoji_spec.rb:150 # AwardEmoji broadcasting updates on a note broadcasts updates on the note when saved
rspec ./spec/models/award_emoji_spec.rb:157 # AwardEmoji broadcasting updates on a note broadcasts updates on the note when destroyed
rspec ./spec/models/award_emoji_spec.rb:169 # AwardEmoji broadcasting updates on a note when importing does not broadcast updates on the note when saved
rspec ./spec/models/award_emoji_spec.rb:278 # AwardEmoji updating upvotes_count on another awardable does not update upvotes_count on the merge_request when saved
rspec ./spec/models/award_emoji_spec.rb:266 # AwardEmoji updating upvotes_count on an issue updates upvotes_count on the issue when destroyed
rspec ./spec/models/award_emoji_spec.rb:259 # AwardEmoji updating upvotes_count on an issue updates upvotes_count on the issue when saved
rspec ./spec/models/award_emoji_spec.rb[1:3:1:1:2] # Lint factories for AwardEmoji with saas, license, and factory defaults behaves like factory award_emoji factory does not raise error when created
rspec ./spec/models/award_emoji_spec.rb[1:3:1:1:3:1] # Lint factories for AwardEmoji with saas, license, and factory defaults behaves like factory award_emoji factory linting :upvote trait does not raise error when created

How to verify on CI

See 🔴 https://gitlab.com/gitlab-org/gitlab/-/jobs/7437972340 where the failing factory lint spec was retried!

Edited by Peter Leitzen

Merge request reports

Loading