API 呼び出しを行い、書籍の配列を返す get_books_from_amazon というヘルパー メソッドがあります。リクエスト仕様でそれをスタブ化する方法がわかりません。
module BooksHelper
def get_books_from_amazon(search_term)
...
end
end
class StaticController < ApplicationController
include BooksHelper
def resources
@books = get_books_from_amazon(search_term)
end
end
私は自分の仕様で次のことを試しましたが、それぞれ役に立ちませんでした:
# spec/requests/resource_pages_spec.rb
...
describe "Navigation" do
it "should do such and such" do
BooksHelper.stub!(:get_books_from_amazon).and_return(book_array)
StaticHelper.stub!(:get_books_from_amazon).and_return(book_array)
ApplicationHelper.stub!(:get_books_from_amazon).and_return(book_array)
StaticController.stub!(:get_books_from_amazon).and_return(book_array[0..4])
ApplicationController.stub!(:get_books_from_amazon).and_return(book_array[0..4])
request.stub!(:get_books_from_amazon).and_return(book_array)
helper.stub!(:get_books_from_amazon).and_return(book_array)
controller.stub!(:get_books_from_amazon).and_return(book_array)
self.stub!(:get_books_from_amazon).and_return(book_array)
stub!(:get_books_from_amazon).and_return(book_array)
visit resources_path
save_and_open_page
end
問題が何であるかについてのアイデアはありますか?