Saturday, 15 September 2012

ruby on rails - How to stub after_create callback collectively in a model? -


I am using Rail 3.2.11, Mac OS X Mountain Lion, Rspec

this My problem is:

I have a model that has been created, it sends information to an API that works fine, but when I am testing it in RSPC, the test data is also API Is sent to the database. Here's the code:

Model

 After : create: send_to_api def send_to_api api = APIModule.initialize_api (parameter) api.send_data (self .attribute1, to connect to the API, to send data at the end of the API   

I tried this in my test:

  Model.any_instance .stub (: Send_to_api) .and_return (true)   

But this did not work. Every time I have created the model I said in my test, which sends them to the database. Will be appreciated. Thank you very much in the rim!

Not sure that you have yet detected it, but if you Mocha can be installed

  Model.any_instance.stubs (: send_to_api). Return (true)   

Just tested it and it works

No comments:

Post a Comment