Ruby on Rails2.3.8:单元测试:Rails/Ruby已设置为在每次测试之前运行.在所有测试之前运行的方法怎么样?

Nul*_*uli 5 ruby testing unit-testing ruby-on-rails

每次运行测试时,我都想初始化数据库,而不是每次测试.我知道Rspec之前有(:all),但我还没有能够做到这一点.我想知道铁轨是否有类似的东西.

Nul*_*uli 2

所有事情先于一切事情运行才进入班级的顶部

require 'test_helper'

class ObjectTest < ActiveSupport::TestCase
  call_rake("db:bootstrap RAILS_ENV=test")

  #set up our user for doing all our tests (this person is very busy)  
  @user = Factory(:user)
  @account = Factory(:account)    
  @user.account = @account
  @user.save

  # make sure our user and account got created 
  puts "||||||||||||||||||||||||||||||||||||||||||||||"
  puts "| propsal_test.rb"
  puts "|      #{@user.name}"
  puts "|      #{@user.account.name}"
  puts "||||||||||||||||||||||||||||||||||||||||||||||"
Run Code Online (Sandbox Code Playgroud)