Skip to content

Instantly share code, notes, and snippets.

View justin808's full-sized avatar
💭
Hiring!

Justin Gordon justin808

💭
Hiring!
View GitHub Profile
@justin808
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.
# IMPT:
# 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?
begin
raise "foo"
rescue => e
puts <<-MSG
===================================================
@justin808
justin808 / Gemfile
Created March 10, 2014 07:43
Testing gems for Rails, Capybara, Poltergeist, Rspec
# http://soupmatt.com/fixing-bundlewithout-on-heroku-cedar
# 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)
end
group :test, hg(:ci) do
gem 'simplecov', require: false
@justin808
justin808 / database_cleaner.rb
Created March 10, 2014 07:53
Database Cleaner setup for Rails and Capybara
RSpec.configure do |config|
config.add_setting(:seed_tables)
config.seed_tables = %w(seed_table_1 seed_table_2)
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation, except: config.seed_tables)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
@justin808
justin808 / typeahead_helper.rb
Created March 10, 2014 07:55
Capybara, Poltergeist, typeahead.js
def fill_in_autocomplete(selector, value)
script = %Q{ $('#{selector}').val('#{value}').focus().keypress() }
page.execute_script(script)
end
def choose_autocomplete(text)
expect(page).to have_css(".tt-suggestion p", text: text, visible: false)
script = %Q{ $('.tt-suggestion:contains("#{text}")').click() }
page.execute_script(script)
end
@justin808
justin808 / Guardfile
Created March 10, 2014 08:02
Guard rspec setup with Zeus and parallel-rspec
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{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch("spec/spec_helper.rb") { "spec" }
@justin808
justin808 / .rspec
Created March 10, 2014 08:05
Normal .rspec file
--color
--require spec_helper
--require rspec/instafail
--format RSpec::Instafail
--backtrace
--format documentation
def run_command_raise_if_error(command)
puts "Executing: #{command}"
result = %x[#{command}]
raise "rake task failed..........\n#{result}" if result.include?('rake aborted!')
end
def run_rake_command_raise_if_error(command)
run_command_raise_if_error("bundle exec rake #{command}")
end
@justin808
justin808 / my_project.yml
Last active August 29, 2015 13:57
Sample Tmuxinator configuration
# 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
justin808 / webpack.rails.config.js
Created September 16, 2014 19:12
Sample file for building rails assets with webpack. See https://github.com/justin808/react-webpack-rails-tutorial for more details.
// 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
justin808 / webpack.hot.config.js
Created September 16, 2014 19:16
Sample file for testing webpack bundled assets when used in the context of Rails. See https://github.com/justin808/react-webpack-rails-tutorial for more details.
var webpack = require("webpack");
var path = require("path");
module.exports = {
devtool: "source-map",
context: __dirname, // + "/../app/assets/javascripts",
entry: [
"webpack-dev-server/client?http://localhost:3000",
"webpack/hot/dev-server",
"./scripts/webpack_only",