class RuboCop::Cop::RSpec::BeEq
expect(foo).to be(nil)
expect(foo).to be(false)
expect(foo).to be(true)
# good
expect(foo).to eq(nil)
expect(foo).to eq(false)
expect(foo).to eq(true)
# bad
@example
This cop is unsafe because it changes how values are compared.
@safety
the ‘be` matcher is preferable as it is a more strict test.
using `==`. Booleans and nil can be compared by identity and therefore
The `be` matcher compares by identity while the `eq` matcher compares
Check for expectations where `be(…)` can replace `eq(…)`.
def on_send(node)
def on_send(node) return unless eq_type_with_identity?(node) add_offense(node.loc.selector) do |corrector| corrector.replace(node.loc.selector, 'be') end end