[英]rails How to load test fixtures before tests without rspec?
Right now, I have a unit test that looks something like this:现在,我有一个看起来像这样的单元测试:
class ModelTest < ActiveSupport::TestCase
# fixtures are not loaded yet
# would like to setup something here ONCE (not once for every test)
context 'test1' do
#fixtures are not loaded in here either
should 'test1 test1' do
#fixtures are only loaded in here
end
end
end
As the comments suggest, I want to setup something there ONCE (not once for every test) before all the tests run, but in order to do so, it requires the fixtures defined in test/fixtures
folder to be loaded outside the scope of the tests and before the tests even run.正如评论所暗示的,我想在所有测试运行之前设置一次(不是每个测试一次),但为了做到这一点,它需要在
test/fixtures
文件夹中定义的夹具加载到 scope 之外测试甚至在测试运行之前。 Is there any way of accomplishing this?有没有办法做到这一点?
You can use before(:suite)
hook.您可以使用
before(:suite)
钩子。 It will be called only once.它只会被调用一次。
before(:suite) do
#load test/fixtures here
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.