Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different databases for specs

I want to run most my RSpec-s agains blazing fast SQLite, but be able to "tag" particular specs to use PostgreSQL (due to the heavy use of features of PG).

this is approx what I need:

describe "something" do
  it "runs against SQLite by default" do
    # etc
  end

  it "but this against PG", :pg do
    # etc
  end
end

I can probably hack in the establish_connection but want to do it "right" so the models don't share any of the stuff between the two.

Another issue is how to run rake tasks against those 2 DBs.

Please NOTE, I'm not asking about using multiple databases from the app. I want to switch DB between the specs.

There gotta be a gem for that :)

like image 662
Dmytrii Nagirniak Avatar asked Jun 16 '26 10:06

Dmytrii Nagirniak


1 Answers

One way would be to use this solution:

Rails RSpec with Multiple Databases

Basically in your before(:each / :all) connect to the other database and in your after(:each / :all) restore the default connection.

like image 51
bobics Avatar answered Jun 17 '26 22:06

bobics



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!