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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:44:43+00:00 2026-06-02T22:44:43+00:00

It seems I understood something wrong. I have a class module Spree class OmnikassaPaymentResponse

  • 0

It seems I understood something wrong. I have a class

module Spree
  class OmnikassaPaymentResponse
    #...
    # Finds a payment with provided parameters trough ActiveRecord.
    def payment(state = :processing)
      Spree::Payment.find(:first, :conditions => { :amount => @amount, :order_id => @order_id, :state => state } ) || raise(ActiveRecord::RecordNotFound)
    end
  end
end

Which is specced in Rspec:

describe "#payment" do
  it 'should try to find a Spree::Payment' do
    Spree::Payment.any_instance.stub(:find).and_return(Spree::Payment.new)
    Spree::Payment.any_instance.should_receive(:find)
    Spree::OmnikassaPaymentResponse.new(@seal, @data).payment
  end
end

This, however, always throws ActiveRecord::RecordNotFound. I expected any_instance.stub(:find).and_return() to make sure that whenever, wherever I call a #find on whatever instance I happen to have of Spree::Payment, it returns something.

In other words: I would expect the stub.and_return would avoid getting to || raise(ActiveRecord::RecordNotFound). But it does not.

Is my assumption wrong, my code? Something else?

  • 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-02T22:44:45+00:00Added an answer on June 2, 2026 at 10:44 pm

    In your case find is not an instance method, but a class method of Spree::Payment. That means you should stub it directly without any_instance like that:

    Spree::Payment.stub(:find).and_return(Spree::Payment.new)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DIV container that is a CSS class defined on the top
I have the following classes: abstract class DTO{ } class SubscriptionDTO extends DTO {
Now I have been scouring the web for what seems to be a mystery
I'm really confused. I want to do something that a) seems like it should
I have homework that I need to make a custom string class using C
Nominally a good problem to have, but I'm pretty sure it is because something
I have two lists based on the same class. I would like one list
Quick note: I'm using the SoundPool class http://developer.android.com/reference/android/media/SoundPool.html What I have here is a
It seems I have another problem with special character and double quotes and so
It seems I don't understand IPTABLES logic. I reinstalled ubuntu server 11.10 on my

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.