Module: Adva::Testing

Defined in:
lib/adva/testing.rb,
lib/adva/testing/engine.rb

Defined Under Namespace

Modules: Engine

Class Method Summary collapse

Class Method Details

.each_engine(&block) ⇒ Object



30
31
32
# File 'lib/adva/testing.rb', line 30

def each_engine(&block)
  Adva.engines.each(&block)
end

.load_assertionsObject



34
35
36
# File 'lib/adva/testing.rb', line 34

def load_assertions
  Adva.engines.each { |e| e.load_assertions }
end

.load_cucumber_supportObject



42
43
44
# File 'lib/adva/testing.rb', line 42

def load_cucumber_support
  Adva.engines.each { |e| e.load_cucumber_support }
end

.load_factoriesObject



38
39
40
# File 'lib/adva/testing.rb', line 38

def load_factories
  Adva.engines.each { |e| e.load_factories }
end

.load_helpersObject



46
47
48
# File 'lib/adva/testing.rb', line 46

def load_helpers
  Adva.engines.each { |e| e.load_helpers }
end

.setup(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/adva/testing.rb', line 8

def setup(options = {})
  options = {
    :migrate => true
  }.merge(options)

  Adva.out = StringIO.new('')
  setup_logging(options)
  setup_active_record

  each_engine { |e| e.setup_load_paths }
  ActiveSupport::Slices.register

  each_engine { |e| e.new.require_patches }

  if options[:migrate]
    each_engine { |e| e.migrate }
  end

  load_assertions
  load_factories
end

.setup_active_recordObject



58
59
60
61
62
# File 'lib/adva/testing.rb', line 58

def setup_active_record
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
  ActiveRecord::Migration.verbose = false
  DatabaseCleaner.strategy = :truncation
end

.setup_logging(options) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/adva/testing.rb', line 50

def setup_logging(options)
  if log = options[:log]
    FileUtils.touch(log) unless File.exists?(log)
    Rails.logger = Logger.new(log)
    ActiveRecord::LogSubscriber.attach_to(:active_record)
  end
end