uninitialized constant Rake::DSL in Ruby Gem - ruby

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

Related

ActiveResource::Collection is giving NameError

I am trying to run ActiveResource::Collection on console, but its giving name error. Kindly give me a solution to solve this.
NameError: uninitialized constant ActiveResource::Collection
from (irb):10
from /var/lib/gems/2.1.0/gems/railties-3.2.17/lib/rails/commands/console.rb:47:in `start'
from /var/lib/gems/2.1.0/gems/railties-3.2.17/lib/rails/commands/console.rb:8:in `start'
from /var/lib/gems/2.1.0/gems/railties-3.2.17/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
UPDATE
Others like ActiveResource::Base, ActiveResource::Format, ActiveResource::Connection are working.
It looks like you don't have ActiveResource added. Add it into your Gemfile and run bundle install.
# Gemfile
gem 'activeresource'
# Command line
bundle install
I solved this issue by updating activeresource gem version to activeresource-4.0.0. Earlier it was activeresource-3.2.17 .

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.

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.

Rake aborted: could not find rspec

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

Inability to find a required service_manager gem

I'm working on some cucumber tests from The Cucumber Book. I've got the code that tries to use a transaction processor and there is a file with the following code:
require 'service_manager'
ServiceManager.start
This is on Mac OS X 10.6.8 using Ruby 1.9.2. When this file executes, I get the following:
no such file to load -- service_manager (LoadError)
/opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
/opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
/opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/Users/gpollice/MyCucumber/ATMBookExample/features/support/services.rb:6:in `<top (required)>'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/cucumber-1.1.2/lib/cucumber/rb_support/rb_language.rb:143:in `load'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/cucumber-1.1.2/lib/cucumber/rb_support/rb_language.rb:143:in `load_code_file'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/cucumber-1.1.2/lib/cucumber/runtime/support_code.rb:171:in `load_file'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/cucumber-1.1.2/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
The service_manager gem is installed in /opt/local/lib/ruby1.9/gems/1.9.1/gems as are other gems that the application uses. Until I added the code for this iteration, there were no problems. I've looked for reasons why the gem is not found and just can't figure out why. Any help would be appreciated.
It appears to be a load path issue.
Is require "rubygems" invoked prior to this require statement?
Also, if you're using bundler, you have to add this gem to your Gemfile, as bundler attempts to sandbox your dependencies. If you're using bundler, try the following after adding the gem to the Gemfile:
bundle exec rake cucumber

Resources