How to make 'whenever' gem work on Windows? - ruby

I wan to run "simple" cron using whenever on Windows XP. So I installed whenever gem install whenever and then ran my cron.rb
require 'rubygems'
require 'whenever'
every 1.days, :at => '5:30am' do
command "puts now"
end
but it complained that
You don't have i18n installed in your application.
Please add it to your Gemfile and run bundle install
So I ran gem install i18n and now the same code gives me an error
C:\whenever>ruby cron.rb
cron.rb:4: undefined method 'every' for main:Object (NoMethodError)
Any idea how I can make whenever gem work?
ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
gem 1.3.7
LOCAL GEMS
aaronh-chronic (0.3.9)
activesupport (3.0.9)
backports (1.18.2)
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)
whenever (0.6.8)

This gem is a wrapper for the *nix utility cron. We can see in the gem source file command_line.rb line 75 that it uses 'crontab' shell command.
It will not work on a standard Windows install as this command is not available.
There are windows versions such as cronw, but I cannot say if these would be compatible with the whenever gem.
Alternatively you could run your long running task as a windows service. This article should get you started.
If you must use whenever/cron, perhaps because you are deploying on *nix, try downloading the Binami Rubystack VM - you'll be up and running in minutes.

Related

Getting Load error -- watir-webdriver on Mac Yosemite

