Skip to content

Setting up integration testing

Saverio Miroddi edited this page Jan 24, 2018 · 3 revisions

When writing integration tests, the vcr gem will record, for each VCR block, the requests/responses of the first UT execution.

When recording, it's crucial to have the data correct for avoiding performing and recording bad requests.

One of the most crucial components is the repository.
There are two ways of setting it up:

  • use :location, pointing to a real repository, for the first request, then remove it and use stubs for refining the UT
  • use stubs from the beginning

Using :location will make easier to get the UT right from the first attempt, and UT refinements will be inexpensive because the requests/responses stored are for a successful case.

A good reference is spec/integration/create_pr.rb.

Example of :location:

let(:git_client) { Geet::Utils::GitClient.new(location: '/path/to/testrepo') }
let(:repository) { Geet::Git::Repository.new(git_client: git_client) }

Stubbing:

allow(repository).to receive(:current_branch).and_return('mybranch1')
allow(repository).to receive(:remote).with('origin').and_return('git@github.com:saveriomiroddi/testrepo')
allow(repository).to receive(:remote).with('upstream').and_return('git@github.com:saverio-fr/testrepo_u')

The stubs to define are the three above (only the first two, when upstream is not used), so also the direct-stubbing approach is straightforward.

Clone this wiki locally