Matt Gibson
Matt Gibson

Reputation: 14959

If I swap out Postgres for SQLite in my Rails test suite, is it going to cause problems?

I've seen people suggest that SQLite is a good option for running a test suite because it's faster. This seems like a good thing, and I want faster tests. However, I'm currently using Postgres because it's what I use in production and it seems like a bad idea to have a test environment that differs from production in such a significant way.

Given that I am using Rspec and Cucumber with Rails 4, is there any risk that switching my test suite to SQLite will cause errors to emerge, or maybe hide errors that I will not pick up? Essentially, it it totally transparent from ActiveRecord's point of view so that I can use it as a drop-in replacement?

I am not aware of any Postgres-specific code, although I am using some complex queries in places via scopes.

Upvotes: 1

Views: 97

Answers (1)

B Seven
B Seven

Reputation: 45941

As BroiSatse mentioned, you should make your test environment as much like your production environment as possible. It's not about making the tests run faster; it is critical to make the test suite useful.

Given that I am using Rspec and Cucumber with Rails 4, is there any risk that switching my test suite to SQLite will cause errors to emerge

Your question shows that different DB's can behave differently and reduce the efficacy of the test suite.

The best thing to do is switch to Postgres for your test environment. If you have failing specs that cannot be fixed immediately, then mark them as pending or switch to a new branch. Once the specs are fixed, merge the new branch to master.

Upvotes: 3

Related Questions