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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:04:22+00:00 2026-06-15T01:04:22+00:00

I need to test that a piece of code executes two sql statements, which

  • 0

I need to test that a piece of code executes two sql statements, which I’m doing by saying

  ActiveRecord::Base.connection.should_receive(:execute).with("s1")
  ActiveRecord::Base.connection.should_receive(:execute).with("s2")

However, the code also executes a lot of other statements that I don’t care about, which trips up the test. How do I tell Rspec to make sure that s1 and s2 are in the list of executed statements?

  • 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-15T01:04:23+00:00Added an answer on June 15, 2026 at 1:04 am

    Update your version of RSpec to 2.12 and you will have access to the and_call_original method (see the documentation and use cases). Using that method, you can stub the execute method of ActiveRecord::Base.connection and make it call through to the original method, and then just add to that the expectations you want:

    ActiveRecord::Base.connection.stub(:execute).and_call_original
    ActiveRecord::Base.connection.should_receive(:execute).with(:s1)
    ActiveRecord::Base.connection.should_receive(:execute).with(:s2)
    

    If for whatever reason you are not using (or don’t want to use) the latest version of RSpec, you can achieve the same functionality this way:

    execute = ActiveRecord::Base.connection.method(:execute)
    ActiveRecord::Base.connection.should_receive(:execute).with(:s1)
    ActiveRecord::Base.connection.should_receive(:execute).with(:s2)
    ActiveRecord::Base.connection.stub(:execute) { |*args| execute.call(*args) }
    

    Refs:

    • rspec 2: detect call to method but still have it perform its function
    • Expect method call and proxy to original method with RSpec
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's look at the following piece of code which I unintentionally wrote: void test
My application contains a piece of code that executes inside of Component Services, so
I need to execute some piece of code before every JUnit test method. To
I need a live test server that accepts my requests for basic information via
I have this JUnit test that I need help developing a Interface and Class
I need to test a database user to see if that user has privileges
I need a script that will test an input field's contents to see if
I have table to test score data that I need to pivot and I
Problem I have a UDPlistener application that I need to write a unit test
I need to test Perl Application ( File operation , Data base operation..etc )

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.