How to solve " uninitialized constant Clockwork (NameError)" - ruby

I successfully installed gem clockwork
C:\web>gem install clockwork
Successfully installed clockwork-0.2.3
1 gem installed
Installing ri documentation for clockwork-0.2.3...
Installing RDoc documentation for clockwork-0.2.3...
but when running simple script
require 'rubygems'
require 'clockwork'
include Clockwork
every(1.minute, 'custom.event.handler' ) do
puts "This event has its own handler - #{Time.new.strftime("%Y%m%d%H%M%S")}"
end
I get this error
C:\web>ruby clockwork.rb
./clockwork.rb:3: uninitialized constant Clockwork (NameError)
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
from clockwork.rb:2
Any suggestion how to make clockwork work on
Windows XP
ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
gem 1.3.7
C:\web>gem list --local
*** LOCAL GEMS ***
aaronh-chronic (0.3.9)
activesupport (3.0.9)
backports (1.18.2)
clockwork (0.2.3)
daemons (1.1.0)
delayed_job (2.0.3)
eventmachine (0.12.10 x86-mswin32-60)
fastercsv (1.5.4)
haml (3.0.21)
i18n (0.6.0)
json (1.5.1)
mechanize (1.0.0)
monkey-lib (0.5.4)
nokogiri (1.5.0 x86-mingw32, 1.4.3.1 x86-mingw32)
rack (1.2.1)
rdiscount (1.6.8)
ruby-growl (3.0)
sinatra (1.2.6, 1.0)
sinatra-advanced-routes (0.5.1)
sinatra-reloader (0.5.0)
sinatra-sugar (0.5.1, 0.5.0)
thin (1.2.7 x86-mswin32)
tilt (1.3)

Let me give you a hint. The name of your own program is clockwork.rb, and in it you do:
require 'clockwork'
See the problem?

you need to include the following in your clock.rb
require './config/boot'
require './coonfig/environment'

Related

Cannot load Nokogiri

I'm writing Ruby scripts on Linux Mint 14 under RVM. In both Ruby 2.0 and 1.9.3, when I try to run what I'm working on, I get the error:
/home/tom/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- Nokogiri (LoadError)
from /home/tom/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from make_index.rb:1:in `<main>'
Nokogiri is installed; gem list gives:
*** LOCAL GEMS ***
bigdecimal (1.1.0)
bundler (1.3.5)
bundler-unload (1.0.1)
io-console (0.3)
json (1.5.5)
mini_portile (0.5.1)
minitest (2.5.1)
nokogiri (1.6.0)
rake (10.1.0, 0.9.2.2)
rdoc (3.9.5)
rubygems-bundler (1.2.1)
rvm (1.11.3.8)
The file in question starts with require 'Nokogiri'. Running the file with sudo doesn't make a difference, nor does using the terminal vs. running it in Geany.
Not Nokogiri rather, you should write as below
require 'nokogiri'
See SYNOPSIS:

JRuby "no such file to load"

Using jruby-1.6.7 via rvm and gem version 1.8.24 I created a new project containing a Gemfile:
source 'http://rubygems.org'
gem 'google-api-client'
and a main.rb:
require 'google/api_client'
After
gem install bundler
bundle install
gem list
I get
addressable (2.2.8)
autoparse (0.3.1)
bouncy-castle-java (1.5.0146.1)
bundler (1.1.4)
extlib (0.9.15)
faraday (0.8.1, 0.7.6)
ffi (1.0.11 java)
google-api-client (0.4.3)
jruby-launcher (1.0.14 java)
jruby-openssl (0.7.7)
json (1.7.3 java)
jwt (0.1.4)
launchy (2.1.0 java)
multi_json (1.3.6)
multipart-post (1.1.5)
rack (1.4.1)
rake (0.9.2.2)
rubygems-bundler (1.0.2)
rubygems-update (1.8.24, 1.7.2)
rvm (1.11.3.3)
signet (0.3.4)
spoon (0.0.1)
But when I run ruby main.rb, it results in an error:
LoadError: no such file to load -- google/api_client
require at org/jruby/RubyKernel.java:1033
(root) at main.rb:1
On MRI everything seems to be working fine. The problem does not seem bound to any specific gem.
Can someone help me with this?
Unless you have JRUBY_OPTS=--1.9 in your environment, or you pass the --1.9 flag on the command line, JRuby will default to 1.8 mode, which means that you explicitly have to require 'rubygems' in main.rb before you load your gems.

Unable to run ruby-debug on ruby1.9.3p0 under XP

How do I get ruby-debug to run under XP so that I can step through my Watir test scripts.
I am unable to "require" ruby-debug on Windows XP. All of the solutions I have seen refer to a Unix-based system running Rails. Here is my system profile:
H:\>ruby -v
ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
Here are the gems I have installed to support my testing in Watir
H:\>gem list
*** LOCAL GEMS ***
archive-tar-minitar (0.5.2)
awesome_print (1.0.2)
bigdecimal (1.1.0)
childprocess (0.2.4)
columnize (0.3.6)
ffi (1.0.11)
io-console (0.3)
json (1.5.4)
linecache19 (0.5.13)
minitest (2.5.1)
mkrf (0.2.3)
multi_json (1.0.4)
net-ssh (2.2.1)
rake (0.9.2.2)
rdebug (0.1)
rdiscount (1.6.8)
rdoc (3.9.4)
ruby-debug-base19x (0.11.30.pre4)
ruby_core_source (0.1.5)
rubygems-update (1.8.13)
rubyzip (0.9.5)
selenium-webdriver (2.15.0)
watir-webdriver (0.4.1)
wirble (0.1.3)
This is the error that presents itself when I try to "require" ruby-debug.
Error:
irb(main):001:0> require 'ruby-debug'
LoadError: cannot load such file -- ruby-debug
from C:/Ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):1
from C:/Ruby/bin/irb:12:in `<main>'
irb(main):002:0>
ruby-debug has been broken with recent ruby versions for a very long time. Try the debugger gem instead. I've no idea if it works on Windows though.
try this
gem install ruby-debug --pre

