ruby ocra wont compile scripts with business_time gem - ruby

Trying to compile a ruby script to a Windows executable using ocra. For some reason since adding business_time to the script, it refuses to compile. If I remove the require 'business_time' it will compile. So I created a script for just business_time and it works but will not compile. Struggling to see what the issue is from the ERROR message.
Thanks in advance.
require 'rubygems'
require 'business_time'
puts 1.business_day.ago.strftime("%Y%m%d")
puts 1.business_day.ago.strftime("%m/%d/%Y")
C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:467: Use
RbConfig instead o
f obsolete and deprecated Config.
C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.rb:8:in
test'
: unknown command 'a' (ArgumentError)
from C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.r
b:8:in'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.r
b:3:in <module:Tests>'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.r
b:2:in'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/i18n-0.6.1/lib/i18n/tests/basics.r
b:1:in <top (required)>'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:467:inconst_
get'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:467:in block
(3 levels) in attempt_load_autoload'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:464:ineach'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:464:in block
(2 levels) in attempt_load_autoload'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:462:ineach'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:462:in block
in attempt_load_autoload'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:456:inloop'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:456:in attemp
t_load_autoload'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:679:inbuild_
exe'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:1138:in `block
in '
C:\Ruby>

Related

invalid byte sequence in UTF-8 (ArgumentError) with ocra

I try to convert a sample ruby script to an executable file with the ocra gem.Here is my ruby script.
puts "Hello word"
Gives me the following error when running ocra test.rb
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:34:in `tr': invalid byte sequence in UTF-8 (ArgumentError)
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:34:in `to_posix'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:57:in `subpath?'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:611:in `block (2 levels) in find_gem_files'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:609:in `each'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:609:in `block in find_gem_files'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:597:in `each'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:597:in `find_gem_files'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:755:in `build_exe'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ocra-1.3.11/bin/ocra:1231:in `block in <top (required)>'
My version of ruby
ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
Is there a good way to convert a ruby script to an executable file ?
The issue was my Window username contained the character รจ. Like Casper mentioned, UFT-8 must be respected with ocra. I followed this link to solve my problem and then restarted ocra and the issue was fixed.
Change user name on windows 10

Getting Warning from require savon in ruby

Ubuntu 18.04, ruby 2.5.1p57
I have a ruby program that I use on a number of different linux system. On one it produces a screed of warning from require 'savon'
elasticsearch#secesprd02:~$ ruby /usr/local/tools/dev/es-cluster/bin/send-json.rb -v --cluster test -c /usr/local/tools/dev/conf/conf.json -r name=ES-api-winlogbeat json/winlogbeat-api-key
/var/lib/gems/2.5.0/gems/akami-1.3.1/lib/akami/wsse.rb:99: warning: shadowing outer local variable - key
/var/lib/gems/2.5.0/gems/akami-1.3.1/lib/akami/wsse.rb:99: warning: shadowing outer local variable - v1
/var/lib/gems/2.5.0/gems/akami-1.3.1/lib/akami/wsse.rb:99: warning: shadowing outer local variable - v2
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59: warning: loading in progress, circular require considered harmful - /var/lib/gems/2.5.0/gems/gyoku-1.3.1/lib/gyoku/hash.rb
from /usr/local/tools/dev/es-cluster/bin/send-json.rb:8:in `<main>'
from /usr/local/tools/dev/es-cluster/bin/send-json.rb:8:in `require_relative'
from /usr/local/tools/dev/common-library/lib/app-configure.rb:3:in `<top (required)>'
from /usr/local/tools/dev/common-library/lib/app-configure.rb:3:in `require_relative'
from /usr/local/tools/common-library/lib/SecretServer.rb:1:in `<top (required)>'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from /var/lib/gems/2.5.0/gems/savon-2.12.1/lib/savon.rb:26:in `<top (required)>'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
...
The program runs without any obvious problems apart from the warings.
I have updated savon and akami gems but this made no difference.
The warning is caused due to
loading in progress, circular require considered harmful - /var/lib/gems/2.5.0/gems/gyoku-1.3.1/lib/gyoku/hash.rb
That should not cause you any harm, given that the require keeps track of files already loaded, so the behaviour of your application should not be affected in any way.
A good overview on that can be found on this answer.
Under normal circumstances it's fine to require the same file twice, because require keeps a record of the libraries it has loaded and ignores a second call.
It looks as if you get this error if the library you are requiring
requires itself somehow, which is not something that require can cope
with -- the require operation presumably needs to complete before the
library is added to the list.
So if in a.rb you require b.rb and in b.rb you require a.rb. then when you write require "a" Ruby will
* start to require a.rb
* start to require b.rb
* start to require a.rb again and realise there is something terribly wrong.

Ruby: Ocra not building standalone executables from ruby scripts even when provided the gems path as argument

As I stated in the Question title, I have installed Ruby 3.0 version in Windows 10 64Bit OS and I have coded this program for Password generation and copying the generated password to clipboard(PasswordGenerator.rb):
require 'clipboard'
CHARS = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a + ('!'..'?').to_a
def GeneratePassword(length=16)
return CHARS.sort_by{rand}.join[0...length.to_i]
end
Clipboard.copy (GeneratePassword 15)
And I have also installed all the necessary gems that could be needed as dependencies and even sub-dependencies with these:
gem install ocra
gem install --install-dir ./gems thor ftools nokogiri rubygems clipboard
But the second command above installed all the dependencies inside (dir of PasswordGenerator.rb)/gems/gems directory instead of (dir of PasswordGenerator.rb)/gems/ folder, but I ignored that as maybe gem install --install-dir sucked once due to glitch.
But now as I try to build standalone executable from PasswordGenerator.rb with ocra in the same directory it gives me this error. I want a permanent solution of this issue with understanding of why and how ocra wasn't able to add the gems even when specified in the build command the extra paths like ocra PasswordGenerator.rb ./gems/gems and threw this error:
path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:693:in `block (3 levels) in find_gem_files': undefined method `relative_path_from' for nil:NilClass (NoMethodError)
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:693:in `select'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:693:in `block (2 levels) in find_gem_files'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:685:in `each'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:685:in `block in find_gem_files'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:627:in `each'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:627:in `find_gem_files'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:755:in `build_exe'
from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:1231:in `block in <top (required)>'

