Can't resolve the load error for telegram bot - ruby

i've followed https://www.process.st/telegram-bot/ steps for creating a telegram bot. an absolute beginner to coding and i can't seem to get my bot to respond at all even after renaming the file.
Traceback (most recent call last):
2: from bot.rb:1:in `<main>'
1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- telegramtest_bot (LoadError)```

Looking over the tutorial, it looks like the gem is "telegram_bot" and not "telegramtest_bot". Gem requirees are exact wording.
e.g. require "nokogiri"
Additionally, you can version the gem in your gemfile.
This post seems to be a good overview of how "require" works: https://www.educba.com/ruby-require/

You can try the following in order to resolve it (for windows users):
Navigate to your telegram bot folder
Install bundle
run ruby bot.rb
Worked for me when i did that!

Related

Project working on one computer but not the other

My ruby project is working fine on one of my Macbooks, but on the other I get this error:
Traceback (most recent call last):
13: from bin/audiobook-now:5:in `<main>'
12: from /Users/TuzsNewMacBook/Development/code/audiobook-now-cli/lib/cli.rb:50:in `run'
11: from /Users/TuzsNewMacBook/Development/code/audiobook-now-cli/lib/cli.rb:7:in `get_books_from'
10: from /Users/TuzsNewMacBook/Development/code/audiobook-now-cli/lib/scraper.rb:7:in `scrape_book_list'
9: from /Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/capybara-2.18.0/lib/capybara/session.rb:274:in `visit'
8: from /Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/poltergeist-1.18.1/lib/capybara/poltergeist/driver.rb:100:in `visit'
7: from /Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/poltergeist-1.18.1/lib/capybara/poltergeist/driver.rb:27:in `browser'
6: from /Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/poltergeist-1.18.1/lib/capybara/poltergeist/driver.rb:47:in `client'
5: from /Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/poltergeist-1.18.1/lib/capybara/poltergeist/client.rb:16:in `start'
4: from /Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/poltergeist-1.18.1/lib/capybara/poltergeist/client.rb:16:in `new'
3: from /Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/poltergeist-1.18.1/lib/capybara/poltergeist/client.rb:53:in `initialize'
2: from /Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/cliver-0.3.2/lib/cliver.rb:24:in `detect!'
1: from /Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/cliver-0.3.2/lib/cliver/dependency.rb:116:in `detect!'
/Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/cliver-0.3.2/lib/cliver/dependency.rb:143:in `raise_not_found!': Could not find an executable ["phantomjs"] on your path. (Cliver::Dependency::NotFound)
I had been getting similar problems at various points and most of the fixes were in the code (some require statements were looping around to each other), but the program works on my other Macbook without these errors. Their repos are synced, I've even tried looking at the code to make sure they're identical. I've also used bundle list to compare the versions of the gems and they match. Here's the gemfile, in case it's helpful.
source "https://rubygems.org"
gem 'pry'
gem 'pry-rescue'
gem 'pry-stack_explorer'
gem 'pry-nav'
gem 'poltergeist'
gem 'nokogiri'
gem 'rspec'
gem 'require_all'
Both Macbooks are running the same version of Mojave and I don't think there's anything different about the systems that would cause this. They should all be on the same version of gems and bundlers etc.
Any ideas?
This line
/Users/TuzsNewMacBook/.rvm/gems/ruby-2.5.1/gems/cliver-0.3.2/lib/cliver/dependency.rb:143:in `raise_not_found!': Could not find an executable ["phantomjs"] on your path. (Cliver::Dependency::NotFound)
explains why your project does not work on another computer.
Gem poltergeist is a PhantomJS driver for Capybara. To make it work you need to install phantomjs (a headless browser). You could download it from PhantomJS official site:
http://phantomjs.org/download.html
Make sure you're installing the same version. To do so run this command in Terminal of 1st Macbook:
phantomjs -v
to find out the installed version, and install the same version on the 2nd Macbook.

Clarification of what Ruby's 'require' does

A heads up that I'm in no way a Ruby expert...I just use it from time to time for basic scripting. I'm trying to use the RubyCocoa framework so that I can use additional commands in my Ruby script.
As an example, if I was to try something as explicit as this:
#!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
require '/System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/cocoa.rb'
puts "Hello, World"
I receive this error:
/usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- osx/objc/cocoa.rb (LoadError)
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/cocoa.rb:8:in `<top (required)>'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from Test.rb:4:in `<main>'
I do have Homebrew installed on my Mac (running 10.10), but why does the require command go through to the Cellar folder? You can see I'm trying to use the 2.0 Ruby version from my Frameworks folder (the one in /usr/bin is still 1.9.3 (would also love for someone to explain how these versions differ and why)).
It goes through the Cellar folder because it is in your load path.
You can examine your load path by writing in your script
puts $:
Concerning your error message
You can use fully qualified path in require so
require '/System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/cocoa.rb'
is correct.
And indeed in your error message you can see this line
from /System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/cocoa.rb:8:in `<top (required)>'
So you correctly required your file
However from the first line of your error message.
usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- osx/objc/cocoa.rb (LoadError)
We can see ruby/osx/cocoa.rb tries to require another file. This one is different and found under osx/objc/cocoa.rb. So those files have similar names but are different.
And since it tries to require with require 'osx/objc/cocoa.rb' it fails because it does not know how to find it (not a fully qualified path here).
Maybe you can try to change the load path variable.
By adding the line:
$: << '/System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/objc/'
It might work but I’m not sure since I don’t know where that osx/obj folder is located on your machine.
you might want to take some time to clean your ruby installation and maybe instead a fresh ruby using rvm or rbenv (I prefer rbenv)

ruby test-unit test runner isnt running

I am attempting to make a custom test runner using test/unit in ruby
and have followed a tutorial outlined here
http://endofline.wordpress.com/2008/02/11/a-custom-testrunner-to-scratch-an-itch/
however when i try to run on it using the
ruby -rfast_fail_runner example_test.rb --runner fastfail
however i get the error
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- fast_fail_runner (LoadError)
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
You have a file in the current directory named fast_fail_runner.rb, right? Ruby is not finding it. You are following a very old tutorial and I suspect that old versions of Ruby had the current directory (.) on the load path or something like that.
Try replacing -rfast_fail_runner with -r./fast_fail_runner.

Rails Sinatra application not loading Gems. Do I have them in the wrong place?

I hope you can help me.
I am working on a small Sinatra Rails application. I have Ruby installed on Mac OSX using RVM (currently using ruby 1.9.2)
I changed my app to include some new gems and to use bundler/setup but I receive the following error when I start the server:
/Users/Matt/.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 -- bundler/setup (LoadError)
from /Users/Matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from application.rb:2:in `<main>'
I am fairly sure I have something going wrong here, I'm just not sure what or how to fix it.
Running the which commands receives the following output:
which ruby: /Users/Matt/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
which bundle: /Users/Matt/.rvm/gems/ruby-1.9.2-p290/bin/bundle
which gem: /Users/Matt/.rvm/rubies/ruby-1.9.2-p290/bin/gem
Please can someone help me as this is starting to drive me a little crazy.
Many thanks in advance for your help.
from the #stephenmurdoch's comment above:
try running gem install bundler followed by bundle install from inside your application.

