Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Hiring!

Justin Gordon justin808

💭
Hiring!
View GitHub Profile
@justin808
justin808 / spec_helper.rb
Last active Aug 29, 2015
spec_helper.rb What @railsonmaui uses for testing. See my gist of gems for testing.
View spec_helper.rb
# 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
===================================================
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!')
end
def run_rake_command_raise_if_error(command)
run_command_raise_if_error("bundle exec rake #{command}")
end
@justin808
justin808 / database_cleaner.rb
Created Mar 10, 2014
Database Cleaner setup for Rails and Capybara
View database_cleaner.rb
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 Mar 10, 2014
Capybara, Poltergeist, typeahead.js
View typeahead_helper.rb
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 Mar 10, 2014
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{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch("spec/spec_helper.rb") { "spec" }
@justin808
justin808 / .rspec
Created Mar 10, 2014
Normal .rspec file
View .rspec
--color
--require spec_helper
--require rspec/instafail
--format RSpec::Instafail
--backtrace
--format documentation
@justin808
justin808 / Gemfile
Created Mar 10, 2014
Testing gems for Rails, Capybara, Poltergeist, Rspec
View Gemfile
# 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 / my_project.yml
Last active Aug 29, 2015
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
justin808 / webpack.rails.config.js
Created Sep 16, 2014
Sample file for building rails assets with webpack. See https://github.com/justin808/react-webpack-rails-tutorial 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
justin808 / assets.rake
Created Sep 16, 2014
Create rails-bundle.js file by using webpack. More details here: https://github.com/justin808/react-webpack-rails-tutorial.
View assets.rake
# lib/tasks/assets.rake
# The webpack task must run before assets:environment task.
# Otherwise Sprockets cannot find the files that webpack produces.
Rake::Task['assets:precompile']
.clear_prerequisites
.enhance(['assets:compile_environment'])
namespace :assets do
# In this task, set prerequisites for the assets:precompile task
task :compile_environment => :webpack do