How can I make a gem appear in gem list without actually doing a gem install?
I did try to look at the GemRunner code but didn't get it.
How can I make a gem appear in gem list without actually doing a gem install?
I did try to look at the GemRunner code but didn't get it.
The file <rub-install-dir>/bin/gem
is a Ruby script that executes gem commands. When using command line it uses Gem::ConsoleUI
defined in user_interaction.rb
. Hence, gem commands will typically dump the output of commands to console.
For your tests, you may want to use Gem::MockGemUi
which lets you collect output of gem list command to a string.
Here is a sample Ruby program to demonstrate that.
require 'rubygems'
require 'rubygems/commands/list_command'
require 'rubygems/mock_gem_ui'
list_command = Gem::Commands::ListCommand.new
p list_command.ui
list_command.ui = Gem::MockGemUi.new
list_command.execute
list_command.ui.outs << "fake_gem (2.1.0)"
puts list_command.ui.output
Output will be something like this:
*** LOCAL GEMS ***
actionmailer (4.2.5, 4.2.4)
actionpack (4.2.5, 4.2.4)
...
warden (1.2.3)
web-console (2.2.1)
fake_gem (2.1.0)
The last line is a fake gem.
More information can be found by studying how RubyGems have written its tests.
It may not be a good idea to modify bin/gem
file to have custom output though, it will be better to use Gem::Commands::*
in your test class
1: gem 'My_own_gem', path: '<path-for-directory>'
2: Run bundle install
group :development do
gem 'awesome', :path => "~/code/awesome"
end
For More Info check-out how-can-bundler-gemfile-be-configured-to-use-different-gem-sources-during-dev
Hope this help you !!!