Ruby on Rails2.3.8: Testing devices: Rails / Ruby has a setting to run before each test. What about the method that runs before all tests?

I would like to initialize the database every time I run tests, and not every test. I know that Rspec has (: all), but I could not achieve this. I was wondering if the rails have anything like that.

+5
source share
2 answers

Everything you need to run before everything just returns to class

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 "||||||||||||||||||||||||||||||||||||||||||||||"
+2
source

First: Test :: Unit used to use the equivalent of before (: all), but it was removed (I don’t know why).

-: , - , , , db. , , , .

, db, , , , - . , .

: db .

- , db, ... , db .

... , - - , , , , .

... , .

: , : " "

+4

All Articles