I have Ruby 2.2.2, I have already watir-webdriver gem installed, when I run following script
require 'rubygems'
require 'watir-webdriver'
browser = Watir::Browser.new :firefox
It gives in
`require': cannot load such file -- watir-webdriver(LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I have rubymine 7.1.2
Here is my gem list
$ gem list
* LOCAL GEMS *
bigdecimal (1.2.6)
bundler (1.10.3)
bundler-unload (1.0.2)
childprocess (0.5.6)
executable-hooks (1.3.2)
ffi (1.9.8)
gem-wrappers (1.2.7)
io-console (0.4.3)
json (1.8.1)
multi_json (1.11.1)
psych (2.0.8)
rake (10.4.2)
rdoc (4.2.0)
rubygems-bundler (1.4.4)
rubyzip (1.1.7)
rvm (1.11.3.9)
selenium-webdriver (2.46.2)
watir-webdriver (0.7.0)
websocket (1.2.2)
yard (0.8.7.6)
Please suggest what to do?
/System/Library/Frameworks/Ruby.framework/Versions/2.0/... is the system library in OS X Yosemite.
Ruby 2.2 (or any other version) is installed by you or some other user -- perhaps via RVM, given you have some rvm gem installed? If so you need to use RVM to change the default. If you did not install RVM correctly or ignored some warning or command it gave to you, you might want to re-install.
If you did not install Ruby 2.2 via RVM*, here are instructions for changing OS X default Ruby installed using Brew.
(*I could not recommend RVM more strongly. Other people like rbenv to do the same job.)

Error loading watir-webdriver

Is there a way to install an earlier version of watir-webdriver including dependencies?
I've been running watir-webdriver for a while now, but just ran into problems today when installing on a new Windows environment.
The error is on the require "watir-webdriver". The first error line indicates that ruby is unable to load ffi
C:/Ruby21/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ffi_c (LoadError)
It looks like the problem may be with the combination of gems, so am including the versions here:
bigdecimal (1.2.4)
childprocess (0.5.3)
ffi (1.9.5 x86-mingw32)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
multi_json (1.10.1)
psych (2.0.5)
rake (10.1.0)
rdoc (4.1.0)
rubyzip (1.1.6)
selenium-webdriver (2.43.0)
test-unit (2.1.3.0)
watir-webdriver (0.6.11, 0.6.10)
websocket (1.2.1)
If you know of a version that worked in the past, you can simple remove the current version and install an old one with the -v flag for gem install.
For example,
gem uninstall watir-webdriver
gem install watir-webdriver -v '= 0.4.0'
You can find the different available version on rubygems.org It will automatically install the proper dependencies.

Installing Webistrano on Debian squeeze 64bits

I'm currently trying to install Webistrano on a freshly installed debian squeeze 64bits, but I'm facing some issues that I can't manage to solve.
Note: The machine is created under Xen environment, I don't think this affect the procedure however it seemed important to mention it.
Procedure:
Informations:
Ruby version: ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
Rails version: `Rails 2.3.11
Path modifier with: /usr/lib/ruby/1.8:/var/lib/gems/1.8/bin
Rails env: development
Databases have been created
Databases setups for webistrano are, I believe correct (user/pass/path_to_sock_file)
So, here is what I did:
I first installed the 'basics' packages for such installation:
# apt-get install build-essential ruby rubygems libmysql-ruby libmysqlclient-dev libdbd-mysql-ruby mysql-server unzip rake
Then I have been downloading and extracting the project into /usr/src. After copying and configuring the files for email/databses setups (as suggested by https://github.com/peritor/webistrano), I continued by installing all the gems needed for the project:
bundle install
at this point, the command is stuck and isn't doing anything for an hour.
I know it can happen if the Gemfile is complicate, but it doesn't seem to be the case for me. (see the Gemfile following)
# cat Gemfile
source "http://rubygems.org"
gem 'bundler', "~>1.0.10"
gem "rails", "2.3.11"
gem "mysql"
gem "erubis"
gem "rake"
gem "syntax", "1.0.0"
gem "capistrano", "2.6.0"
gem "open4", "0.9.3"
gem "exception_notification", "2.3.3.0"
group :test do
gem "mocha", "0.9.8"
end
So deciding to go ahead I installed the gems by hands, which once finished gives:
# gem list *gems of Gemfile*
bundler (1.0.10)
rails (2.3.11)
mysql (2.8.1)
erubis (2.7.0)
rake (0.9.2.2)
syntax (1.0.0)
capistrano (2.6.0)
open4 (0.9.3)
exception_notification (2.3.3.0)
mocha (0.9.8)
So I believe everything should be working without having to run: bundle install
This is why I finally tried to create the database's structure with rake:
# rake db:migrate --trace
(in /usr/src/peritor-webistrano-a98ba6b)
rake aborted!
Bundler couldn't find some gems.Did you run `bundle install`?
/usr/src/peritor-webistrano-a98ba6b/config/../config/preinitializer.rb:18
/usr/src/peritor-webistrano-a98ba6b/config/boot.rb:28:in `load'
/usr/src/peritor-webistrano-a98ba6b/config/boot.rb:28:in `preinitialize'
/usr/src/peritor-webistrano-a98ba6b/config/boot.rb:10:in `boot!'
/usr/src/peritor-webistrano-a98ba6b/config/boot.rb:123
/usr/src/peritor-webistrano-a98ba6b/Rakefile:4:in `require'
/usr/src/peritor-webistrano-a98ba6b/Rakefile:4
/usr/lib/ruby/1.8/rake.rb:2383:in `load'
/usr/lib/ruby/1.8/rake.rb:2383:in `raw_load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2017:in `load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:2016:in `load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2000:in `run'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:1998:in `run'
/usr/bin/rake:28
According to rake error message, apparently some gems aren't properly installed, which seems weird to be, but I guess he can't find it.
So I double check with bundle tool:
# bundle check
Your Gemfile's dependencies could not be satisfied
Install missing gems with `bundle install`
# bundle show
Could not find gem 'mocha (= 0.9.8, runtime)' in any of the gem sources listed in your Gemfile.
And I'm stuck here, I just don't know how to continue.
I google around about mocha or gemfile issue, but haven't found much relevant.
I hope everything is clear and easy to understand as this is my first post.
Thanks for any reply/hints, also if I manage to evolve I'll try keeping you up to date!
Check these instructions:
http://www.gogolek.co.uk/blog/2012/10/web-application-deployment-webistrano-capistrano/
Additionally I had problems with mysql gem installation on my clean debian 6 64-bit, so I had to run
$ apt-get install libmysqlclient-dev ruby-dev
I ended up with following gems installed
Using rake (0.8.7)
Using activesupport (2.3.11)
Using rack (1.1.6)
Using actionpack (2.3.11)
Using actionmailer (2.3.11)
Using activerecord (2.3.11)
Using activeresource (2.3.11)
Using bundler (1.0.10)
Using highline (1.6.20)
Using net-ssh (2.7.0)
Using net-scp (1.1.2)
Using net-sftp (2.1.2)
Using net-ssh-gateway (1.2.0)
Using capistrano (2.6.0)
Using erubis (2.7.0)
Using exception_notification (2.3.3.0)
Using mocha (0.9.8)
Installing mysql (2.9.1) with native extensions
Installing open4 (0.9.3)
Installing rails (2.3.11)
Installing syntax (1.0.0)
Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed.

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.

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