繁体   English   中英

rails 如何在没有 rspec 的测试之前加载测试夹具?

[英]rails How to load test fixtures before tests without rspec?

现在,我有一个看起来像这样的单元测试:

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

正如评论所暗示的,我想在所有测试运行之前设置一次(不是每个测试一次),但为了做到这一点,它需要在test/fixtures文件夹中定义的夹具加载到 scope 之外测试甚至在测试运行之前。 有没有办法做到这一点?

您可以使用before(:suite)钩子。 它只会被调用一次。

before(:suite) do
  #load test/fixtures here
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM