I'm working on a program that assists in running Ruby code on the command line (at https://github.com/keithrbennett/rexe, gem install rexe).
When I gem install it, and cd to the project root, and try to require a file not in the Gemfile, it fails:
➜ rexe git:(master) ✗ rexe -r awesome_print -oa '"hello"'
Traceback (most recent call last):
12: from /Users/kbennett/.rvm/gems/ruby-2.6.0/bin/ruby_executable_hooks:24:in `<main>'
11: from /Users/kbennett/.rvm/gems/ruby-2.6.0/bin/ruby_executable_hooks:24:in `eval'
10: from /Users/kbennett/.rvm/gems/ruby-2.6.0/bin/rexe:23:in `<main>'
9: from /Users/kbennett/.rvm/gems/ruby-2.6.0/bin/rexe:23:in `load'
8: from /Users/kbennett/work/rexe/exe/rexe:403:in `<top (required)>'
7: from /Users/kbennett/.rvm/gems/ruby-2.6.0/gems/bundler-2.0.1/lib/bundler.rb:313:in `with_clean_env'
6: from /Users/kbennett/.rvm/gems/ruby-2.6.0/gems/bundler-2.0.1/lib/bundler.rb:562:in `with_env'
5: from /Users/kbennett/.rvm/gems/ruby-2.6.0/gems/bundler-2.0.1/lib/bundler.rb:313:in `block in with_clean_env'
4: from /Users/kbennett/work/rexe/exe/rexe:403:in `block in <top (required)>'
3: from /Users/kbennett/work/rexe/exe/rexe:385:in `call'
2: from /Users/kbennett/work/rexe/exe/rexe:385:in `each'
1: from /Users/kbennett/work/rexe/exe/rexe:385:in `block in call'
/Users/kbennett/work/rexe/exe/rexe:385:in `require': cannot load such file -- awesome_print (LoadError)
However, when I cd ~, it works fine:
➜ ~ rexe -r awesome_print -oa '"hello"'
"hello"%
I wrapped my code in Bundler.with_clean_env, which I thought should take care of this.
I can use the Ruby interpreter directly and it works:
➜ rexe git:(master) ✗ ruby -r awesome_print -e "ap 'hello'"
"hello"
So I guess Bundler is making an assumption that non-Gemfile-listed gems should not be permitted to be loaded, and that is almost always reasonable, but in my case, where the program should be able to load any gem whatsoever, it is an impediment.
I understand that Bundler is finding the Gemfile[.lock] and doing what it thinks is right, but is there any way around this?
Not a complete answer, just a direction: try adding the path to the requested gem to $LOAD_PATH explicitly before requiring the gem. For example:
pry(main)> require "awesome_print"
LoadError: cannot load such file -- awesome_print
But then
pry(main)> $LOAD_PATH << "<home>/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/awesome_print-1.8.0/lib/";
pry(main)> require "awesome_print"
=> true
Voila! The question is how to get the proper path for the gem, maybe gem which could help...
Related
After install ruby 2.5.1 using RVM (lasted), when i run rails s, i got error bellow:
Traceback (most recent call last):
5: from bin/rails:3:in `<main>'
4: from bin/rails:3:in `require_relative'
3: from /Users/thiensubs/Documents/super-control/config/boot.rb:3:in `<top (required)>'
2: from /Users/thiensubs/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
1: from /Users/thiensubs/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
/Users/thiensubs/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require': cannot load such file -- bundler/setup (LoadError)
Any body can help me?
You need to check your gem list and see if bundler is installed, then bundle install (--without production)
Check that you don't have a .ruby-version file with just "2.5" in it. Switching mine to "2.5.1" fixed this.
Worked for me
gem update --system
I'm trying to play around with serverspec, however it seems I have some weird gem error that I cannot pinpoint.
$ rake spec
/usr/bin/ruby -I/usr/lib/ruby/gems/1.8/gems/rspec-support-3.0.2/lib:/usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib -S /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/exe/rspec spec/localhost/httpd_spec.rb
/home/mikolajewskim/puppet-master/spec/spec_helper.rb:1:in `require': no such file to load -- serverspec (LoadError)
from /home/mikolajewskim/puppet-master/spec/spec_helper.rb:1
from /home/mikolajewskim/puppet-master/spec/localhost/httpd_spec.rb:1:in `require'
from /home/mikolajewskim/puppet-master/spec/localhost/httpd_spec.rb:1
from /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `load'
from /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `load_spec_files'
from /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `each'
from /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `load_spec_files'
from /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:97:in `setup'
from /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:85:in `run'
from /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:70:in `run'
from /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:in `invoke'
from /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/exe/rspec:4
/usr/bin/ruby -I/usr/lib/ruby/gems/1.8/gems/rspec-support-3.0.2/lib:/usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/lib -S /usr/lib/ruby/gems/1.8/gems/rspec-core-3.0.2/exe/rspec spec/localhost/httpd_spec.rb failed
Still, when I look at the list of gems, serverspec is there (1.9.0). I've also checked it's existance in gems directory. I'm running a system version of ruby 1.8.7 and I do not have multiple ruby installations.
I'm not really sure where to go from here. Thanks in advance for any help.
What helped was:
1) Upgrading ruby package on the system (still 1.8.7).
2) Upgrading rubygems.
3) Removing all gems.
4) Installing serverspec and rake again.
I'm a noob, working through a tutorial which many here may know (testfirst.org). I'm getting the error below in terminal.app, when I try running 'rake':
fname-lnames-macbook-pro:00_hello macbookowner$ rake
(in /Users/macbookowner/Desktop/learn_ruby-master)
/Users/macbookowner/.rvm/gems/ruby-1.9.3-p448#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:216: warning: Insecure world writable dir /Users in PATH, mode 040777
/Users/macbookowner/Desktop/learn_ruby-master/00_hello/hello_spec.rb:116:in `require': cannot load such file -- hello (LoadError)
from /Users/macbookowner/Desktop/learn_ruby-master/00_hello/hello_spec.rb:116:in `<top (required)>'
from /Users/macbookowner/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load'
from /Users/macbookowner/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /Users/macbookowner/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `each'
from /Users/macbookowner/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /Users/macbookowner/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:22:in `run'
from /Users/macbookowner/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
from /Users/macbookowner/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'
/Users/macbookowner/.rvm/rubies/ruby-1.9.3-p448/bin/ruby -S rspec /Users/macbookowner/Desktop/learn_ruby-master/00_hello/hello_spec.rb -I/Users/macbookowner/Desktop/learn_ruby-master/00_hello -I/Users/macbookowner/Desktop/learn_ruby-master/00_hello/solution -f documentation -r ./rspec_config failed
fname-lnames-macbook-pro:00_hello macbookowner$
My questions: What is going wrong? And how can I fix it?
Info:
I got the same/similar error running rvm 1.9.3 and rvm 2.0.0
I installed 'gem install rspec' on both rvm versions
My best guess is that the hello.rb file [which I created in Sublime Text 2, and saved on macbookowner ->Desktop] is not being found by rake. When I run ls on Desktop, it does show hello.rb.
Thanks in advance!
If you look at the error,
/Users/macbookowner/Desktop/learn_ruby-master/00_hello/hello_spec.rb:116:in 'require': cannot load such file -- hello (LoadError)
it shows that in hello_spec.rb, on line 116, there is a require 'hello' statement which is failing. Likely the file does not exist at the path specified.
I read a lot of the issues here before, unfortunately non of the described solutions worked for me. I'm on OSX and using ruby-1.9.3-p448 via rvm. Everything freshly set up.
Then I did sudo gem install compass for getting compass and sass.
No error messages.
stnwbr$ ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.4.0]
stnwbr$ compass -v
Compass 0.12.2 (Alnilam)
stnwbr$ sass -v
Sass 3.2.10 (Media Mark)
but as soon as I do something like compass create or compass watch I get:
stnwbr$ compass create
LoadError on line ["51"] of /Users/stnwbr/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb: cannot load such file -- breakpoint
Run with --trace to see the full backtrace
Including --trace the result is the following:
stnwbr$ compass create --trace
LoadError on line ["51"] of /Users/stnwbr/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb: cannot load such file -- breakpoint
/Users/stnwbr/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:51:in `require'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/data.rb:161:in `require'
/Users/stnwbr/Dropbox/Projects/2013/11 OUA outdooradventures/OUA-sync/config.rb:1:in `get_binding'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/serialization.rb:24:in `eval'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/serialization.rb:24:in `parse_string'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/serialization.rb:15:in `block in _parse'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/serialization.rb:14:in `open'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/serialization.rb:14:in `_parse'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/file_data.rb:7:in `block in new_from_file'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/inheritance.rb:204:in `with_defaults'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/file_data.rb:6:in `new_from_file'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/helpers.rb:42:in `configuration_for'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/configuration/helpers.rb:97:in `add_project_configuration'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/commands/project_base.rb:31:in `add_project_configuration'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/commands/installer_command.rb:9:in `configure!'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/commands/project_base.rb:15:in `initialize'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/commands/stamp_pattern.rb:69:in `initialize'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/exec/sub_command_ui.rb:42:in `new'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/exec/sub_command_ui.rb:42:in `perform!'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/exec/sub_command_ui.rb:15:in `run!'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/bin/compass:30:in `block in <top (required)>'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/bin/compass:44:in `call'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/bin/compass:44:in `<top (required)>'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/bin/compass:23:in `load'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/bin/compass:23:in `<main>'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `eval'
/Users/stnwbr/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `<main>'
Unfortunately that's where my understanding stops. All ideas appreciated! Thank you.
Uninstall sass and reinstall it with the following:
gem uninstall sass
gem install sass
For some reason
gem install compass
brings along some bleeding edge version of sass which is causing this error.
Then I did sudo gem install compass
NEVER
ever
use SUDO
with rvm
Follow the instructions here link
I can't figure out why my RSPEC isn't working. I reinstalled RSPEC with sudo gem install rspec and then tried again to install with a specific version number (sudo gem install rspec -v 2.11.0)
I continue to get the following error message and I cannot figure out what it means. I believe that I may or may not have version 1 also installed, not sure.
Castillo$ rspec document_spec.rb
/Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require': no such file to load -- document (LoadError) from
/Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require' from /Users/Castillo/Desktop/document_spec.rb:1:in <top
(required)>' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:inload' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in block in load_spec_files' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:inmap' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in load_spec_files' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:inrun' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in
run' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in
block in autorun'
Add full path to your document.rb file into spec file
or use
require_relative
or
require File.expand_path('../document.rb', __FILE__)