简体   繁体   中英

How should I include before do in minitest rails3.2?

What is the syntax for writing before do in minitest ?

I am trying to write a test case using minitest in rails3.2.

In development environment, we are loading this data using some background jobs. so, I have tried to do the same thing in test environment also. Before running my test suite, I have to run the task in background and generate vibrancy data and the same is being used in the test suite for asserting. but, it's throwing undefined method `before' for 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) from test/unit/community_vibrancy_test.rb:4:in `'

replace before with setup

Check detailed documentation here https://api.rubyonrails.org/v5.1.0/classes/ActiveSupport/Testing/SetupAndTeardown.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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