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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:41:26+00:00 2026-06-11T14:41:26+00:00

Stack: Rails 3.0.7, Mongoid 2.2.5, RSpec 2.11.0, RR 1.0.4 I have a Subscription model

  • 0

Stack: Rails 3.0.7, Mongoid 2.2.5, RSpec 2.11.0, RR 1.0.4

I have a Subscription model that looks like this:

class Subscription
  include Mongoid::Document

  embeds_many :addons

  after_save :update_feature_policy!

  def update_feature_policy!
    puts "Updating feature policy!"
  end
end

I have a spec that looks like this:

it "should update FeaturePolicy when adding an addon" do
  puts "Starting spec"
  mock(subscription).update_feature_policy! { true }
  subscription.addons << user_addon
  puts "Finished spec"
end

The spec fails, but I see this output in the console:

Starting spec
Updating feature policy!
Finished spec

Failure/Error: mock(subscription).update_feature_policy! { true }
 RR::Errors::TimesCalledError:
   update_feature_policy!()
   Called 0 times.
   Expected 1 times.

What’s causing the mock object not to capture the method call and pass the spec?

  • 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-11T14:41:28+00:00Added an answer on June 11, 2026 at 2:41 pm

    It appears that the callback was re-finding the record and creating a separate instance of subscription (thus not hitting the mock object). I’m not sure why – seems like it’s not very performant – but I found a workaround:

    it "should update FeaturePolicy when adding an addon" do
      puts "Starting spec"
      mock.instance_of(Subscription).update_feature_policy! { true }
      subscription.addons << user_addon
      puts "Finished spec"
    end
    

    This checks for update_feature_policy! being called on any instance of Subscription. Not great, but for my purposes it works.

    If anyone can answer why this is happening or provide a better solution, please do.

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

Sidebar

Related Questions

My stack looks like this nginx -> thin -> rails. In my rails app
I have a Rails 3.2 app that I'm deploying on the Heroku Cedar stack.
I have Bitnami Rails stack installed on my Mac. To better explain my problem
I read that as you are using the default Rails stack you are happy,
I have deployed a rails 3.1 app to Heroku Cedar stack, and am trying
Still can't get this working...Rails 3.1.3, Ruby 1.9.2 on Heroku's Cedar Stack. Trying to
In my rails project I have a form to enter a dollar amount. This
I Am using exception notifier like this in my rails 3.0.7- gem 'exception_notification_rails3', :require
I using rails 3.2.3 on Heroku Bamboo stack. I got this error last night
I have a Rails 3.2 app that I've created and want to deploy it

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.