Install *gem file with bundle - ruby

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

Related

rake neo4j:install[community-latest] - The `neo4j-rake_tasks` gem is no longer a dependency of the `neo4j-core` gem

I am following this instruction, "Getting Started with Neo4j and Ruby", https://neo4j.com/developer/ruby-course/.
Here is how you would setup your asset portal Rails app:
rails new asset_portal -m http://neo4jrb.io/neo4j/neo4j.rb -O
cd asset_portal
rake neo4j:install[community-latest]
rake neo4j:start
But after I run
rake neo4j:install[community-latest]
I got this note
The `neo4j-rake_tasks` gem is no longer a dependency of the `neo4j-core` gem.
If you would like to use the rake tasks, you will need to explicitly include the `neo4j-rake_tasks` gem in your project.
Please note that the `neo4j-rake_tasks` gem is only for development and test environments (NOT for production).
Be sure to require the `neo4j-rake_tasks` gem AFTER the `neo4j-core` and `neo4j` gems.
For more details see the Neo4j.rb documentation
What can I do now to make this statement, rake neo4j:install[community-latest], work?
Thanks!
only add the flowing snippet
gem 'neo4j-rake_tasks'
bundle install
Hopefully would solve your problem.
I need to add the following lines to GemFile
gem 'neo4j-core'
gem 'neo4j-rake_tasks'
And then run the commands
bundle install
rake neo4j:install[community-latest]
rake neo4j:start

Travis CI Build doesn't install gems for JRuby platform

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)

Using rspec with a local gem

I am using a local gem (on my machine) with another application that is a command line app.
I have something like this in the gemfile to refer to the local gem:
gem 'mygem', :path => '/Users/devmachine/Projects/mygem'
When I run bundle console I am able to use the gem and all is well. However, whenever I run my test suite (rspec) I get the following message:
ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mygem (LoadError)
I'm confused. Any ideas?
You need to run:
bundle exec rspec
If you are not using the bundle evironment rspec won't know what you put in your Gemfile and just use the Gems it finds installed.

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.

How can I run a gem's tests when using bundler

I have a private gem (built with jeweler) hosted on Github. I run unit tests before I commit but I'd like to test everything works when I use bundler from the end-user side.
So far I've just been creating a test environment with two files:
Gemfile:
gem 'my_gem', :git => 'git#github.com:my_repo/my_gem.git'
main.rb:
require "rubygems"
require "bundler/setup"
require "my_gem"
# Some code calling arbitrary methods from my gem
It seems like there's probably a way for me to run the unit tests built in to the gem.
Bundler supports the use of gemspecs for development. You can change your gemfile to the following:
source "http://www.rubygems.org"
gemspec
This will allow you to access all the gems you would need as a client of the gem you're building. Then in your test file you can just:
require "my_gem"
You can find more information in Yehuda's post.

Resources