I have a suite of specs to run. I would like to run the specs multiple times with different parameters each time. For example, I am testing the SQL scripts against two different database versions. The test cases are the same, but the connection string is different. How will I achieve this? I am new to RSpec, I was able to get the whole suite working for one version. Just need to know how to rerun with different parameters?

I looked at Class:RSpec::Core::Runner, but it's not very clear to me from the documentation that how this can be leveraged to run multiple times?

1 Answers

2
Community On

You can solve this with env variables. Let's say that you want to run rspec for two different MySQL databases. You can define your db connection like this:

db_client = Mysql2::Client.new(database: ENV['DB_NAME'])

Now you can run your rspec like this:

DB_NAME=your_custom_db_name rspec
DB_NAME=other_db_name rspec