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 8371611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:12:18+00:00 2026-06-09T14:12:18+00:00

Using Rails 3.2 I have a controller in a subdirectory (e.g. /controllers/data_feeds/acme_feed_controller.rb) This controller

  • 0

Using Rails 3.2 I have a controller in a subdirectory (e.g. /controllers/data_feeds/acme_feed_controller.rb)

This controller has some constants as below

class DataFeeds::AcmeFeedController < ApplicationController

  MY_CONSTANT = "hi

  def do_something do
    ...
  end

end

In my rspec controller spec (which is in /spec/controllers/data_feeds/acme_feed_controller_spec.rb) I want to access that constant and below are two ways I’ve tried it (both commented out in the code below)

describe AcmeFeedController do
  if "tests something" do
    #c = AcmeFeedController.MY_CONSTANT
    #c = DataFeeds::AcmeFeedController.MY_CONSTANT
  end
end

I’m clearly not understanding something about the scope in which the spec test is run. What do I need to do and equally important why (i.e. what’s happening with the scopes).

Thanks for your help.

  • 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-06-09T14:12:19+00:00Added an answer on June 9, 2026 at 2:12 pm

    Constants cannot be referenced with dot syntax, so DataFeeds::AcmeFeedController.MY_CONSTANT would never work in any context. You need to use :: to reference constants: DataFeeds::AcmeFeedController::MY_CONSTANT.

    Note that is a ruby issue and has nothing to do with RSpec. When you face an issue like this, I recommend you figure out how to do it with plain ruby (e.g. in IRB) before worrying about how it works in RSpec (usually it will be the same, anyway).

    If you want to know how constants work in ruby, I commend you watch this talk that explains them in detail.

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

Sidebar

Related Questions

I'm using Rails 3 and I'd like to move some controller files from app/controllers
Using Rails 2.3.8. I have added this in my controller: filter_parameter_logging :password, :password_confirmation But
Using Rails 3.2. I have an individual Shop post, and each shop has reviews.
I'm using Rails 3 I have a controller called subscriber_controller.rb I just added an
I have a Rails application that unfortunately after a request to a controller, has
Im using Rails 3.0.3 I have a Model Bill: class Bill < ActiveRecord::Base has_many
Using: Rails 3.1.1 I have a controller/model/view called Category that is built up on
I'm using Rails and I have a User Controller for creating new users. To
Using Rails v2.1, lets say you have an action for a controller that is
I'm using rails-rspec gem and I have several specs (models, controllers, etc). When I

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.