Skip to content

Is RSpec/ReceiveNever even a valid cop? #1755

Open
@ekohl

Description

@ekohl

Summary

The RSpec/ReceiveNever cop says:

Prefer not_to receive(...) over receive(...).never

When running rspec it says:

allow(...).not_to receive is not supported since it doesn't really make sense. What would it even mean?

Either I'm doing something wrong, or the whole cop is invalid.

Details

In #628 the RSpec/ReceiveNever cop was added, but there's this code:
https://github.com/puppetlabs/puppetlabs-stdlib/blob/7e7ded41443750e6643599fa02ad4456e781fede/spec/functions/loadjson_spec.rb#L31-L35

Or a minimal example: allow(JSON).to receive(:parse).never. The cop suggests this should be allow(JSON).not_to receive(:parse) but when I run that, the tests fail with:

$ bundle exec rspec ./spec/functions/loadjson_spec.rb
...
Failures:

  1) loadjson when calling with valid arguments when a non-existing file is specified 
     Failure/Error: allow(JSON).not_to receive(:parse)
       `allow(...).not_to receive` is not supported since it doesn't really make sense. What would it even mean?
     # ./spec/functions/loadjson_spec.rb:34:in `block (4 levels) in <top (required)>'
     # /home/ekohl/.local/share/gem/ruby/bin/rspec:25:in `load'
     # /home/ekohl/.local/share/gem/ruby/bin/rspec:25:in `<top (required)>'
     # /usr/bin/bundle:25:in `load'
     # /usr/bin/bundle:25:in `<main>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions