mercredi 2 septembre 2015

Stub a service's instance method and check whether it received a call to it

I'm writing specs for a Rails project that uses an external service (Aws::S3 in this case). I would to stub calls to upload_file on any instance of Aws::S3::Object, and also be able to check afterwards whether an instance of this class has received a call to upload_file.

What I did so far:

allow_any_instance_of(Aws::S3::Object).to receive(:upload_file).and_return('Stubbed!')

and

expect_any_instance_of(Aws::S3::Object).to receive(:upload_file)

but somehow the expectation doesn't work (my code calls upload_file but RSpec doesn't see it).




Aucun commentaire:

Enregistrer un commentaire