lundi 26 novembre 2018

rspec expectations change depending on other expectations existing

I have a rails app tested with rspec using factorybot. Users have many entries. Entries belong to a category. Users have many categories through entries.

I created a user and put an expectation in to confirm the user had zero entries. Then I did a post request to create a new entry and category. The post request is successful and a new entry and category are created but my expectations fail in strange ways.

let(:user) {create(:user)} expect(user.categories.length).to eq(0) expect(user.entries.length).to eq(0) post "/api/v1/entries", params: valid_params, headers: { "Authorization" => "#{jwt}" } expect(response).to have_http_status(200) expect(user.categories.length).to eq(1) expect(user.entries.length).to eq(1)

If I have expectations for the users entries and categories being 0 and 1 the second set fails for them being 1. If I take out the first set of expectations for 0 the second set for 1 pass. Is there some rule in rspec that I am missing that changes behavior when testing the same value twice?

Aucun commentaire:

Enregistrer un commentaire