开发者

Where should I place universal setup code for rails unit tests?

开发者 https://www.devze.com 2022-12-17 21:23 出处:网络
I would like to stub a web service proxy before all my unit tests. I could call some shared code in e开发者_JAVA百科ach unit test, but I was wondering if there is a better way.

I would like to stub a web service proxy before all my unit tests. I could call some shared code in e开发者_JAVA百科ach unit test, but I was wondering if there is a better way.

I am using Shoulda.

Thanks


in test/test_helper you can do the following:

class ActiveSupport::TestCase
  def stub_some_stuff
    …
  end

  setup :stub_some_stuff
end

Be careful to ensure you don't just do it once by putting it outside of a setup block, doing so may result in the stub being torn down by the first test, and then all future requests just go straight through!


test/test_helper is a good place for common code - this will be injected into your TestCases

0

精彩评论

暂无评论...
验证码 换一张
取 消