Helpers are usually used to clear the presentation logic, so I would not put something like calling the Amazon API in a helper method.
Instead, move this method to a plain old Ruby class that you can call from your controller. An example would be:
class AmazonBookRetriever def get_books_from_amazon
Then your controller can call it:
def resources @books = AmazonBookRetriever.new.get_books_from_amazon(params[:search_term]) end
This should make the mockery much easier. You can drown out #new on AmazonBookRetriever to return the layout, and make sure it receives the get_books_from_amazon message.
source share