At my current work setup we use Vagrant to make the setup of our development environments as seamless as possible. The goal was to just enter ‘vagrant up’ and automate the rest of the development setup for Ruby on Rails applications whilst letting us use our familiar text edtiors on the host machine. We documented how to set up such an environment in this coding guide. This allows us to run the servers, tests and all other background services on the virtual machine and syncing the edited application files via unison, keeping our normal workflow.
The first thing to do is to setup the Vagrant box so that it uses static IPs for itself and the host machine, this is the same if VirtualBox is running in bridged mode. The single most important thing you need to know is that there exists a
:private_network - option and the host machine will always be accessible via
192.168.50.1. So for the guest machine you have to do this:
Now the VM will be reachable under the given IP. Of course you have to enter all hostnames in the
etc/hosts/ - file inside the guest machine. Following the conventions of the coding guide, this is done in the Bash script that bootstraps the Vagrant box, for example in
Now the Vagrant box knows where to find the respective applications.
The nice part about this is that you can now have any service or API required by the tested app running on the host machine, and it will be found. For example, for using an Selenium server on the host machine out of the Vagrant box you can set up your Capybara tests like this (in your
This means that the app inside the VM is reachable on port 4567, but the test driver will use the Selenium server which has to run on the host machine. The app under test has to run on its own dev server inside the Vagrant VM, and you will have to install all needed binaries for other web driver browsers on the host machine. When you now start the Capybara tests inside the VM, the tests will magically use the browsers on the host machine but run inside the VM.