Cannot load such file -- ffi_c error in RubyMine - ruby

I tried to run a simple script as follows to learn automation using watir-webdriver and Ruby. But I am getting no such class error -ffi_c.
class TestWatir
require 'watir-webdriver'
require 'cucumber'
browser = Watir :: Browser.new :firefox
browser.goto 'http://www.google.com'
end
I've added Cucumber and Watir-webdriver gems and also checked there is ffi dependency in the external library.

I had this problem and resolved it by:
del Gemfile.lock
bundle clean --force
gem install bundler -v 1.12.1
gem install ffi -v 1.9.10 --platform=ruby
bundle install
It seams that some versions of ffi era labeled with the incorrect platform or something like that, that's bringing some problems on windows.
Hope it helps!

Related

Is the net/http gem not in the default library for Ruby?

I want to create a Gemfile.lock by typing 'bundle install' but my local machine can't find the gem net/http. I've tried typing 'bundle update net/http' & 'bundle --full-index' & 'gem install bundler' but I keep getting this error when I try 'bundle install' again:
Could not find gem 'net/http' in rubygems repository https://rubygems.org/ or installed locally. The source does not contain any versions of 'net/http'
my Gemfile resembles the following:
source "https://rubygems.org"
gem 'open-uri'
gem 'nokogiri'
gem 'net/http'
gem 'pry'
Other solutions to this problem suggest removing the line for gem net/http because net/http is part of the default library for Ruby...however when I do this everything loads fine, and I can create a Gemfile.lock upon typing 'bundle install' but when I run my code I get the following error:
Traceback (most recent call last):
run.rb:4:in `': uninitialized constant Net (NameError)
Did you mean? Set
The line of code this refers to is
response = Net::HTTP.get(url)
I'm running Ruby version 2.6.1
The name of the gem is net-http. It is one of the first hits when you google for "net/http".
However, in Ruby 2.6.1, net/http is still part of the standard library, not a gem. Net/http was only removed from the standard library in Ruby 3.0.
There are two different kinds of standard gems:
Default gems: These gems are part of Ruby and you can always require them directly. You cannot remove them. They are maintained by Ruby core.
Bundled gems: The behavior of bundled gems is similar to normal gems, but they get automatically installed when you install Ruby. They can be uninstalled and they are maintained outside of Ruby core.
Your problem is the wrong name gem ('net-http' instead of 'net/http', you can run gem search ^net to find out remote gems start by 'net').
If the gem is 'default', no need to declare it in Gemfile.
You can check standard default gems on: https://stdgems.org/

Ruby Gem not install dependency

I created a Ruby Gem and published it. I tried downloading it and I keep getting cannot require my dependent gem. The code is at https://github.com/wallerjake/toolshed and the gem in question is httparty. The error that I am getting is
~/.rvm/gems/ruby-2.0.0-p353#sullivan_cotter/bundler/gems/toolshed-46404c5af06d/lib/toolshed.rb:2:in `require': cannot load such file -- httparty (LoadError)
I have updated my https://github.com/wallerjake/toolshed/blob/master/toolshed.gemspec to use add_dependency instead but that doesn't seem to be helping. Could it be conflicting with other Gems?
The version on rubygems is still the old one with only development dependencies. Worked fine when I downloaded and built you gem from Github.
Yes sorry I solved this by adding them as a dependency not a development dependency.
spec.add_dependency "httparty"
spec.add_dependency "json"
spec.add_dependency "pivotal-tracker"
You have specified development dependency, but call the rake form binary, just put rake gem dependency into usual add_dependency, and remove ::gem call to:
bin/toolshed:
require 'rubygems'
require 'toolshed'
require 'rake'
One again question: for what do you need the binary?
The toolshed.gemspec seems correct. How do you call it? Remove the installed gem with gem uninstall toolshed including binary. Make sure that the bundle install, and then call to bundle exec bin/toolshed.rb is correct after patching the dependencies.
After that generate the gem with gem build toolshed.gemspec, and install the gem with gem install toolshed-0.0.4.gem. Make sure that binary works. Only then publish the gem.

Ruby Gem LoadError

