Skip to content

Instantly share code, notes, and snippets.

@dcunited001
Last active December 14, 2015 17:28
Show Gist options
  • Save dcunited001/5121926 to your computer and use it in GitHub Desktop.
Save dcunited001/5121926 to your computer and use it in GitHub Desktop.
Zeus Rails Config: - zeus json - custom plan - minitest helper - Guardfile - Gemfile `bundle install` `guard start` # https://github.com/dcunited001/guard-titan to setup: - need to write some test commands - and save them to the ".t/" folder - `echo 'zeus test test/models/*_test.rb' > .t/mo` - `touch .t/all` with this guard-titan config: - touch…
require 'zeus/rails'
# your custom command specifies your environments for each zeus command
# custom commands: https://github.com/burke/zeus/blob/master/docs/ruby/modifying.md
class CustomPlan < Zeus::Rails #refer to the Zeus::Rails for better info on how it works
# i override the default test environment
def test_environment
Bundler.require(:test)
::Rails.env = ENV['RAILS_ENV'] = 'test'
require APP_PATH
# this line ends up meaning that your environment
# won't be loaded. i don't really get it
#$rails_rake_task = 'yup' # lie to skip eager loading
::Rails.application.require_environment!
$rails_rake_task = nil
$LOAD_PATH.unshift ".", "./lib", "./test", "./spec"
end
def test_helper
require 'minitest_helper'
end
alias :minitest_helper :test_helper
def test
Zeus::M.run(ARGV)
end
def int_test_environment
test_environment
end
# not reaally necessary to save time,
# the integration helper is not too slow
def int_helper
require 'minitest_helper_integration'
end
def int
Zeus::M.run(ARGV)
end
end
Zeus.plan = CustomPlan.new
source :rubygems
# these really need to be saved in your default gemset
group :development, :test do
gem "zeus", "~> 0.13.2"
gem "guard-titan", "~> 0.0.1", github: "dcunited001/guard-titan"
end
# basic example of using guard with zeus
scope groups: [:zeus] #limit guard to watch these groups
interactor :guard_rc => '~/.my_guard-rc', :history_file => '.guard_history'
#=======================================================
# guard-titan: runs tests with zeus
#=======================================================
# for more notes:
# https://github.com/dcunited001/guard-titan/blob/master/lib/guard/titan/templates/Guardfile
group :zeus do
guard :titan, root: __FILE__, on_run_all: :recent, exclude_from_all: %w(ob mail) do
watch /^(.t\/(.*))$/
watch(%r|^test/(.*)_test\.rb|)
end
end
# unless you use :recent,
# you'll need to set up groups of scripts to run
# in the $PROJECT_ROOT/.t folder
#
# e.g.:
# make scripts:
# mkdir .t
# touch .t/all
# echo 'zeus test test/controllers' > .t/co
# echo 'zeus test test/features' > .t/feat
# echo 'zeus test test/helpers' > .t/help
# echo 'zeus test test/jobs' > .t/jo
# echo 'zeus test test/models' > .t/mo
# run a group: `touch .t/models .t/controllers` # or .t/mo .t/co
# run all groups: 'touch .t/all'
# on_run_all: :recent
# when you hit enter, guard only runs
# the files changed since last commit
# on_run_all: :all_keys
# when you hit enter, guard runs each script
# in .t folder.
# (except all + any keys in :exclude_from_all)
# on_run_all: :all
# runs ALL the tests...
# but zeus's arguments can only be so long..
# too many tests and you'll see: 'zeusclient.go:86: EOF'
#=======================================================
# guard-shell: runs tests without guard-titan gem
#=======================================================
# run `scope zeus-shell at guard prompt`
group :zeus-shell do
# though this one executes files one by one,
# so it's very slow..
guard :shell do
watch /(.*_test\.rb)/ do |m|
p m[0], 'Changed' #need better output here
n m[0], 'Changed' #notify with guard
`zeus test #{m[0]}`
end
end
end
# if you do this, add to your .gitignore_global!
# there's probably a better way to do this,
# this won't work well for a project
def zeus_test_setup
# normal minitest_helper code
# just trying to avoid running this twice
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
# etc, etc, ..
Dir[File.join("./test/support/**/*.rb")].sort.each { |f| require f }
end
def zeus_already_ran_helper?
@@zeus_already_ran_helper == true
end
begin
#unless the minitest_helper has already ran, this will fail
# thought of this to solve this problem quickly,
# theres probably a better way to ensure that
# minitest_helper only runs once
# not on ruby 2.0 yet, so don't want to autoload it
zeus_already_ran_helper?
rescue
zeus_test_setup
@@zeus_already_ran_helper = true
end
#run the files changed since last commit
# this should probably be a function
alias zchng="git status --porcelain |
grep 'test' | grep -v 'factories' |
cut -c4- | sort | uniq"
alias zchn="zchng | xargs zeus test"
{
"command": "ruby -rubygems -r./custom_plan -eZeus.go",
"plan": {
"boot": {
"default_bundle": {
"development_environment": {
"prerake": {"rake": []},
"runner": ["r"],
"console": ["c"],
"server": ["s"],
"generate": ["g"],
"destroy": ["d"],
"dbconsole": []
},
"test_environment": {
"test_helper": {"test": ["test"]}
},
"int_test_environment": {
"int_helper": {"int": ["int"]}
}
}
}
}
}
@dcunited001
Copy link
Author

trying to divide up tests into groups, specified by commands in files like .t/all, .t/models, etc.

then you can run each group of tests, or just run the changed ones, by setting up a default watcher.

# guard-shell
watch /(.t/models)/ do |m|
  `zeus test test/models/**/*_test.rb`
end

then with guard running, in any shell you can do:

touch .t/models

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment