Jack, It's better done with WebMock, but it depends on what type of test it is. Is this a feature/system test? Can you set up data in such a way that this endpoint returns this naturally?
On Tue, Mar 30, 2021 at 5:31 AM Jack Royal-Gordon <jac...@pobox.com> wrote: > > I’m trying to test how my screen handles an error return from an Ajax call. > In order to accomplish this, I need the Ajax call to return the error > response, and I’d like to do that by mocking the controller action. I’d like > to do something like: > > allow_any_instance_of(BooksController).to receive(:modify) { render status: > :not_found, json: "Unknown book: #{@book.id}" } > > > But the render call gives an “undefined method” error, presumably because I’m > in a test and not in a controller method. Is there a way for me to mock this > behavior, or do I somehow have to manipulate the actual controller into the > desired behavior? > > -- > You received this message because you are subscribed to the Google Groups > "rspec" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rspec+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rspec/4E901F64-D8F3-45FA-B49B-25E67B7E3988%40pobox.com. -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/CAAk5Ok-KUmqi5%2BoZmSHSRB9uGTsk07XkvtHbVWLjF_H%2Bv9dDkg%40mail.gmail.com.