Skip to content

Instantly share code, notes, and snippets.

View justin808's full-sized avatar

Justin Gordon justin808

View GitHub Profile
justin808 / spec_helper.rb
Last active August 29, 2015 13:57
spec_helper.rb What @railsonmaui uses for testing. See my gist of gems for testing.
View spec_helper.rb
# Configure ENV['LOG_LEVEL'] to be one of DEBUG, INFO, WARN, ERROR, FATAL
# figure out where we are being loaded from
if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any?
raise "foo"
rescue => e
puts <<-MSG
justin808 / Gemfile
Created March 10, 2014 07:43
Testing gems for Rails, Capybara, Poltergeist, Rspec
View Gemfile
# Hack to make heroku work. Works b/c on heroku, the ENV['HOME'] will be 'app'
# and this will then return test, which heroku knows to exclude
def hg(g)
(ENV['HOME'].gsub('/', '') == 'app' ? 'test' : g)
group :test, hg(:ci) do
gem 'simplecov', require: false
justin808 / database_cleaner.rb
Created March 10, 2014 07:53
Database Cleaner setup for Rails and Capybara
View database_cleaner.rb
RSpec.configure do |config|
config.seed_tables = %w(seed_table_1 seed_table_2)
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation, except: config.seed_tables)
config.before(:each) do
DatabaseCleaner.strategy = :transaction
justin808 / typeahead_helper.rb
Created March 10, 2014 07:55
Capybara, Poltergeist, typeahead.js
View typeahead_helper.rb
def fill_in_autocomplete(selector, value)
script = %Q{ $('#{selector}').val('#{value}').focus().keypress() }
def choose_autocomplete(text)
expect(page).to have_css(".tt-suggestion p", text: text, visible: false)
script = %Q{ $('.tt-suggestion:contains("#{text}")').click() }
justin808 / Guardfile
Created March 10, 2014 08:02
Guard rspec setup with Zeus and parallel-rspec
View Guardfile
group :spec do
guard('rspec', all_on_start: false,
all_after_pass: false,
run_all: { parallel: true, parallel_cli: '-n 4' },
cmd: 'zeus rspec',
notification: true,
failed_mode: :keep) do
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch("spec/spec_helper.rb") { "spec" }
justin808 / .rspec
Created March 10, 2014 08:05
Normal .rspec file
View .rspec
--require spec_helper
--require rspec/instafail
--format RSpec::Instafail
--format documentation
View parallel_tests.rake
def run_command_raise_if_error(command)
puts "Executing: #{command}"
result = %x[#{command}]
raise "rake task failed..........\n#{result}" if result.include?('rake aborted!')
def run_rake_command_raise_if_error(command)
run_command_raise_if_error("bundle exec rake #{command}")
justin808 / my_project.yml
Last active August 29, 2015 13:57
Sample Tmuxinator configuration
View my_project.yml
# First brew install tmux, gem install tmuxinator, and download item2
# Copy this file here: ~/.tmuxinator/my_project.yml
# Modify the paths (replace ~/my_project with your directory)
# Invoke with
# mux project
# Then hit 'Ctrl-a d' to detach
# Then run 'tmux -CC attach'
# Make sure that option for iterm2 is General --> tmux --> When attaching, open unrecognized windows in Tabs
# Also, check option "Automatically hide the tmux client session after connecting"
# alias beg='bundle exec guard'
justin808 / webpack.rails.config.js
Created September 16, 2014 19:12
Sample file for building rails assets with webpack. See for more details.
View webpack.rails.config.js
// Run like this
// cd webpack && webpack -w --config webpack.rails.config.js
var path = require("path");
var railsBundleFile = "rails-bundle.js";
var railsJsAssetsDir = "../app/assets/javascripts";
var railsBundleMapFile = railsBundleFile + ".map";
var railsBundleMapRelativePath = "../../../public/assets/" + railsBundleMapFile;
module.exports = {
justin808 /
Created September 16, 2014 19:16
Sample file for testing webpack bundled assets when used in the context of Rails. See for more details.
var webpack = require("webpack");
var path = require("path");
module.exports = {
devtool: "source-map",
context: __dirname, // + "/../app/assets/javascripts",
entry: [