Base / Home Gemstone Catalog

As part of RSpec, I need to reference the file contained in the gem. I am depending on (name it gem foo). I control gem foo, so I can make changes to it as needed.

The gem 'foo' contains the file I need to refer to in the rspec spec. Is there a stable enough RubyGem or Bundler API to define the base directory foo?

Assuming 'foo' is already required in my Gemfile: in the Gemfile:

gem 'foo'

I want to do something like this (in something_spec.rb):

filename = File.expand_path('examples/xml/result.xml', Gem.gem_base_path('foo'))

What is the gem_base_path API call?

+3
source share
2 answers

I would recommend creating a function in your stone to do this:

module Foo
  class Configuration
    def self.result_xml_path
      File.realpath("../examples/xml/result.xml")
    end
  end
end

:

filename = Foo::Configuration.result_xml_path

, . .

+2

, , ant 'foo':

matches = Gem::Specification.find_all_by_name 'foo'
spec = matches.first
filename = File.expand_path('examples/xml/result.xml', spec.full_gem_path)

, - , ( , , , )

0

Source: https://habr.com/ru/post/1793676/


All Articles