Skip to content

Instantly share code, notes, and snippets.

@dnagir
dnagir / ste3-automactially-run.sh
Created January 13, 2012 09:43
RVM JRuby 1.9 mode
> if [[ "$RUBY_VERSION" == "jruby-19" ]]; then export export PROJECT_JRUBY_OPTS=( --1.9 ); fi
> rvm use $RUBY_VERSION
@dnagir
dnagir / gist:1630480
Created January 18, 2012 02:34
When Ruby undefined becomes defined
> irb
1.9.3p0 :001 > a
NameError: undefined local variable or method `a' for main:Object
from (irb):1
from /Users/dnagir/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :002 > b
NameError: undefined local variable or method `b' for main:Object
from (irb):2
from /Users/dnagir/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :003 > a = b
@dnagir
dnagir / controller_spec_plain.rb
Created January 24, 2012 02:54
How the simples thing (its gem) makes specs much easier to read
# Controller spec using plain old matchers
describe "#create" do
let(:participation) { stub 'Participation' }
let(:params) { {:participation => {}} }
before { InviteUser.stub(:into_company_by_params => participation) }
context "with success" do
before { participation.stub(:valid? => true) }
@dnagir
dnagir / faster_helper.rb
Created January 25, 2012 03:21
The spec helper I use to run faster specs
ENV["RAILS_ENV"] ||= 'test'
cur_dir = File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH << "#{cur_dir}"
if defined? Bundler
# Most likely going with the full env
require 'spec_helper'
else
$LOAD_PATH << "#{cur_dir}/app/models"
@dnagir
dnagir / ci.rake
Created January 28, 2012 07:24
Fail CI build with SimpleCov
# lib/tasks/ci.rake
require 'nokogiri'
desc "Run everything on the CI server with all its outcomes (deploy etc)"
task :ci do
Rake::Task['spec'].invoke
ensure_test_coverage 99
Rake::Task['cucumber'].invoke
# TODO: Figure out how to run Jasminerice https://github.com/bradphelan/jasminerice/issues/31
@dnagir
dnagir / fail_fast.rb
Created February 1, 2012 08:00
Fail fast with Capybara
require 'capybara/util/timeout'
# Rewriting the https://github.com/jnicklas/capybara/blob/master/lib/capybara/util/timeout.rb
# Instead of raising timeout error, print the response info
module Capybara
class << self
##
# Provides timeout similar to standard library Timeout, but avoids threads
@dnagir
dnagir / has_symbolic_field.rb
Created February 8, 2012 23:44
Symbols and enums
module HasSymbolicField
extend ActiveSupport::Concern
module ClassMethods
# Defining (all below are equivalent):
# - has_symbolic_field :status, [:active, :pending]
# - has_symbolic_field :status, :active => 'Active', :pending => 'Pending'
# - has_symbolic_field :status, :active => 'Active', :pending => nil
# Accessing:
# - it.status # :available
@dnagir
dnagir / application.rb
Created February 15, 2012 01:37
Rails 3.2.1 configs
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
@dnagir
dnagir / utility_steps.rb
Created February 20, 2012 23:14
Capybara/Cucumber AJAX
module UtilitySteps
def wait_for_page_load
page.wait_until do
if Capybara.current_driver != :rack_test
page.has_css?('body.dom-loaded') and !has_pending_ajax_request?
else
true
end
end
@dnagir
dnagir / Gemfile.lock
Created February 21, 2012 07:20
Rails issue #5095
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.1)
actionpack (= 3.2.1)
mail (~> 2.4.0)
actionpack (3.2.1)
activemodel (= 3.2.1)
activesupport (= 3.2.1)
builder (~> 3.0.0)