Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RubyMine doesn't recognize `it_behaves_like` method

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

like image 494
ironsand Avatar asked Jun 18 '15 08:06

ironsand


1 Answers

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.

like image 53
Houen Avatar answered Sep 19 '22 03:09

Houen