I'm currently testing an iOS app that communicates with an JSON API. I need to start a sinatra server before running the tests. The server works as a mock for the real API.
Is there any way to run a one line script like this one ruby /path/to/server.rb ?
Thanks
Go to "Mange Schemes" and select you scheme, then expand "Tests" and select "Pre-actions" and add a new run script:

Select "Provide build settings from:" 
I think the variable you are looking for is ${SRCROOT}
In addition to @Sebastian answer make sure to add & after your ruby command since without it sinatra will block your tests execution.
Also it's useful to take care about post-action where you need to kill the ruby process. Following example uses bundler and rackup to start sinatra.
Example for pre-action script:
exec > /tmp/tests-pre-actions.log 2>&1
source ~/.bash_profile
SERVER_PATH="${PROJECT_DIR}"/"Server"
cd "$SERVER_PATH"
bundle exec rackup > /tmp/server.log 2>&1 &
#get the PID of the process
PID=$!
#save PID to file
echo $PID > /tmp/sinatra.pid
Example for post-action script:
exec > /tmp/tests-pre-actions.log 2>&1
source ~/.bash_profile
PID=$(</tmp/sinatra.pid)
echo "Sinatra server pid $PID"
kill -9 $PID
config.ru for rackup gem:
require './server'
trap('TERM') {Process.kill 'INT', Process.pid}
puts 'Run sinatra'
run Sinatra::Application
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With