Travis CI Build doesn't install gems for JRuby platform - ruby

I have a travis build set up for my project that also run on JRuby. I mention the activerecord-jdbcsqlite3-adapter gem in the Gemfile for the :jruby platform:
platforms :jruby do
gem "activerecord-jdbcsqlite3-adapter"
end
but the build still always fails with the message LoadError: Please install the sqlite3 adapter:gem install activerecord-sqlite3-adapter(sqlite3 is not part of the bundle. Add it to Gemfile.) and the gem actually doesn't get installed.
The project is open source at https://github.com/simplabs/rails_api_auth, the build is at https://travis-ci.org/simplabs/rails_api_auth.

On travis-ci for sqlite3 the docs seem to indicate you need 'jdbc-sqlite3:
platforms: jruby do
gem 'jdbc-sqlite3'
gem 'activerecord-jdbc-adapter'
end
EDIT
Actually I think your real problem is that you checked-in your Gemfile lock files (Gemfile.lock && gemfiles/*.lock). Travis-ci isn't re-evaluating what Gems are needed for the particular platforms.

what happens if you do?:
platforms :jruby do
gem 'sqlite3'
gem 'activerecord-jdbcsqlite3-adapter'
end
maybe the adapter is still relying on classes from the sqlite3 gem (thats what i read from the errors so far)

Related

Ruby - Cannot use locally installed gem

I've written a simple PasswordGenerator gem that I have at ~/workspace/gems/password_generator and have an app at ~/workspace/rubysamples/app where I want to use it. I have a Gemfile, the content of it is this:
gem 'password_generator', path: '~/workspace/gems/password_generator'
I installed it locally, like this:
bundle install --local
Resolving dependencies...
Using bundler 1.16.5
Using password_generator 0.1.0 from source at `~/workspace/gems/password_generator`
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
It looks like it's installed locally:
bundle info password_generator
* password_generator (0.1.0)
Summary: Simple password generator
Homepage: https://github.com/jedrekdomanski/password_generator
Path: /home/jedrek/workspace/gems/password_generator
When I try to use it
~/workspace/rubysamples/app/password_reset.rb
PasswordGenerator.generate
I get an error
uninitialized constant PasswordGenerator (NameError)
What am I doing wrong? Am I missing anything?
Here's my gem repo: https://github.com/jedrekdomanski/password_generator
I also tried pointing to my repo and branch in the Gemfile
gem 'password_generator', git: 'git#github.com:jedrekdomanski/password_generator.git', branch: 'master'
but I get the same error message uninitialized constant PasswordGenerator (NameError)
There are potentially two issues. The first is how you are starting Ruby and the second is how you are requiring your module.
First, if you are starting Ruby by running ruby password_reset.rb then you are ignoring the Gemfile. The Gemfile is only used when you're using bundler, so you want to make sure you are starting Ruby by running bundle exec ruby password_reset.rb. This causes bundler to read your Gemfile and execute Ruby in that context.
Second, you're not properly including your module in your Ruby file. Just because you've added the gem to your Gemfile and started Ruby using bundler doesn't mean that the Ruby process knows you intend to use that gem's module; it just makes the module available for use. You might wonder, "Why don't I have to do that in Rails?" Because Rails does that for you automatically via config/application.rb.
Given these two issues, the correct way to accomplish your goal is to configure your app as follows:
First, create your Gemfile:
# Gemfile
gem 'password_generator', path: '~/workspace/gems/password_generator'
Second, create your password_reset.rb file:
# password_reset.rb
# Manually require any libraries that this app will use, even if defined in Gemfile
require 'password_generator'
# Call `puts` so something is printed to the console when this app runs
puts PasswordGenerator.generate
Third, run bundle install to ensure your Gemfile is properly formatted and to generate your Gemfile.lock:
⇒ bundle install
Using bundler 1.16.5
Using password_generator 0.1.0 from source at `../../gems/password_generator`
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Fourth, run bundle exec ruby password_reset.rb and observe the output:
⇒ bundle exec ruby password_reset.rb
kpiDfyTxtdAsKmYuZqmK
Everything works because:
Ruby is started with Bundler
Bundler reads your Gemfile and makes the gems available to Ruby
Your app requires the module from the gem before attempting to use the module

Install *gem file with bundle

I try to develop a gem. I include it in my rails application through Gemfile with :path option for testing purpose, but there are some errors that appear when I build it and release to rubygems that does not appear when gem included from local path. How can I install gem from *gem file (made with rake build command) in rails or any bundle driven application for testing?
This will give you the best help: http://guides.rubygems.org/make-your-own-gem/
But in summary you need to build your gem from the .gemspec then using irb require your gem to test it out.
Example:
gem build hola.gemspec
% irb
require 'hola'
=> true

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.

Create gem locally and skip rake install

I'm creating a ruby gem using Bundler for a simple rackup app (not Rails). It's a real pain to run rake install and then restart the webserver everytime. For most part it's ok because I test everything using rspec but not design. My gem contains a whole lot of design and everytime I update my gem I have to go threw the same procedure.
Is it possible to build gems locally without having to run rake install and then restart my rack server every single time?
If you're using Bundler to manage the gems in your application, you can use Bundler's path directive to use a gem that's currently in development.
In your Gemfile:
# My awesome gem that I'm developing
gem 'some-awesome-gem', :path => '~/Projects/some_awesome_gem'
Essentially, just point the path at the directory where your gem resides and you won't have to package new versions of the gem while you're actively developing it.
See the Bundler homepage and Gemfile Manual for more details.

Cannot install metric_fu, how to switch to simplecov?

I tried to install metric_fu against my Ruby 1.9 environment, but it failed due to the problem below:
$ gem install metric_fu
...
Fetching: rcov-1.0.0.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing metric_fu:
ERROR: Failed to build gem native extension.
/Users/xxx/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
**** Ruby 1.9 is not supported. Please switch to simplecov ****
It says "switch to simplecov", but how to do that?
UPDATE: Resoved after installing rcov 0.9.11. I found the same issue here:
https://github.com/iain/metrical/issues/12
You can use SimpleCov by adding
gem 'simplecov', :require => false
to your gem file in the test group, and then add into your spec_helper.rb:
require 'simplecov'
SimpleCov.start
then just open coverage/index.html and you get SimpleCov in the browser. It's really excellent.
I'm the new maintainer of metric_fu and it should work now on ruby 1.9 without any problems. See configuration instructions at https://github.com/metricfu/metric_fu which include how you can have metric_fu load external coverage output (e.g. using simplecov)
Rcov on ruby 1.9 segfaults and fails a lot, so running it is disabled by default and the gem is no longer included as a dependency. However, you may still config it to run or load coverage stats you've already generated
Also, it works from the command-line now. Now need to bundle it or run rake or metrical
Try rcov 0.9.11 as described here.
add to Gemfile (test section)
gem "rcov", "0.9.11"
rerun bundle install
run tests with bundle exec of course.

Resources