Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass parameter to Rspec test on the command line

I am trying to use RSpec to functional test my REST apis.

The way I would LIKE it to work is using a CI build to build and deploy my application to a test server somewhere in the cloud and then have it kick off automated functional tests. But in order to properly do that, I need to be able to pass in the base url/domain for where the app was deployed. It will not be the same.

Everything I've found so far makes it seem like RSpec can't do this. Is there another way to do it if I can't pass in parameters on the command line? Or is RSpec not the right choice for this?

like image 953
Kevin M Avatar asked Sep 22 '14 20:09

Kevin M


1 Answers

One way would be to bypass the call to rspec with something that accepts command line arguments and then initiate rspec in code. If you do not want to write your own binary for that, rake is capable of that too.

Look here for how to run rspec from code.

Another way would be setting an ENV variable when calling your test and preferably making it optional in the specs.

$> SPEC_URL=http://anotherhost:666 rspec

in code:

url = ENV['SPEC_URL'] || "http://localhost:4000"

I would suggest method two as it's the cleaner and easier approach in my opinion.

like image 81
dfherr Avatar answered Sep 21 '22 06:09

dfherr