mardi 1 décembre 2020

How do you correctly test that an error is raised in Rails?

I'm testing an Interactor in Rails with assert_raise and I'm passing arguments to it that should not raise an error.

However, the assert_raise on that Interactor call doesnt fail, rendering a false positive.

VCR.use_cassette("crm.active_campaign.retrieve_contact_tags_for_contact.successful") do
  response = Crm::ListTags.call(adapter: @adapter, contact_id: contact_id)
  assert response.success? # assertion success
  assert_raise StandardError do
    Crm::ListTags.call(adapter: @adapter, contact_id: contact_id) # assertion should fail but doesn't (as if it were reaching the error)
  end
end

As you can see I'm passing the same arguments to both Interactor calls. The second one should fail because it should not reach the error that it expects to. However it doesnt.

Aucun commentaire:

Enregistrer un commentaire