mardi 20 février 2018

ActiveSupport::TestCase won't run DB commands?

I have 3 questions:

  1. What is the default testing library that comes with Rails? I can't actually see what it's called... MiniTest? TestUnit?

  2. How can I make some code run once per TestCase to setup for ALL tests. It seems setup do is run before each test, but I want to set up for the entire file.

  3. How come my example below doesn't work (it won't clear out and re-create the seed data before each test)

Code:

require 'test_helper'

# negative numbers
# 3+ line item journal entries

class LedgerTest < ActiveSupport::TestCase
  setup do
    ActiveRecord::Base.subclasses.each(&:delete_all)

    AccountType.create!(code: 101, name: 'Cash',                     category: :asset,     normal_balance: :debit)
    AccountType.create!(code: 102, name: 'Equipment',                category: :asset,     normal_balance: :debit)
    AccountType.create!(code: 103, name: 'Accumulated Depreciation', category: :asset,     normal_balance: :credit, contra: true)
  end

  test "test 1 here" do
  end

  test "test 2 here" do
  end
end

Aucun commentaire:

Enregistrer un commentaire