Skip to content

Instantly share code, notes, and snippets.

View nowk's full-sized avatar

Yung Hwa Kwon nowk

  • damncarousel
  • New York, NY
View GitHub Profile
require 'benchmark'
RSpec::Matchers.define :take_less_than do |n|
chain :seconds do; end
match do |block|
@elapsed = Benchmark.realtime do
block.call
end
@elapsed <= n
@nowk
nowk / rr.rb
Created November 9, 2011 19:50
require "rr"
Cucumber::Rails::World.send(:include, RR::Adapters::RRMethods)
@nowk
nowk / rspec-syntax-cheat-sheet.rb
Created November 19, 2011 23:13 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@nowk
nowk / admin_setup.rb
Created December 11, 2011 22:30
Devise + Declarative Authorization multi session/role use
module AdminSetup
def self.included(base)
base.send :include, InstanceMethods
end
module InstanceMethods
protected
def declarative_devise_scope
:admin
@nowk
nowk / helper.rb
Created January 13, 2012 15:59
visit helper for capybara + rspec
def visit_the page_to
visit page_to
end
def method_missing(method, *args, &block)
if method.to_s =~ /_page$/
route_path = method.to_s.gsub /_page$/, "_path"
__send__ route_path, *args
else
super
@nowk
nowk / screen.scss
Created February 3, 2012 20:07
A basic reset/style base for formtastic
.formtastic {
ol, ul {
list-style-type: none;
li {
font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
margin-bottom: 10px;
label {
display: block;
jQuery.fn.capitalize_word = function() {
$(this).each(function() {
$(this).bind("keyup", function() {
$(this).val($(this).val().toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
}));
})
})
}
@nowk
nowk / application_helper.rb
Created February 6, 2012 17:56
states array collection for selects
def states_collection
[
['Alabama', 'AL'],
['Alaska', 'AK'],
['Arizona', 'AZ'],
['Arkansas', 'AR'],
['California', 'CA'],
['Colorado', 'CO'],
['Connecticut', 'CT'],
['Delaware', 'DE'],
@nowk
nowk / email_matchers.rb
Created February 23, 2012 20:12
Simple custom matcher for emails against a "user" model
RSpec::Matchers.define :have_received_an_email do |expected|
def last_email
@last_email ||= ActionMailer::Base.deliveries.last
end
def inbox_size
ActionMailer::Base.deliveries.size
end
def to
@nowk
nowk / Gemfile
Created February 24, 2012 00:16
Most basic test gems
gem 'chronic'
group :development, :test do
gem "foreman"
# group :test do
# Pretty printed test output
gem 'turn', '0.8.2', :require => false
gem "capybara"