class RuboCop::Cop::RSpec::BeEql
coerce objects for comparison.
necessarily the same type as ‘b` since the `#==` operator can
`a == b`, and `b` is comparable by identity, `a` is still not
than `!equal?`. We also do not try to flag `eq` because if
do not check `to_not` or `not_to` since `!eql?` is more strict
This cop only looks for instances of `expect(…).to eql(…)`. We
expect(foo).to be(nil)
expect(foo).to be(:bar)
expect(foo).to be(false)
expect(foo).to be(true)
expect(foo).to be(1.0)
expect(foo).to be(1)
# good
expect(foo).to eql(nil)
expect(foo).to eql(:bar)
expect(foo).to eql(false)
expect(foo).to eql(true)
expect(foo).to eql(1.0)
expect(foo).to eql(1)
# bad
@example
This cop is unsafe because it changes how values are compared.
@safety
preferable as it is a more strict test.
can be compared by identity and therefore the `be` matcher is
compares using `eql?`. Integers, floats, booleans, symbols, and nil
The `be` matcher compares by identity while the `eql` matcher
Check for expectations where `be(…)` can replace `eql(…)`.
def on_send(node)
def on_send(node) eql_type_with_identity(node) do |eql| add_offense(eql.loc.selector) do |corrector| corrector.replace(eql.loc.selector, 'be') end end end