Undefined Method 'Require_Relative' for Main:Object (Nomethoderror)

undefined method `require_relative' for main:Object (NoMethodError)

I fixed the problem by completely removing Rails, Ruby, and RVM altogether - then starting from scratch.

I don't remember all of the commands exactly, but it was something like:

sudo gem uninstall rails
sudo rvm remove 2.0
rvm implode
sudo chown -R drewwyatt: ~/.rvm/
rm -rf ~/.rvm
\curl -L https://get.rvm.io | bash -s stable --rails
rvm use 2.0
gem install rails

undefined method `require_relative' for main:Object when running build from sublime

It's probably because sublime runs 1.8.7 version of ruby. You could change it. Here is how.

NoMethodError but did 'require_relative'

In order to call the method within the class Run you have to instantiate it. Since is an instance method. The way your calling the class is giving you the error undefined because it can not find it with in the scope of your current file

run_instance = Run.new 
to_separate = IO.readlines(ARGV[0])
sperated = run_instance.separate(to_separate)

How to use require_relative with an rspec test?

Just add this to your spec_helper.rb in the RSpec.configure block:

RSpec.configure do |config|
config.before :all do
CONTINUE_SPEC= true
end

config.around :each do |example|
if CONTINUE_SPEC
CONTINUE_SPEC = false
example.run
CONTINUE_SPEC = true unless example.exception
else
example.skip
end
end

# ...
end

Did require become replaced by require_relative for files?

require works exactly the same as it did before: it searches the $LOAD_PATH. What has changed is the default $LOAD_PATH: the current directory . was removed from it, for various maintenance and security reasons.

In almost all cases, you don't want to load a file relative to the current working directory anyway (after all, the CWD is controlled by the user, so you don't even know what it is, how could you then reliably load a file from there?), you want to load it relative to the current file … which is exactly what require_relative does.

By the way: this change was relased 7 years ago, made before that, and announced even before that, I don't know where you are getting that code from, but I would be highly suspicious of code that hasn't been maintained for such an extended period of time (almost 10 years).

`to_specs': Could not find 'railties' (= 0) among 8 total gem(s) (Gem::LoadError)

The solution that worked for me is updating my OS X certs with brew (https://github.com/rubygems/rubygems/issues/1736) :

brew update
brew install openssl
brew tap raggi/ale
brew install openssl-osx-ca

Then updating my ruby version by rbenv install 2.4.0

rbenv local 2.4.0

gem install bundler
gem update --system

And it work :)

`require': cannot load such file -- spec_helper (LoadError)

You're running the specs from the spec folder. This messes up the load path. Run specs from the root of your project: ~/sheetal.

rspec spec/sheetal_spec.rb

Rspec adds the spec and lib folders to the load path automatically. If you're already in the spec folder, rspec is going to add spec/spec to the load path instead.

Assuming that you have your code in the lib folder, you would have to add both . and ../lib to the load path if you want to run your tests in the spec folder.



Related Topics



Leave a reply



Submit