Stub Feature.enabled? in a way that it can capture misuse

In https://gitlab.com/gitlab-org/gitlab-ee/issues/9738 we got an error upon misusing against Feature.enabled? but it didn't get caught in the tests, because we stubbed it universally without checking the arguments at all in spec/spec_helper.rb:

allow(Feature).to receive(:enabled?) { true }

We should update this so that it can capture such problem. Maybe something like this:

# Enable all features by default for testing
allow(Feature).to receive(:enabled?)
  .with(kind_of(Symbol)) { true }

allow(Feature).to receive(:enabled?)
  .with(kind_of(Symbol), hash_including(:default_enabled)) { true }

allow(Feature).to receive(:enabled?)
  .with(kind_of(Symbol), anything, hash_including(:default_enabled)) { true }

The following discussion from !9532 (merged) should be addressed:

  • @godfat started a discussion: (+9 comments)

    What do you think if we also test that for_environment will be called when the feature is enabled, in another test? Because I am thinking if the method is renamed or moved, this test can still pass, and if we have another test making sure that the method will be called, in that case that test will fail and we should see that we need to change this test, too.

Assignee Loading
Time tracking Loading