Need help with require while modifiying a gem (active_merchant)

I'm trying to add a new gateway to the active_merchant gem and I'm having 'require' issues when I try to run it from source.
(I think my problem is not active_merchant-specific, but more of a general Ruby environment issue, so I dont think the specific gem in use has to do with it.)
This is what I've done:
Cloned the Git repo for AM, to my local directory "C:\Users\jb\Documents\Aptana Studio 3 Workspace\active_merchant"
Went about doing the changes in the "billing/gateways" directory (this is just background info..)
Copied the "Sample Usage" example on AM's Git repo to C:\Users\jb\Documents\Aptana Studio 3 Workspace\simple_gw_test.rb, which starts with:
require 'rubygems'
require 'active_merchant'
Ran "ruby simple_gw_test.rb" and got the error message:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
active_merchant (LoadError)
from <internal:lib/rubygems/custom_require>:29:in 'require'
from simple_gw_test.rb:3:in '<main>'
This is understandable, since I don't have active_merchant gem installed
However, I want to use the downloaded source in the sample file, since I'm modifying the gateway source continually.
I tried
require '/Users/jb/Documents/Aptana Studio 3 Workspace/active_merchant'
And then got the same error:
<internal:lib/rubygems/custom_require>:29:in require': no such file to load --
/Users/jb/Documents/Aptana Studio 3 Workspace/active_merchant (LoadError)
from <internal:lib/rubygems/custom_require>:29:inrequire'
from simple_gw_test.rb:2:in `<main>';
Any Ruby Guru who can shed some light greatly appreaciated!
--jb
PS: I'm using MRI 1.9.2 on Windows 7 x64.
Make sure you have read access to that file. Ruby has given me that error before when I didn't have correct permissions.
I guess I scratched my own itch: After a couple of hours of "Pickaxe book-ing" and googling, I got the code necessary to bootstap the gem without it being installed:
require_relative 'active_merchant/lib/active_merchant'

Resources