Skip to content

Add means to fail test for expectations set on nil

Created by: lizrush

This PR adds a configuration option for setting expectations on nil. Previously there was an option to allow_expectations_on_nil that would either warn by default or suppress the warnings when an expectation was set on nil.

Now, we have the following options that can be set inside an RSpec configuration:

  • Do nothing with the config flag and retain the default behavior:
    • RSpec will warn the user when an expectation has been set on nil, but the test will not fail
  • Set allow_expectations_on_nil to true:
    • RSpec will suppress the warning messages
  • Set allow_expectations_on_nil to false:
    • RSpec will fail the test when the expectation has been set on nil.

This will help catch false positives and help prevent users from thinking their tests are fine when green but warnings that were given were not read.

Merge request reports