Ruby undefined method error using Deprecate.skip_during

I am trying to install Gitorious in my local computer. However I get this error when I execute the console application:
/usr/lib/ruby/gems/1.9.1/gems/bundler-1.0.15/lib/bundler/rubygems_integration.rb:194:in
block in stub_source_index170':
undefined methodskip_during' for
Bundler::RubygemsIntegration::Deprecate:Class
(NoMethodError)
The ruby code that is executing in /usr/lib/ruby/gems/1.9.1/gems/bundler-1.0.15/lib/bundler/rubygems_integration.rb is:
def stub_source_index170(specs)
Gem::SourceIndex.send(:define_method, :initialize) do |*args|
#gems = {}
# You're looking at this thinking: Oh! This is how I make those
# rubygems deprecations go away!
#
# You'd be correct BUT using of this method in production code
# must be approved by the rubygems team itself!
#
# This is your warning. If you use this and don't have approval
# we can't protect you.
#
Deprecate.skip_during do
self.spec_dirs = *args
add_specs(*specs)
end
end
end
I guess the error occurs because the deprecate module is not loaded or something like that... I don't know ruby... but how can I try to correct it?
I have ruby 1.9.1p431 (2011-02-18 revision 30908) with gem 1.8.5
List of gems:
* LOCAL GEMS *
actionmailer (2.3.5) actionpack
(2.3.5) activerecord (2.3.8, 2.3.5)
activeresource (2.3.5) activesupport
(2.3.8, 2.3.5) acts-as-taggable-on
(2.0.6) builder (3.0.0) bundler
(1.0.15) chronic (0.3.0)
daemon_controller (0.2.6) daemons
(1.1.0) diff-lcs (1.1.2) echoe (4.3.1)
eventmachine (0.12.10)
exception_notification (1.0.20090728)
factory_girl (1.3.3) fastthread
(1.0.7) gemcutter (0.6.1) geoip
(0.8.9) hoe (2.8.0) json_pure (1.5.0)
mime-types (1.16) mocha (0.9.10) mysql
(2.8.1) oauth (0.4.4) paperclip
(2.2.9.2) passenger (3.0.7)
proxymachine (1.2.4) rack (1.0.1)
rails (2.3.5) rake (0.8.7) rdiscount
(1.3.1.1) revo-ssl_requirement (1.1.0)
riddle (1.2.2) rmagick (2.13.1)
ruby-hmac (0.4.0) ruby-openid (2.1.8)
ruby-yadis (0.3.4) rubyforge (2.0.4)
shoulda (2.9.2) state_machine (0.9.4)
stomp (1.1) stompserver (0.9.9) tuxml
(0.0.1) validates_url_format_of
(0.1.1) will_paginate (2.3.15)
Many thanks in advance.
Carlos.
Newer versions of Rubygems are deprecating some old internal methods. You can downgrade Rubygems with gem update --system 1.x.y (e.g. 1.5.2) to see if that solves your problem.
Deprecate was namespaced to Gem::Deprecate. You can temporary patch it:
Gem::Deprecate.skip_during do
self.spec_dirs = *args
add_specs(*specs)
end

Rake 0.8.7 and ActiveSupport 3.0.1

I am running Ruby 1.9.2. I have rake 0.8.7 installed. However running rake inside a Rails application gives me the following:
(in /usr/home/users/dimitar/Rails/spek)
Could not find activesupport-3.0.1 in any of the sources
Try running `bundle install`.
So I go ahead and run bundle install again and everything looks good:
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.1)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.1)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.1)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.8)
Using mail (2.2.7)
Using actionmailer (3.0.1)
Using arel (1.0.1)
Using activerecord (3.0.1)
Using activeresource (3.0.1)
Using bundler (1.0.3)
Using thor (0.14.3)
Using railties (3.0.1)
Using rails (3.0.1)
Using sqlite3-ruby (1.3.1)
Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed.
But rake still gives me the same error message. Any suggestions?
Actually the problem seems to come from the config/boot.rb file:
# Set up gems listed in the Gemfile.
gemfile = File.expand_path('../../Gemfile', __FILE__)
begin
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
rescue Bundler::GemNotFound => e
STDERR.puts e.message
STDERR.puts "Try running `bundle install`."
exit!
end if File.exist?(gemfile)
Do you have multiple Ruby interpreters installed (maybe via rvm or some other method)? If so, are you sure that the right one is active?
Things to look at:
which ruby
which rake
ruby -e 'puts $:' # To show the LOAD_PATH for gems
I had a similar problem using ruby-1.9.2 and fixed it by upgrading rubygems
sudo gem update --system
I had the same problem when I was using REE 1.8.7. I switched to 1.9.2 and did bundle install. Then my rake commands worked.
I had this issue when I mistakenly ran passenger with ruby 1.9.3 and the app used 1.8.7 in its .rvmrc. Fixed by using 1.9.3 (now I have encoding problems, but thats a different story).

Resources