RubyMine doesn't recognize `it_behaves_like` method

1.4k Views Asked by At

When I open a spec like it_behaves_like method is not recognized by RubyMine with error message can't find 'it_behaves_like'.

The RSpec test itself works fine, so somehow RubyMine can't find the method.

In the Preference rspec-rails is listed.enter image description here

How can I find where the problem stand?

Edit

It seems RubyMine can't recognize dynamically defined method.

https://youtrack.jetbrains.com/issue/RUBY-13950

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, RubyMine, even latest version has a problem recognising these generated methods. You have the option of "tricking" RubyMine into recognising it though. Simply add the following empty method to the end of your spec_helper.rb:

def it_behaves_like(*args) ; end

This will make RubyMine see a method with the correct signature, but it will still be overriden by rspec, so it will not affect your tests.

Even better, you can put it in a require from spec_helper.rb, e.g. rubymine_signatures.rb

require 'rubymine_signatures'

No matter where it is placed, however, it will still be polluting your codebase to 'fix' the IDE, which I don't recommend doing. Since it is only for tests though, it can be defended.