Module: GemSuit::Application::Test::InstanceMethods

Defined in:
lib/gem_suit/application/test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



25
26
27
# File 'lib/gem_suit/application/test.rb', line 25

def config
  @config
end

#verboseObject

Returns the value of attribute verbose.



25
26
27
# File 'lib/gem_suit/application/test.rb', line 25

def verbose
  @verbose
end

Instance Method Details

#create_test_databaseObject



35
36
37
38
39
40
# File 'lib/gem_suit/application/test.rb', line 35

def create_test_database
  write   "config/database.yml"
  execute "RAILS_ENV=test rake db:create"
ensure
  restore "**/*.#{STASHED_EXT}"
end

#descriptionObject



27
28
29
# File 'lib/gem_suit/application/test.rb', line 27

def description
  # Implement in subclass
end

#prepareObject



31
32
33
# File 'lib/gem_suit/application/test.rb', line 31

def prepare
  # Implement in subclass
end

#prepare_databaseObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gem_suit/application/test.rb', line 69

def prepare_database
  return if @db_prepared
  if @ran_generator
    stash   "db/schema.rb"
    execute "rake db:test:purge"
    execute "RAILS_ENV=test rake db:migrate"
  else
    execute "rake db:test:load"
  end
  @db_prepared = true
end

#run_environmentObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/gem_suit/application/test.rb', line 81

def run_environment
  ENV["RAILS_ENV"] = "test"

  require File.expand_path("config/environment.rb", root_path)
  require "#{"rails/" if Rails::VERSION::MAJOR >= 3}test_help"

  begin
    require "gem_suit/integration_test"
  rescue LoadError
    gem_suit_path = File.expand_path "../../..", __FILE__
    $:.unshift gem_suit_path
    require "gem_suit/integration_test"
  end

  Dir[File.expand_path("../#{File.basename(self.class.__file__, ".rb")}/**/*.rb", self.class.__file__)].each do |file|
    next if skip? :require, file
    require file
  end

  log "\nRunning Rails #{Rails::VERSION::STRING}\n\n"
end

#setup(config = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gem_suit/application/test.rb', line 42

def setup(config = {})
  @skipped_files = nil
  @config = config

  log "\n".ljust 145, "="
  log "Setting up test environment for Rails #{[rails_version, description].compact.join(" - ")}\n"
  log "\n".rjust 145, "="

  restore_all
  stash_all
  bundle_install

  prepare
  prepare_database
  @prepared = true
end

#test(config = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/gem_suit/application/test.rb', line 59

def test(config = {})
  setup config

  log "\n".rjust 145, "="
  log "Environment for Rails #{[rails_version, description].compact.join(" - ")} is ready for testing"
  log "=" .ljust 144, "="

  run_environment
end