Skip to content

Instantly share code, notes, and snippets.

module Expose
def expose(*methods)
attr_reader *methods # for when you still only assign ivars in the action
helper_method *methods
end
end
ActionController::Base.extend Expose
class Person < Struct.new(:name, :language)
def initialize(*)
super
freeze
end
end
rob = Person["rob", "scala"]
default:
nl:
activerecord:
attributes:
job_offering: &job_offering_attributes
function_name: Functienaam
errors:
messages: &errors_messages
blank: moet ingevuld worden
activemodel:
$ rspec spec -fd -p
0.021032
User
has a name
has a name
Top 2 slowest examples:
User has a name
@iain
iain / app-models-user.rb
Created August 29, 2011 18:36
slow test example
class User < ActiveRecord::Base
def name
"#{first_name} #{last_name}"
end
end
User
has a name
has a name
is really slow (FAILED - 1)
Failures:
1) User is really slow
Failure/Error: Unable to find matching line from backtrace
too slow, it took 0.0105 seconds
@iain
iain / spec_helper.rb
Created August 29, 2011 18:09
Fail if specs are too slow!
RSpec.configure do |config|
config.before(:each) do
@__started_time = Time.now
end
config.after(:each) do
ran = @__ended_time - Time.now
ran.should be < ENV['MAX_TIME_PER_SPEC']
end
# The discussion is about two styles of interfaces.
# The first option is to use enumerable to make it look like an array
# The second option is to just return another array
# Of course in real life the class does more than this, this is just an example.
# What is your preference or opinion on this? Please comment :)
# option 1: include Enumerable:
class ActiveWidgets
@iain
iain / gc.patch
Created July 10, 2011 09:41
Two patches I use for Ruby 1.9.2-p180
diff --git a/gc.c b/gc.c
--- a/gc.c
+++ b/gc.c
@@ -77,6 +77,41 @@ void *alloca ();
#ifndef GC_MALLOC_LIMIT
#define GC_MALLOC_LIMIT 8000000
#endif
+#define HEAP_MIN_SLOTS 10000
+#define FREE_MIN 4096
+
@iain
iain / spork.rb
Created April 17, 2011 15:27
just a quick hack
#!/usr/bin/env ruby
CUCUMBER_PORT = 8990
RSPEC_PORT = 8989
def running?(port)
`netstat -an` =~ /\b#{port}\b/m
end
START_CUCUMBER = "spork cuc -p #{CUCUMBER_PORT}"