Why does rake_test_loader.rb fail (LoadError) when tests run in Rake under RVM ruby version 2.2.1

I have just started to use RVM and have installed ruby version 2.2.1. I have a test project whose Rake test task I was successfully executing tests with the system version (2.0.0). When I then switch to 2.2.1 via RVM, the rake_test_loader fails with a LoadError.
As far I can see, there following are possible culprits
different version of Ruby in use
RVM environment is causing a problem
there is a problem with RVM and Rake
My code is packaged into standard gem structure. The rake file is as follows:
($LOAD_PATH << File.expand_path("../lib", __FILE__)).uniq!
require 'rake/testtask'
require 'rdoc/task'
require 'rubygems/package_task'
# Run All Tests Task
#
Rake::TestTask.new('test') do |t|
t.pattern = 'test/**/*tests.rb'
t.warning = true
end
task "default" => ["test"]
The exact error (with --trace flag set) is as follows:
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- test/unit (LoadError) from
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from
/Users/Sancho/dev/git/joy/test/expression/core_staging_gallery_name_regexp_tests.rb:1:in
<top (required)>' from
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:10:in
block (2 levels) in ' from
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:9:in
each' from
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:9:in
block in ' from
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in
select' from
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in
' rake aborted! Command failed with status (1): [ruby -w
-I"lib" "/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb"
"test/**/*tests.rb" ]
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/testtask.rb:108:in
block (3 levels) in define'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils.rb:57:in
call'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils.rb:57:in
sh'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils_ext.rb:37:in
sh'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils.rb:96:in
ruby'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils_ext.rb:37:in
ruby'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/testtask.rb:104:in
block (2 levels) in define'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils_ext.rb:58:in
verbose'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/testtask.rb:100:in
block in define'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in
call'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in
block in execute'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in
each'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in
execute'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in
block in invoke_with_call_chain'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in
mon_synchronize'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in
invoke_with_call_chain'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in
invoke'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in
invoke_task'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in
block (2 levels) in top_level'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in
each'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in
block in top_level'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in
run_with_threads'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in
top_level'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in
block in run'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in
standard_exception_handling'
/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in
run' /Users/Sancho/.rvm/rubies/ruby-2.2.1/bin/rake:33:in `'
Tasks: TOP => test
I am not sure if the above trace is that helpful, so I displayed the $LOAD_PATH when the tests are run under system ruby version 2.0.0 and RVM ruby version 2.2.1
$LOAD_PATH when tests fail under RVM ruby version 2.2.1:
"/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0",
"/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/x86_64-darwin14",
"/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby",
"/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/vendor_ruby/2.2.0",
"/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/vendor_ruby/2.2.0/x86_64-darwin14",
"/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/vendor_ruby",
"/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0",
"/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/x86_64-darwin14",
"/Users/Sancho/dev/git/joy/lib"
$LOAD_PATH when tests pass under 2.0.0:
"/Library/Ruby/Site/2.0.0",
"/Library/Ruby/Site/2.0.0/x86_64-darwin13",
"/Library/Ruby/Site/2.0.0/universal-darwin13",
"/Library/Ruby/Site",
"/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/vendor_ruby/2.0.0",
"/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/vendor_ruby/2.0.0/x86_64-darwin13",
"/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/vendor_ruby/2.0.0/universal-darwin13",
"/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/vendor_ruby",
"/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0",
"/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/x86_64-darwin13",
"/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin13",
"/Users/Sancho/dev/git/joy/lib"
The root of the project is /Users/Sancho/dev/git/joy/
Tests are located at /Users/Sancho/dev/git/joy/test/.../*_tests.rb
Code under test located at /Users/Sancho/dev/git/joy/lib/joy/.../*.rb
So to summarise, the same code (invoked by rake test task) is being executed in both scenarios, 1 passes the other fails. The first scenario is using the system version of ruby (version 2.0.0, passes) and the second scenario is RVM ruby version 2.2.1 (fails).
So, what's causing the LoadError problem?
Thanks.
UPDATE:
I have installed version 2.0.0p598 via RVM (as opposed to the system version 2.0.0p481. (I had to use p598 because p481 is no longer available).
Using version 2.0.0p598, the tests worked fine. This rules out RVM in itself being a problem and leads me to believe there is an issue with the latest version of ruby 2.2.1. Can anyone shed any light on this?
UPDATE No 2:
Ruby version 2.1.1p76 also works.

Error when trying to run RSPEC. Why?

I can't figure out why my RSPEC isn't working. I reinstalled RSPEC with sudo gem install rspec and then tried again to install with a specific version number (sudo gem install rspec -v 2.11.0)
I continue to get the following error message and I cannot figure out what it means. I believe that I may or may not have version 1 also installed, not sure.
Castillo$ rspec document_spec.rb
/Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require': no such file to load -- document (LoadError) from
/Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require' from /Users/Castillo/Desktop/document_spec.rb:1:in <top
(required)>' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:inload' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in block in load_spec_files' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:inmap' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in load_spec_files' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:inrun' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in
run' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in
block in autorun'
Add full path to your document.rb file into spec file
or use
require_relative
or
require File.expand_path('../document.rb', __FILE__)

Resources