require not working with rspec - ruby

Here is my file, test.rb:
require 'rubygems'
require 'pry'
There is no problem running it with ruby:
$ ruby test.rb
However, there is an error with rspec:
$ rspec test.rb
/path/to/test.rb:2:in `require': no such file to load -- pry (LoadError)
Versions:
$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin12.5.0]
$ rspec -v
3.0.4
$ gem -v
2.0.14
$ gem list pry
*** LOCAL GEMS ***
pry (0.9.12.6)

Found the issue.
rspec was installed using bundle install.
pry was installed using gem install.
I went back and installed pry using bundle install and now rspec runs without error.
I cannot however explain why exactly the failure occurs. Anyone?

Bundler is probably storing/looking for gems in a different location than gem install. Unless you have a extremely good reason to, it's better to always use bundler and the Gemfile.
Oh, I also strongly recommend you to install a newer version of Ruby. That should be pretty simple using RVM.

Related

Ruby Gem adaptor MySQL error

I am getting the below error while using the MySQL gem; Tried mysql2 and it also gives the same error.
-bash-4.1$ gem list
*** LOCAL GEMS ***
mysql (2.9.1)
-bash-4.1$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
-bash-4.1$ irb
irb(main):001:0> require 'mysql'
NameError: uninitialized constant Mysql
from ./mysql.rb:10
from (irb):1:in `require'
from (irb):1
from :0
irb(main):002:0>
Please let me know if there is a solution for this; thanks!
Are you using bundler/rvm? If so, start irb with:
bundle exec irb
make sure you are in the right gemset and ruby version from where you are accessing the gem.
Before typing in the irb, check what gemset you are in:
rvm gemset list
then check the gems installed in that particular gemset
rvm <my-gemset-name> do gem list
If they do not match, that is your problem and you can fix it by changing to the right gemset:
rvm use <my-gemset>
Similarly, check for ruby version, i.e if the ruby version for your installed gem and from where you are running your irb match

ERROR: While executing gem ... (Gem::FilePermissionError)

I have install rbev
rbenv version
2.0.0-p247 (set by /Users/amritdeepdhungana/.rbenv/version)
, ruby
ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]\
and rails
rails -v
Rails 4.0.1
I have create new project and bundle it. But I get this problem
Installing rake (10.1.1)
Errno::EACCES: Permission denied - /Library/Ruby/Gems/2.0.0/build_info/rake-10.1.1.info
An error occurred while installing rake (10.1.1), and Bundler cannot continue.
Make sure that `gem install rake -v '10.1.1'` succeeds before bundling.
After that, I have install rake gem but again I got error
gem install rake -v '10.1.1'
ERROR: Could not find a valid gem 'rake' (= 10.1.1), here is why:
Unable to download data from https://rubygems.org/ - too many connection resets (https://s3.amazonaws.com/production.s3.rubygems.org/specs.4.8.gz)
ERROR: Possible alternatives: rake
How can I set the permission while install any gem package ?
Like #bjhaid said, you're trying to install these gems into your system Ruby.
/Library/Ruby/Gems/2.0.0/build_info/rake-10.1.1.info
Ruby 2.0.0p247 is bundled w/Mavericks. Specifically:
$ /usr/bin/ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]
My self-built (rvm) version is has a slightly different version string:
$ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]
To find out which ruby is actually being used, try which ruby. Make sure you've properly installed rbenv, and installed a new local Ruby.
It almost looks like you haven't set your PATH up correctly, but your answer to Nick Veys' question doesn't look like it. I would surmise that you haven't installed any ruby under rbenv yet. What does rbenv versions look like?

"bundle install" for Ruby 1.8.7 on Ubuntu Raring Ringtail 13.04

