Skip to content

Testing with VCR

Dany Marcoux edited this page Apr 30, 2020 · 11 revisions

In our CI environment, we don't have the backend running and therefore we are using VCR to replay previous recorded HTTP sessions between frontend and backend.

global_write_through

We have a configuration global named global_write_through which controls if data will be sent to backend or not. This configuration is controlled on spec/support/vcr.rb. To be able to generate or refresh an already generated cassette, you will need to enable the global_write_through before to run a spec. Important do not run the whole suite with global_write_through enabled. Instead run just the specific spec needing a new cassette.

Flushing the backend

In the process, of developing tests with cassettes, the backend doesn't get flushed between test runs. If cassettes are recorded without flushing the backend, they will contain responses from a backend filled up with previous data.

So, for example, when in your test you use a factory to create a package package1 with a file and run the test, a package with a file is created in the backend. If you modify the test to create a simple package package1 without a file, and run the test, the backend will keep the file attached to this package. And the rest of the code of your test will work as it was the first run, when it probably shouldn't.

To assure this doesn't happen when creating the cassettes, just delete the docker backend container, and wake up it again. This can be done with the following commands:

docker-compose rm -s -f backend
docker-compose up -d backend
Clone this wiki locally