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

  • Home
  • SEARCH
  • 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 7401211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:24:21+00:00 2026-05-29T04:24:21+00:00

How can I mix a module into an rspec context (aka describe ), such

  • 0

How can I mix a module into an rspec context (aka describe), such that the module’s constants are available to the spec?

module Foo
  FOO = 1
end

describe 'constants in rspec' do

  include Foo

  p const_get(:FOO)    # => 1
  p FOO                # uninitialized constant FOO (NameError)

end

That const_get can retrieve the constant when the name of the constant cannot is interesting. What’s causing rspec’s curious behavior?

I am using MRI 1.9.1 and rspec 2.8.0. The symptoms are the same with MRI 1.8.7.

  • 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-29T04:24:23+00:00Added an answer on May 29, 2026 at 4:24 am

    You can use RSpec’s shared_context:

    shared_context 'constants' do
      FOO = 1
    end
    
    describe Model do
      include_context 'constants'
    
      p FOO    # => 1
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume I want to create a trait that I can mix in into
I want to have classes that can mix only specified traits: class Peter extends
Via this question , it would seem that normally you can't mix-and-match look and
I found nothing about how I can mix-in routes from another module, like this:
I'm looking for a scala trait that I can mix in to a scala.swing.Component
I understand the IOC concept, which we can mix-and-match different classes using wiring. Every
Can you mix .net languages within a single project? So pre-compiled, I would like
Can we mix JSF RI 1.1 with Tomahawk, Primefaces, MyFaces, etc in one application?
Simple question: Can I mix in my desktop application Java and JavaFX Script code?
Can anyone tell me if it is possible to mix views arguments with static

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.