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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:23:50+00:00 2026-05-26T23:23:50+00:00

I need orientation implementing the tests of a gem I’d like to build. It’s

  • 0

I need orientation implementing the tests of a gem I’d like to build. It’s a small gem that adds a new class method to ActiveRecord::Base. This new method will execute some SQL on demmand.

Trouble is, the SQL to be executed depends on the database backend. It’s different for SQLite, Postgres and MySQL. The ruby method signature is the same for all database backends – only the SQL changes.

So, how do I make the tests for this?

To clarify: I know how to ask ActiveRecord “what database backend are you on?”. What I need is a way to tell RSpec/Minitest/TestUnit “change the database backend to Postgres, and try all tests again. And then MySQL”.

  • 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-05-26T23:23:51+00:00Added an answer on May 26, 2026 at 11:23 pm

    Take a look at how DataMapper does this. They pass an environment variable ADAPTER when running the specs, which alters the gems that are installed/loaded by bundler and changes the connection setup in the spec helper. You should be able to do something similar, basically running the full suite once for each possible database backend.

    It looks like this when you run the DM core specs:

    ADAPTER=mysql bundle install
    ADAPTER=mysql bundle exec spec spec
    
    ADAPTER=sqlite bundle install
    ADAPTER=sqlite bundle exec rspec spec
    

    I reckon if you want to get the best coverage, this is a good approach. If you want to selectively test different things for different parts of the tests, you’d just have to use conditionals, though (in general) I see conditionals in tests as a bad thing.

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

Sidebar

Related Questions

Is there a special method to get iPhones orientation? I don't need it in
I need to detect when the device is in portrait orientation so that I
I need to implement data table with vertical header orientation and header that's take
I don't need to specify the orientation in this case, I just need to
Is there a function like beginIgnoringInteractionEvents in UIApplication that ignores rotation instead of touches?
I need a way to get an orientation (local x/y/z axes) at any point
I need to block rotation to landscape orientation because my app crashes when it
I need to build compass for my application. From reading the documentation it seems
I'm fairly new to ios programming and am implementing AQGridView in a project I'm
I need to get interface orientation in appDidBecomeActive:(UIApplication *)application [application statusBarOrientation]; but if the

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.