dior001
dior001

Reputation: 761

Rubymine Rspec Debugging: Uninitialized constant x (NameError)

I often use Rubymine to debug my rspec tests. I have recently upgraded to Rubymine 7.0.2 (Build RM-139.800) and I am receiving an error when trying to debug any rspec test. I have tried to roll back to Rubymine 6.3 and the problem persists. A change to my environment has triggered the problem but I don't know what the change is.

The error is as follows:

Fast Debugger (ruby-debug-ide 0.4.24, debase 0.1.1) listens on 127.0.0.1:49882
/Users/rubyminepain/code/websites/somerepo/spec/lib/bots_spec.rb:1:in `<top (required)>': uninitialized constant Bots (NameError)
from /Users/rubyminepain/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load'
from /Users/rubyminepain/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /Users/rubyminepain/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
from /Users/rubyminepain/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /Users/rubyminepain/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
from /Users/rubyminepain/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
from /Users/rubyminepain/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'

I'm using rspec-rails (2.14.2) rspec-core (2.14.8) with ruby-debug-ide (0.4.24) & debase (0.1.1).

If I run the spec from the terminal e.g. rspec spec/lib/bots_spec.rb it works fine. It's only when I try to "Debug run spec 'bots_spec'" in Rubymine that the error occurs.

I've tried using older versions of the gems listed above but am still having problems. Any suggestions appreciated.

Update:

Adding require_relative '../spec_helper' to the top of the spec fixes the problem. The .rspec configuration file already contains --require spec_helper. The spec helper is in the standard spec folder location. Confused as to why this require_relative is necessary. Other Rails projects I have using rspec don't need this. Require relative is discussed here https://stackoverflow.com/a/5045884/880381. Don't really want to add require_relative to all my specs so still looking to understand more about why it's required.

Upvotes: 1

Views: 1798

Answers (1)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42789

It's probably just a naming issue, check the first line in the file mentioned in the error log bots_spec.rb and replace the constant Bots with a singular name Bot
Model names should always be called in singular form

Upvotes: 1

Related Questions