RVM, Merb, Rake and RSpec - ruby

I am currently running ruby-1.9.1 installed via RVM. I have been looking at using Merb, but when I try and run it I get this error:
sam#shiny-dev:~/Projects/mojo$ rake db:migrate
(in /home/sam/Projects/mojo)
Merb root at: /home/sam/Projects/mojo
/home/sam/.rvm/gems/ruby-1.9.1-p378#merb/gems/dm-validations-1.0.0/lib/dm-validations.rb:33: warning: already initialized constant OrderedHash
Loading init file from ./config/init.rb
Loading ./config/environments/development.rb
rake aborted!
no such file to load -- spec/rake/spectask
/home/sam/Projects/mojo/Rakefile:24:in `require'
(See full trace by running task with --trace)
I have installed rspec, but even in IRB I cannot require 'spec/rake/spectask' unless I also install rspec-rails (which I have now done).
Any ideas where I could even start?
Cheers,
Sam

I had the same problem with this on Rails 2.3.5. I ended up having to uninstall RSpec 2.0 and install RSpec 1.3.0 instead.

After 2 weeks I finally figured it out!
Edit your Gemfile and add the line:
gem "rspec", :require => "spec"
and you're away!

Related

rake neo4j:install[community-latest] - The `neo4j-rake_tasks` gem is no longer a dependency of the `neo4j-core` gem

I am following this instruction, "Getting Started with Neo4j and Ruby", https://neo4j.com/developer/ruby-course/.
Here is how you would setup your asset portal Rails app:
rails new asset_portal -m http://neo4jrb.io/neo4j/neo4j.rb -O
cd asset_portal
rake neo4j:install[community-latest]
rake neo4j:start
But after I run
rake neo4j:install[community-latest]
I got this note
The `neo4j-rake_tasks` gem is no longer a dependency of the `neo4j-core` gem.
If you would like to use the rake tasks, you will need to explicitly include the `neo4j-rake_tasks` gem in your project.
Please note that the `neo4j-rake_tasks` gem is only for development and test environments (NOT for production).
Be sure to require the `neo4j-rake_tasks` gem AFTER the `neo4j-core` and `neo4j` gems.
For more details see the Neo4j.rb documentation
What can I do now to make this statement, rake neo4j:install[community-latest], work?
Thanks!
only add the flowing snippet
gem 'neo4j-rake_tasks'
bundle install
Hopefully would solve your problem.
I need to add the following lines to GemFile
gem 'neo4j-core'
gem 'neo4j-rake_tasks'
And then run the commands
bundle install
rake neo4j:install[community-latest]
rake neo4j:start

Rspec rake task gem no longer importing

Pulling my hair out on this. I'm running some rspec specs through rake using rspec's rake task. Its been working fine until I started getting this error message:
rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
Here is the results of gem list | grep rspec
rspec (3.1.0)
rspec-core (3.1.7)
rspec-expectations (3.1.2)
rspec-mocks (3.1.3)
rspec-support (3.1.2)
and here is the line I'm using to include the rake task in my Rakefile
require 'rspec/core/rake_task'
I uninstalled all rspec gems and re-installed. Same error. As I mentioned I've been running these tests for a few months now without issue. There have been no changes to the environment and it runs in a VM so I can ensure it wasn't a coworker. What am I missing?
EDIT
I double checked my Gemfile.lock file all the gem versions are matching with the one in the upstream repo.
First off, I recommend running your specs through the rspec command. It's far more flexible than running specs through rake and has less overhead. Running the specs through rake is still useful as part of a build pipeline (the kind of thing rake is good at).
You haven't provided sufficient information to definitely answer your question, but I can provide some suggestions:
Are you running rake via bundle exec rake? Bundler is designed to manage the load path at runtime after it installs your gems, and should ensure that the installed rspec-core/lib is on your load path.
You can add puts $LOAD_PATH.join("\n") to the top of your Rakefile to see what the load path is. Is rspec-core in the list anywhere? (I suspect it's not). If it's not, then require 'rspec/core/rake_task' is not going to work unless rspec-core is installed as a system gem. Use gem which rspec-core to see if it's installed that way.

Using rspec with a local gem

I am using a local gem (on my machine) with another application that is a command line app.
I have something like this in the gemfile to refer to the local gem:
gem 'mygem', :path => '/Users/devmachine/Projects/mygem'
When I run bundle console I am able to use the gem and all is well. However, whenever I run my test suite (rspec) I get the following message:
ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mygem (LoadError)
I'm confused. Any ideas?
You need to run:
bundle exec rspec
If you are not using the bundle evironment rspec won't know what you put in your Gemfile and just use the Gems it finds installed.

Ruby rspec test command: could not locate Gemfile

I just installed Ruby 1.9.3 on Windows 7 and I also installed rubygems. I'm trying to work with rspec so I ran:
gem install rspec
It seemed to work well and everything installed. SO I went on to try the example on this page. But anytime I run the rspec command I get this error message:
"Could not locate Gemfile".
According to the example, I should get: "./bowling_spec.rb:4:
uninitialized constant Bowling"
I've googled it and it was suggested I try bundle exec rspec but it still yielded the same results.
I have also tried the suggestion on this page but it yields the same results. What am I doing wrong? Thanks
Create the Gemfile with this content. Gemfile can have no extension or .gem extension
source 'https://rubygems.org'
gem 'rspec'
so you have
app/
Gemfile or Gemfile.gem
spec/
bowling_spec.rb
Also you might need to execute this commands after
gem install bundler
and then, in the app directory
bundle install
gem install rspec in the same directory as your app and
change require statement to require './bowling.rb'

I see gem in "gem list" but have "no such file to load"

I am on Ubuntu10
sudo apt-get install ruby1.9.1-full
then download sources of rubygem 1.3.7 and install it
sudo ruby setup.rb
then, for example, install sinatra
sudo gem install sinatra
Finally open irb and type
require "rubygems"
require "sinatra"
and get error
LoadError: no such file to load -- sinatra
from (irb):2:in `require'
from (irb):2
from /usr/bin/irb:12:in `<main>'
I had exactly this problem. The problem is that gem and ruby disagree about where the gems live. Compare these:
ruby -e "puts Gem.path"
gem env
gem which sinatra
If you're like my setup, you'll notice that there's an entry in gem env's paths that isn't in Gem.path, and that's exactly where sinatra will claim to be. In my case, I had to add
export GEM_HOME=/usr/lib/ruby/gems/1.9.1
to my .profile. Then everyone was happy.
Execute
sudo gem install sinatra --verbose
and note the path where the gem is getting installed.
Then try this in irb
puts $LOAD_PATH
and make sure that gem is installed in one of the directories in $LOAD_PATH
And ideally just start using http://rvm.beginrescueend.com/
I usually hit this error when I forget:
require 'rubygems'
It'd be helpful if you provided the actual code sample, though, what gem you want to require, and what Ruby version you're using if this doesn't solve the problem.
This was before here on SO quite a few times. Problem is that you probably have two versions of ruby. The one is installing the gem and the other one is trying to use it. Do this in terminal:
$ which -a ruby
Or this:
$ which -a gem
to see if you have more than one version of ruby/gem installed. If so - remove one version (via $ rm or package manager of your system).
I use ruby gems 1.8.7 for a project. I was getting the same error. Use the line require 'rubygems'. It must always be the first require statement, otherwise you can get an error. In my code, I had
require 'watir'
require 'rubygems'
# more code
I got the error - in `require': no such file to load -- watir (LoadError).
When I put rubygems first, the error went away and everything worked. I don't know
why this happens.
Btw, I tried user24359 answer and it did not help me.
C:\code>ruby -e "puts Gem.path"
-e:1: uninitialized constant Gem (NameError)

Resources