IntelliJ Ruby warning "Cannot resolve properly, was not processed"

Viewed 895

I have many lines in my specs that result in this IntelliJ warning:

"Cannot resolve properly, was not processed"

The vast majority of the lines have this format:

expect(result[:err]).to include('(Check the file permissions.)')

If I move the literal string to a separate variable, the warning goes away:

    msg = '(Check the file permissions.)'
    expect(result[:err]).to include(msg)

Is there a way to make this error go away (other than moving all my string literals to variables)?

3 Answers

My guess is that the RubyMine parser thinks that include is the Ruby keyword to include a module and so it emits a warning telling it cannot find the corresponding module.

The only way I found to fix this warning is to use the inclusion alias proposed by the rspec include matcher :

expect(result[:err]).to inclusion('(Check the file permissions.)')

This fixes the warning and the expectation works the same, but sadly the english sentence is bad.

There is also 3 other aliases available, but they don't give better english syntax:

alias_matcher :a_collection_including, :include
alias_matcher :a_string_including,     :include
alias_matcher :a_hash_including,       :include
alias_matcher :including,              :include

These alias definitions can be found here

Maybe by chance this answer could lead someone to a better solution.

If you're willing to switch from using the word include to something like contain, you could simply create a custom matcher:

RSpec::Matchers.define :contain do |expected|
  match do |actual|
    expect(actual).to include(expected)
  end
end

You could either add that code directly in your rails_helper.rb file, or better yet in a separate file. For instance, create spec/support/custom_matchers.rb and place the code there. You'll need to make sure that file gets included when running rspec. To do that, you could uncomment the following line which appears in the default spec/rails_helper.rb file:

# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }

With that in place, your spec file would read:

expect(result[:err]).to contain('(Check the file permissions.)')

It can be fixed by adding this to rails_helper.rb or support/rubymine_stubs.rb:

# Rubymine IDE underlines `include` matchers with warning "Cannot resolve properly, was not processed"
# To fix this issue let's make an alias `contain` and use it instead
RSpec::Matchers.alias_matcher :contain, :include

module RubymineStubs
  # create stub for `contain` so Rubymine won't underline it
  def contain(*_args) end
end
Related