Rake aborted: could not find rspec - ruby

I'm trying to work through the Ruby course from TestFirst.org. It requires you to navigate to the folder containing the exercise, run rake, and then correct any errors in the source code it uncovers. When I run rake in the folder for the first exercise it gives this error:
rake aborted!
Could not find rspec (~> 2) amongst [diff-lcs-1.2.5, rspec-3.0.0, rspec-core-3.0.0,
rspec- expectations-3.0.0, rspec-mocks-3.0.1, rspec-support-3.0.0]
/home/jayson/Desktop/learn_ruby/Rakefile:2:in `<top (required)>'
(See full trace by running task with --trace)
Does this means it will only work with an old version of rspec or something else? Running rake with --trace gives me:
rake aborted!
Could not find rspec (~> 2) amongst [diff-lcs-1.2.5, rspec-3.0.0,
rspec-core-3.0.0, rspec-expectations-3.0.0, rspec-mocks-3.0.1, rspec-support-3.0.0]
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs'
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
/usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
/home/jayson/Desktop/learn_ruby/Rakefile:2:in `<top (required)>'
/usr/lib/ruby/vendor_ruby/rake/rake_module.rb:25:in `load'
/usr/lib/ruby/vendor_ruby/rake/rake_module.rb:25:in `load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:589:in `raw_load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:89:in `block in load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:160:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:88:in `load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:72:in `block in run'
/usr/lib/ruby/vendor_ruby/rake/application.rb:160:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:70:in `run'
/usr/bin/rake:27:in `<main>'
How do I get the rake command to work properly? I'm using Terminal in Ubuntu 14.04, with Ruby 1.9.3, RubyGems 1,8.23, and Rspec 3.0.0. Thanks in advance.

I had the same problem, and sudo gem install -v '<3.0.0' rspec did work, but only after I uninstalled the newer version with gem uninstall rspec.
Without that uninstall first, only the later version remains active and the problem will continue.

hope this help.
gem install rspec -v 2.9.0
It happen because:
Could not find rspec (~> 2)
while rspec version installed on your machine is: rspec-3.0.0
Source: RubyGems

Related

How to resolve ruby gem conflict involving rake on mac?

