Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在所有单元测试之前存根一个 Web 服务代理。我可以在每个单元测试中调用一些共享代码,但我想知道是否有更好的方法。
我正在使用应该。
谢谢
在 test/test_helper 中,您可以执行以下操作:
class ActiveSupport::TestCase def stub_some_stuff … end setup :stub_some_stuff end
小心确保你不要只做一次,把它放在一个设置块之外,这样做可能会导致存根被第一次测试拆除,然后所有未来的请求都会直接通过!
test/test_helper 是常见代码的好地方 - 这将被注入到您的 TestCases