I'm not a rubyist and there might be something obvious I'm missing.
I've wrote an application in Ruby 1.8.7, I'm trying to package it in Vagrant (running Raring 13.04), but I've to run "bundle install" to install the requirements and even though gem1.8 does exist, running bundle install still install the gems for Ruby 1.9.3. And then my program fails at runtime...
Any idea about how to solve this?
UPDATE 1
The related Gemfile (thanks to the first answerers):
ruby '1.8.7'
# ...
gem 'trollop'
but for ruby1.8 myfile.rb an error is raised
no such file to load -- trollop (LoadError)
After investigation, the problem looks in bundle install:
Your Ruby version is 1.9.3, but your Gemfile specified 1.8.7
I don't get how to solve the problem.
UPDATE 2
After following the advices from #klaffenboeck things have changed. I'm using RVM and have Ruby 1.8.7 when entering in the project folder. Bundler seems to install things correctly, however the require seems to fail... Path problem?
See here for detail about Vagrant / RVM setup: https://rvm.io/integration/vagrant
UPDATE 3
Problem solved, I was missing a:
require 'rubygems'
before all gems (it worked locally but not in Vagrant).
Bundler will install gems (by default) for whichever Ruby is in your PATH.
Try /usr/bin/env ruby -v or which ruby to figure out which one that is; my guess is you're running bundler with Ruby 1.8.
Adding
ruby '1.8.7'
on top of your Gemfile will help diagnose.
Not aware of this problem in general, but try to put the ruby-version at the top of your gemfile:
#Gemfile
ruby '1.8.7'
# followed by your gems
Edit:
this is most likely because your Gemfile.lock states ruby 1.9.3 - run bundle update
Try running gem uninstall bundler, then gem1.8 install bundler.
Your bundle command seems to be running under Ruby 1.9.3. You can verify which ruby executable bundler is using with head -n 1 $(which bundle). You want it to be ruby1.8.

rvm, irb and require - not working for installed gems under irb

I have just installed rvm today and it looks really handy/powerful.
I think I am getting the hang of it, but...
When using an rvm installed ruby, and running irb, when I require an installed gem, something, like 'rvm', I get:
> kimptoc$ rvm use 1.8.7
Using /Users/kimptoc/.rvm/gems/ruby-1.8.7-p302
> kimptoc$ gem list
*** LOCAL GEMS ***
abstract (1.0.0)
...
rvm (1.0.11)
...
> kimptoc$ irb
ruby-1.8.7-p302 > require 'rvm'
LoadError: no such file to load -- rvm
from (irb):1:in `require'
from (irb):1
But when using the "system" ruby, it works fine.
Historically I have been using sudo gem install ... and so the "system" gems are generally installed that way. Could that be my problem? Do I need to uninstall these to fix things?
I am running OSX 10.6.4. "system" is the default OSX ruby, 1.8.7 (p174)
Try require 'rubygems' first.
> rvm use 1.8.7
> rvm info
(Find the homes -> gem directory)
> ls -al ~/.rvm/gems/ruby-1.8.7 (Substitute your gem directory as needed)
Is your gem in this directory?
Generally speaking, using sudo gem install with rvm is a bad idea.
As of Ruby 1.9.3 you no longer need, can, require rubygems and you only need to require rvm.
If you want to use it in your .irbrc file for using wirble or awsome print you can use a simple trick to avoid a login error saying it can't include or 'rubygems' or 'rvm'
if RUBY_VERSION > "1.8.7"
require 'rvm'
else
require 'rubygems'
end
require 'wirble'
Wirble.init
Wirble.colorize
Including both rubygems and rvm does not seem logical because RVM replaces rubygems in some sort to handle the gems and gem repositories.
Note: For Ruby 1.8 you must require 'rubygems' before requiring any gems.
source : https://guides.rubygems.org/rubygems-basics/

ruby-debug19: Can't get working with Ruby 1.9.1p376

I'm trying to use ruby-debug19 with Ruby 1.9.1p376 but am getting the following error:
test.rb:2:in `require': no such file to load -- ruby-debug19 (LoadError) from test.rb:2:in `<main>'
Here's test.rb:
require 'rubygems'
require 'ruby-debug19'
Here's the output of "gem list":
*** LOCAL GEMS ***
ruby-debug19 (0.11.6)
(etc.)
So running "ruby test.rb" generates the above error.
Am I doing this wrong? I thought this was the correct way to run ruby-debug19 (by including the gem and adding "debugger" statements) and haven't been able to find any articles/posts with the same problem.
I am using RVM but the above output is all under the same version of Ruby ("ruby -v" shows 1.9.1p376 as expected, and the gem list output is specific to that version and not the OS X system-installed version 1.8.7).
Try just
require 'ruby-debug'
(Despite the gem's name)
Also you don't need require 'rubygems' anymore when using Ruby 1.9.
For ruby 1.9.3 and Rails 3.2 with pow:
In your Gemfile:
group :development do
gem 'debugger'
end
And at the bottom of config/environments/development.rb:
require 'debugger'
Debugger.start_remote
Debugger.settings[:autoeval] = true
Then connect to the debugger in your terminal using:
rdebug -c
For bundler (rails 3):
gem 'ruby-debug19', :require => 'ruby-debug'

Resources