Skip to content

Fix Expectation Set on Nil Warning in Namespace Spec

Jason Goodman requested to merge expectation-on-nil-in-namespace-spec into master

What does this MR do and why?

The following warnings are currently in the test suite on the master branch:

WARNING: An expectation of `:privatized_by_abuse_automation?` was set on `nil`. To allow expectations on `nil` and suppress this message, set `RSpec::Mocks.configuration.allow_message_expectations_on_nil` to `true`. To disallow expectations on `nil`, set `RSpec::Mocks.configuration.allow_message_expectations_on_nil` to `false`. Called from /Users/jason/code/gdk/gitlab/ee/spec/models/ee/namespace_spec.rb:368:in `block (5 levels) in <main>'

This is caused by the following lines in ee/spec/models/ee/namespace_spec.rb: https://gitlab.com/gitlab-org/gitlab/-/blob/7380044816aeca3ee1bc8e78a0dfcf08b7b28c79/ee/spec/models/ee/namespace_spec.rb#L368-369

This is because sometimes namespace.owner is nil. Which is because the different factories for group, user, and project namespaces set the owner in different ways (some don't set the owner at all).

This MR adjusts the specs so that the namespace always has an owner. It also adjusts the stub to be set directly on the owner rather than on namespace.owner.

How to set up and validate locally

  1. Run bin/rspec ee/spec/models/ee/namespace_spec.rb on the master branch. Observe the warnings mentioned above.
  2. Run bin/rspec ee/spec/models/ee/namespace_spec.rb on this branch. Observe the warnings are gone.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Jason Goodman

Merge request reports