3

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.

ndnenkov
  • 35,425
  • 9
  • 72
  • 104
Ankush Ganatra
  • 500
  • 5
  • 23

2 Answers2

1

The file <rub-install-dir>/bin/gemis 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

Wand Maker
  • 18,476
  • 8
  • 53
  • 87
-1

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 !!!

Community
  • 1
  • 1
Gupta
  • 8,882
  • 4
  • 49
  • 59
  • Will this help to create a fake gem as OP is asking? – Wand Maker Dec 22 '15 at 10:29
  • @vinay, thanks for quick response, but its not related to what I am looking for. – Ankush Ganatra Dec 22 '15 at 10:48
  • Yes !!! Indeed because i had added this line in my gemfile _gem 'bing-ads-api', :path => "~/bing-ads-api"_ .And after _bundle install_ .It shows _Using bing-ads-api 0.3 from source at ~/bing-ads-api_ in bundle log file.And further as @Ankush is asking about to _How to create a fake gem which can appear in gem list_. I think it is an answer But Still make me correct if I'm missing something . – Gupta Dec 22 '15 at 10:49
  • @vinay. I want a gem to appear in the 'gem list' without actually creating one. – Ankush Ganatra Dec 22 '15 at 10:52