I am attempting to run rake under Mac OSX and I am getting the below error.
$ rake --trace
rake aborted!
Gem::ConflictError: Unable to activate releasy-0.2.2, because rake-10.3.2 conflicts with rake (~> 0.9.2.2)
/Library/Ruby/Site/2.0.0/rubygems/specification.rb:2112:in `raise_if_conflicts'
/Library/Ruby/Site/2.0.0/rubygems/specification.rb:1280:in `activate'
/Library/Ruby/Site/2.0.0/rubygems.rb:198:in `rescue in try_activate'
/Library/Ruby/Site/2.0.0/rubygems.rb:195:in `try_activate'
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:39:in `require'
/Users/Development/RUBY/rakefile:5:in `<top (required)>'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load_rakefile'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:687:in `raw_load_rakefile'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:94:in `block in load_rakefile'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:93:in `load_rakefile'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:77:in `block in run'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/usr/bin/rake:23:in `load'
/usr/bin/rake:23:in `<main>'
gem list --local displays
rake (10.3.2, 0.9.6, 0.9.2.2)
How would I resolve a conflict between the rake gem I installed and the rake gem that is deployed with OSX? Should I just delete the newest update or is there a way to specify in my rake file to use the newest version and ignore the conflict?
If you are trying to run rake from within a project that uses a Gemfile, try this:
bundle exec rake --trace
This will load up the version of rake required for the project, instead of one that could possibly conflict (like your OSX default /usr/bin/rake binary).
If the bundle command isn't found, do this:
gem install bundler
Also, if this is a recent Rails app, you can also use the provided binstubs instead like this:
bin/rake --trace
If none of this works, try using RVM, Chruby, or RBEnv to manage your Ruby environments separately from the operating-system provided Ruby.

Ruby dependency issue on MacOSX

I'm trying to get started with the excellent deliver tool (https://github.com/KrauseFx/deliver) but I know nothing about ruby. So when I try to run deliver init and I get this message, I don't know what to do about it:
/Users/sarbogast/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/specification.rb:2052:in `raise_if_conflicts': can't activate json-1.6.8, already activated json-1.8.1 (Gem::LoadError)
from /Users/sarbogast/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/specification.rb:1262:in `activate'
from /Users/sarbogast/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:96:in `block in require'
from /Users/sarbogast/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:95:in `each'
from /Users/sarbogast/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:95:in `require'
from /Users/sarbogast/.rvm/gems/ruby-2.1.0#global/gems/deliver-0.3.6/lib/deliver.rb:1:in `<top (required)>'
from /Users/sarbogast/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:73:in `require'
from /Users/sarbogast/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:73:in `require'
from /Users/sarbogast/.rvm/gems/ruby-2.1.0#global/gems/deliver-0.3.6/bin/deliver:5:in `<top (required)>'
from /Users/sarbogast/.rvm/rubies/ruby-2.1.0/bin/deliver:23:in `load'
from /Users/sarbogast/.rvm/rubies/ruby-2.1.0/bin/deliver:23:in `<main>'
from /Users/sarbogast/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/sarbogast/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `<main>'
What should I do? By the way I'm on MacOSX Yosemite.
If you are using bundler and you have a Gemfile you can try to run it with bundle using:
bundle exec deliver init
In that way Gemfile will pick for you the right version of the json gem.
If you aren't using bundler you should uninstall the newer version of json using:
gem uninstall json
and choosing the 1.8.1 to uninstall. Then you can try to run again deliver init
As a matter of fact, all I had to do was to install json with "sudo gem install json" and it solved my problem.

NameError Rack::Attack installing GitLab 7.2

I've got a NameError installing GitLab 7.2. More precisely when initializing the database:
$ bundle exec rake gitlab:setup RAILS_ENV=production --trace
rake aborted!
NameError: uninitialized constant Rack::Attack
/home/[user]/gitlab/config/application.rb:67:in `<class:Application>'
/home/[user]/gitlab/config/application.rb:9:in `<module:Gitlab>'
/home/[user]/gitlab/config/application.rb:8:in `<top (required)>'
/home/[user]/gitlab/Rakefile:5:in `require'
/home/[user]/gitlab/Rakefile:5:in `<top (required)>'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load_rakefile'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:687:in `raw_load_rakefile'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:94:in `block in load_rakefile'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:93:in `load_rakefile'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:77:in `block in run'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/bin/rake:23:in `load'
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/bin/rake:23:in `<main>'
Yes, I found this answer discussing the error with an older version of GitLab, where the following line in config/application.rb had to be uncommented
config.middleware.use Rack::Attack
In 7.2. this line is uncommented from the start. It's there. It's apparently where rake chokes.
I renamed config/initializers/rack_attack.rb.example to config/initializers/rack_attack.rb as well.
Installing the bundle gems worked like a charm.
bundle install --deployment --without development test postgres aws
rack-attack is in the bundle's gems folder:
/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rack-attack-2.3.0/lib/rack/attack.rb
Does anyone know what could be causing this problem? Thanks a lot!
Very ugly workaround™
I added the following line to config/application.rb and it's working:
require '/home/[user]/gitlab/vendor/bundle/ruby/1.9.1/gems/rack-attack-2.3.0/lib/rack/attack.rb'
Why is this working? What's wrong? Thanks!
I can't add comment, so I need to post it as an answer: You need to update your ruby & gems: take a look at https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md#2-ruby.
GitLab requires Ruby (MRI) 2.0 or 2.1 You will have to use the
standard MRI implementation of Ruby. We love JRuby and Rubinius) but
GitLab needs several Gems that have native extensions.

Unable to run serverspec due to gem being unable to load

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.

uninitialized constant Rake::DSL in Ruby Gem

I have been working on updating my gem (whm_xml at https://github.com/ivanoats/whm_xml_api_ruby ) to make it work with ruby 1.9.2, latest rubygems, latest bundler, latest rdoc, latest rake. It works fine in 1.8.7 but has the "uninitialized constant Rake::DSL" error only in 1.9.2 . I thought that rake 0.9.2 fixed that but maybe not? I have read a lot on StackOverflow but am still stuck. Any ideas on where to look?
ivan:~/Development/ruby/whm_xml_api_ruby [git:master+] → bundle exec rake -T
(in /Users/ivan/Development/ruby/whm_xml_api_ruby)
rake aborted!
uninitialized constant Rake::DSL
/Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/tasklib.rb:6:in `<module:Rake>'
/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/tasklib.rb:3:in `<top (required)>'
/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rdoc-3.6.1/lib/rdoc/task.rb:37:in `require'
/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rdoc-3.6.1/lib/rdoc/task.rb:37:in `<top (required)>'
/Users/ivan/Development/ruby/whm_xml_api_ruby/Rakefile:3:in `require'
/Users/ivan/Development/ruby/whm_xml_api_ruby/Rakefile:3:in `<top (required)>'
/Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:2373:in `load'
/Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1991:in `run'
/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/ivan/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `load'
/Users/ivan/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `<main>'
This SO Question might help you out. The suggestion there is to add require 'rake/dsl_definition' above require 'rake' in your Rakefile.
I think this is something that happened with the rake 0.9.0 release. Try putting this in your Gemfile: gem 'rake', '0.8.7'
Update
You could try adding
include Rake::DSL if defined?(Rake::DSL)
to your app; it worked for my Rails app at one point.
I fooled around with the include Rake::DSL, etc and just got other errors.
adding
gem 'rake', '0.8.7'
to the Gemfile seems to work for me
I had the same problem with 0.9.1, installed the 0.9.2 and it worked but the db:migrate command sent a message WARNING: Global access to Rake DSL methods is deprecated. Please....
it got solved adding to the rake file
module ::yourappname
class Application
include Rake::DSL
end
end
and
require 'rake/dsl_definition'
before the .. LoadTask entry

Resources