在 minitest rails3.2 之前应该如何包含?
How should I include before do in minitest rails3.2?
minitest中do之前的语法是什么?
我正在尝试使用 rails3.2 中的 minitest 编写一个测试用例。
在开发环境中,我们正在使用一些后台作业加载此数据。所以,我也尝试在测试环境中做同样的事情。
在 运行 设置我的测试套件之前,我必须 运行 在后台执行任务并生成活力数据,并且在测试套件中使用相同的数据进行断言。
但是,它为 CommunityVibrancyTest:Class (NoMethodError)
抛出未定义的方法“之前”
require 'test_helper'
Class CommunityVibrancyTest < ActiveSupport::TestCase
before :each do
App::Queue.add(CommunityVibrancyWorker, communities(:private_community).id )
end
test 'to check whether the vibrancy of a private community is handliing share or not' do
private_community = communities(:private_community)
share = shares(:share_for_private_microblog)
stat = share.object
post_vibrancy = stat.aggregated_score_mblog.round(1)
assert_equal post_vibrancy, private_community.community_vibrancies.last.post_vibrancy
end
end
test/unit/community_vibrancy_test.rb:24:in <class:CommunityVibrancyTest>': undefined method
before' for CommunityVibrancyTest:Class (NoMethodError)
来自 test/unit/community_vibrancy_test.rb:4:in `'
将before
替换为setup
在此处查看详细文档 https://api.rubyonrails.org/v5.1.0/classes/ActiveSupport/Testing/SetupAndTeardown.html
minitest中do之前的语法是什么?
我正在尝试使用 rails3.2 中的 minitest 编写一个测试用例。
在开发环境中,我们正在使用一些后台作业加载此数据。所以,我也尝试在测试环境中做同样的事情。 在 运行 设置我的测试套件之前,我必须 运行 在后台执行任务并生成活力数据,并且在测试套件中使用相同的数据进行断言。 但是,它为 CommunityVibrancyTest:Class (NoMethodError)
抛出未定义的方法“之前” require 'test_helper'
Class CommunityVibrancyTest < ActiveSupport::TestCase
before :each do
App::Queue.add(CommunityVibrancyWorker, communities(:private_community).id )
end
test 'to check whether the vibrancy of a private community is handliing share or not' do
private_community = communities(:private_community)
share = shares(:share_for_private_microblog)
stat = share.object
post_vibrancy = stat.aggregated_score_mblog.round(1)
assert_equal post_vibrancy, private_community.community_vibrancies.last.post_vibrancy
end
end
test/unit/community_vibrancy_test.rb:24:in <class:CommunityVibrancyTest>': undefined method
before' for CommunityVibrancyTest:Class (NoMethodError)
来自 test/unit/community_vibrancy_test.rb:4:in `'
将before
替换为setup
在此处查看详细文档 https://api.rubyonrails.org/v5.1.0/classes/ActiveSupport/Testing/SetupAndTeardown.html