# Stricter Tests for Expectations Set on Nil in RSpec

DevFeed: [Stricter Tests for Expectations Set on Nil in RSpec](<https://devfeed.tech/articles/stricter-tests-for-expectations-set-on-nil-in-rspec-15898.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/stricter-tests-for-expectations-set-on-nil-in-rspec>)

Author: Square Engineering

Published: 2015-06-19T07:00:00Z

Content type: article

Language: en

Sources: [Square Corner](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [RSpec](<https://devfeed.tech/topics/rspec.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>)

Tags: [bug](<https://devfeed.tech/tags/bug.md>), [code-review](<https://devfeed.tech/tags/code-review.md>), [config](<https://devfeed.tech/tags/config.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [context](<https://devfeed.tech/tags/context.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [errors](<https://devfeed.tech/tags/errors.md>), [expectation](<https://devfeed.tech/tags/expectation.md>), [fail](<https://devfeed.tech/tags/fail.md>), [false-positives](<https://devfeed.tech/tags/false-positives.md>), [framework](<https://devfeed.tech/tags/framework.md>), [logger](<https://devfeed.tech/tags/logger.md>), [logs](<https://devfeed.tech/tags/logs.md>), [maintainers](<https://devfeed.tech/tags/maintainers.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [tests](<https://devfeed.tech/tags/tests.md>)

## AI overview

The article describes an RSpec mocks configuration for catching false-positive tests caused by setting expectations on nil. Leave the setting unchanged to keep the default warning without failing the test; set `allow_message_expectations_on_nil` to `true` to suppress the warning, or to `false` to make the test raise `RSpec::Mocks::MockExpectationError`. The article also shows how maintainers tested the stricter behavior using isolated configuration so it would not affect the rest of the suite.

## Source excerpt

Make your RSpec tests fail when expectations are set on nil.