2013-04-23 20 views
0

내에서 클래스를 스텁 내가 지금 잘 작동 다음 컨트롤러 사양이 있습니다네임 스페이스

# This top part is a hack 
module MyModule 
    class MyOAuthClient < OAuthClient 
    def token_is_valid?(options) 
     true 
    end 
    end 
end 

# Here's the actual spec 
describe MyModule::OAuthController do 
    describe "GET callback" do 
    it "works fine when token is valid" do 
     post :callback, use_route: :my_module 
     expect(response.code).to eq("200") 
    end 
    end 
end 

내가하고 싶은 것은 스텁 내 사양의 원숭이 패치를 대체입니다. 어떻게해야합니까?

rspec-mocks docs은 네임 스페이스 아래에 있지 않은 스텁 클래스의 예제를 보여 주지만 이러한 예제를 네임 스페이스 클래스에 적용하고 작동시킬 수는 없습니다.

나는 이미 특정 것들을 시도했지만 잘못된 생각으로 사람들의 대답을 편향하고 싶지 않습니다.

답변

1

내가이었다 밝혀 any_instance 후 :

MyModule::OAuthClient.any_instance.stub(:token_is_valid?) { true } 
관련 문제