Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3985452
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:53:32+00:00 2026-05-20T05:53:32+00:00

As part of the RSpec, i need to reference a file contained in a

  • 0

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

Gem ‘foo’ contains a file that I need to reference with in the a rspec spec. Is there a reasonably stable RubyGem or Bundler API to figure out ‘foo’ base directory?

Assuming ‘foo’ is already required in my Gemfile:
in 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 gem_base_path API call?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:53:33+00:00Added an answer on May 20, 2026 at 5:53 am

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

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

    You can then do the following in your spec:

    filename = Foo::Configuration.result_xml_path
    

    This is much safer since you are getting all the information from the gem. It also looks cleaner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Part of an app I am working on includes a log file viewer, with
When using a helper class with an rspec test, I can't see to use
Part of an assignment for my parallel programming class is to create a file
If, as part of an RSpec or Cucumber test in my Rails application, I
I've just implemented OmniAuth (using Ryan Bates' Screencast http://asciicasts.com/episodes/235-omniauth-part-1 ) and am writing Rspec
Part of a web app I'm working on handles forms that need to be
I trying to get a backtrace with rspec but I can't get it working
When I run a spec file ( rspec spec/models/user_spec.rb ) it prints something like
I am using Ruby on Rails 3.1.0 and the rspec-rails 2 gem. I am
Part of the header file dlist.h is defined as: #ifndef __DLIST_H__ #define __DLIST_H__ #include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.