私はWebアプリケーションのいくつかのテストを書いていますが、コントローラの1つがScope
オブジェクトのresolve
を呼び出します。これは若干修正されたスコープを返します。テストでは、元のスコープ(パラメータとしてScope.initialize
に渡された)を返すようにこのメソッドをスタブしたいと思います。スタブ中にオブジェクトのインスタンス変数にアクセスする方法は?
Scope
オブジェクト
class Scope
def initialize(scope)
@scope = scope
end
def resolve
# Return a modified scope.
end
end
コントローラ
class FooController < ApplicationController
def show
foos = Scope.new(Foo.some_foos).resolve
respond_with foos
end
end
試験
it "does something" do
allow_any_instance_of(Scope).to receive(:resolve).and_return(???.scope)
get :show
# Do some assertions.
end
Scope
のインスタンスに対してresolve
メソッドをスタブするために、???
のどこに配置する必要がありますか?作成された元のスコープを返すにはどうすればよいですか?
私はRspec 3.4.2を使用しています。