Skip to content

Instantly share code, notes, and snippets.

@bhgames
Last active December 12, 2015 08:18
Show Gist options
  • Save bhgames/4742713 to your computer and use it in GitHub Desktop.
Save bhgames/4742713 to your computer and use it in GitHub Desktop.
How to install TestUnit into a Cramp app
#1. create test directory at project level
#2. Create unit directory in test.
#3. Put this file, base_test.rb in test/units directory.
#Then run ruby -Itest test/unit/any_test.rb
#As long as any_test extends this BaseTest class.
#If you want to run specific tests
# ruby -Itest test/unit/any_test.rb -n test_specific_test_name
#Also, if you want to do something like fixtures, create a module called "RakeTasks"
#(rake_tasks.rb) in your lib directory. You can include methods to populate models in the
#setup method, it's called before every test.
base_dir = File.expand_path(File.join(File.dirname(__FILE__), "../.."))
ENV['RACK_ENV'] = 'test'
ENV['DATABASE_ENV'] = 'test'
require 'active_record'
require 'active_support'
require 'pry'
require "#{base_dir}/application.rb"
require 'test/unit'
require 'yaml'
class BaseTest < ActiveSupport::TestCase
def setup
PangeaApi::Application.initialize! unless ActiveRecord::Base.connected?
#Line below is optional, need lib/rake_tasks.rb module. It populates models before every test...note the
#call to the clean method - it destroys everything before repopulation. A good rule of thumb.
[:clean, :buildings, :units, :customers, :prospects, :applicants, :showings, :csv].map { |k| RakeTasks.send(k) }
end
end
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment