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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:21:52+00:00 2026-06-14T02:21:52+00:00

So my situation is: I have a 2 modules that have the same structure

  • 0

So my situation is:
I have a 2 modules that have the same structure like that:

module Module1
  class Config

    def fee_rate
      2
    end
  end
end

So, say, Module2 would have class Config with the method fee_rate, just with a different value (those are actually implemented in a rails engine, but it shouldn’t matter)

and then my model can use either Module1 or Module2 to get the fee rate value like that:

def config
  @config ||= "#{module_name.titleize}::Config".constantize.new
  @config
end

def get_value
  config.get_fee * some_other_value
end

What I’m trying to test is if get_fee function was called on the correct class:

"#{model.module_name.titleize}::Config".constantize.any_instance.expects(:get_fee).at_least_once
model.get_value

and on the line when I call get_value I get the following error – undefined method `*’ for nil:NilClass. I’m completely lost now, so I’d appreciate any help and ideas.

  • 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-14T02:21:54+00:00Added an answer on June 14, 2026 at 2:21 am

    By setting up an expectation for get_fee you are preventing the actual method call from happening. Because you haven’t set a return value for the expectation, e.g. expects(:get_fee).at_least_once.returns(3) it is returning nil, hence the error message.

    You may have more success by doing away with the expectation altogether and checking that the right type of config class is created, e.g.

    model.get_value
    assert_equal "#{model.module_name.titleize}::Config".constantize, 
                 model.config.class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where I have several VB.NET Modules in the same Logical-Module
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
Let's say i have 2 files located in the same folder. /Test/View.cshtml <h1>File that
I've heard before that modules are just classes too. I have a few situations,
Situation: Drupal 6 node module defining custom content type Necessity to have an automated
I have following situation - Have a MongoService class, which reads host, port, database
Situation I have a client library that uses the Windows Azure AppFabric Service Bus
I have some python module, which has a class ModuleClass and I can't modify
I have a legacy ASP.NET/VB.NET WebSite. There several App_Code modules/code files that use types
My situation is as follows: I use ubercart and I have 3 modules installed

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.