I am getting a ruby error when an app I am running tries to…
require "xcodeproj/xcodeproj_ext" (https://github.com/CocoaPods/Xcodeproj)
The gem has been installed in /Library/Ruby/Gems/1.8/gems/xcodeproj-0.5.5.
gem list xcodeproj outputs the following...
xcodeproj (0.5.5, 0.5.0, 0.4.3, 0.3.4, 0.3.1, 0.1.0)
There is no xcodeproj_ext file or directory. What is it looking for?
How do I best go about debugging this?
UPDATE: The app that I am trying to running is using http://gembundler.com/
Are you able to require any other gems? Try doing:
require 'rubygems'
require 'xcodeproj'
It seems something was missing in the installed gem.
After removing the ~/.bundler folder and running bundle install again it worked as expected.

How to activate test-unit for RubyMine when developing a library (gem)?

I'm developing a library (a gem) using Ruby 1.9.2. My Gemspec looks like the usual for a gem:
source "http://rubygems.org"
# Specify your gem's dependencies in table_builder.gemspec
gemspec
while in my gemspec I have this line:
s.add_development_dependency "test-unit"
I can see it's being installed and my Gemfile.lock includes it:
PATH
remote: .
specs:
foobar (0.0.1)
GEM
remote: http://rubygems.org/
specs:
test-unit (2.4.5)
PLATFORMS
ruby
DEPENDENCIES
foobar!
test-unit
In my Rakefile I load it with:
require "rubygems"
require "test/unit"
as well as in my test_helper.rb:
require "rubygems"
require "test/unit"
In the command line the tests run and pass, but in RubyMine, whether I run tests or the test rake task, I get this message:
MiniTest framework was detected. It is a limited version of original
Test::Unit framework. RubyMine/IDEA Ruby plugin test runner requires
full-featured version of the framework, otherwise default console
tests reporter will be used instead. Please install 'test-unit' gem
and activate it on runtime.
I'm using RVM, so I checked the SDK is the one I'm using on the command line and test-unit is listed in the list of installed gems.
So, how I activate test-unit in a way that RubyMine likes?
Please refer to help. You need Gemfile with the used gems listed in it for RubyMine to recognize the dependencies.
RubyMine 4.0 (in RC2 at the time of this writing) supports minitest and managed to run the tests out of the box. Way to go JetBrains!

Can't stop Sinatra using Ctrl+C when `require 'coffee-script'`

I'm running Ruby 1.9.2p180 on Ubuntu 11.04 64-bit.
I have the simplest possible CoffeeScript example using Sinatra which runs fine, but doesn't stop when I press the Ctrl+C shortcut. So every time I have to kill -9 and it's getting quite tedious.
The app.rb:
require 'sinatra'
require 'coffee-script'
get '/' do
'<script src="/app.js" type="text/javascript"></script>'
end
get '/app.js' do
coffee :app
end
The views/app.coffee:
alert 'Foo'
It works on Ruby 1.8.7 with minor modifications:
require 'rubygems'
require 'sinatra'
require 'coffee-script'
require 'json'
get '/' do
'<script src="/app.js" type="text/javascript"></script>'
end
get '/app.js' do
coffee :app
end
It also works on 1.9.2 when I remove the line require 'coffee-script', but gives me a warning:
WARN: tilt autoloading 'coffee_script' in a non thread-safe way; explicit require 'coffee_script' suggested.
Figured out that it works when using therubyracer, but fails on node. The version 0.1.97 from Ubuntu 10.10 repositories is the only exception. When using the 0.2.6 from Natty, it fails and also when installing the latest (0.4.8) using nvm, I wasn't able to install 0.1.97 via nvm.
Unable to replicate. I'm on a Mac (OS 10.6.7) running bash and Ruby 1.9.2p180. I don't get your tilt warning, either.
I also haven't experienced this problem when using The Middleman (Sinatra-based) or Rails 3.1; both use the same coffee-script gem (as does Tilt; I suspect the coffee_script is just a typo).
Have you tried updating all the pertinent gems (sinatra, coffee-script, tilt, execjs) to their latest versions? What JS environment do you have on your system (e.g. do you have node, or are you relying on therubyracer)?
On Ruby 1.9.2, Sinatra 1.3.2, CoffeeScript 2.2.0 and Node 0.6.2 this does not occur anymore.

Resources