Skip to content

Freeze let_it_be objects in `factory_default: :keep` specs

Thong Kuah requested to merge let_it_be_freeze into master

What does this MR do?

Freeze let_it_be objects in factory_default: :keep specs

This should prevent object modification leading to accidental execution order dependencies between tests

Inspired by https://test-prof.evilmartians.io/#/recipes/let_it_be?id=state-leakage-detection.

Finds/solves issues like:

$ bundle exec spring rspec spec/models/project_spec.rb:2880
Running via Spring preloader in process 1545
WARNING: `around(:context)` hooks are not supported and behave like `around(:example). Called from /Users/tkuah/code/ee-gdk/gitlab/spec/support/omniauth_strategy.rb:36:in `block in <main>'.
Run options: include {:focus=>true, :locations=>{"./spec/models/project_spec.rb"=>[2880]}}
F

Failures:

  1) Project#lfs_enabled? LFS disabled globally when no values are set behaves like it always returns false is expected to be falsey
     Failure/Error: expect(project.lfs_enabled?).to be_falsey
     
       expected: falsey value
            got: true
     Shared Example Group: "it always returns false" called from ./spec/models/project_spec.rb:2880
     # ./spec/models/project_spec.rb:2874:in `block (5 levels) in <main>'
     # ./spec/spec_helper.rb:324:in `block (3 levels) in <main>'
     # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:315:in `block (2 levels) in <main>'
     # ./spec/spec_helper.rb:311:in `block (3 levels) in <main>'
     # ./spec/spec_helper.rb:311:in `block (2 levels) in <main>'
     # -e:1:in `<main>'

Finished in 6.01 seconds (files took 4.17 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/models/project_spec.rb[1:91:3:1:1:1] # Project#lfs_enabled? LFS disabled globally when no values are set behaves like it always returns false is expected to be falsey
Edited by Thong Kuah

Merge request reports