打桩命名空间
问题描述:
中的类我有以下控制器规范是现在工作得很好:打桩命名空间
# 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显示了不属于名称空间的存根类的示例,但似乎并不能将这些示例应用于命名空间类并使其工作。
我已经尝试过某些东西了,但我不想用不正确的猜测来偏倚人们的答案。
答
原来我any_instance
后:
MyModule::OAuthClient.any_instance.stub(:token_is_valid?) { true }