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:
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
$ 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
@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 / README.markdown
Created June 25, 2011 10:19
RSpec Formatter to load SimpleCov

SpecCoverage formatter

This formatter loads SimpleCov a code coverage reporting tool for Ruby 1.9. SimpleCov already does a good job in making it really easy to configure and load itself, but even good efforts can be improved upon.

The only problem is that you'll need to have something like a spec_helper to load it. You might not have this or you might find it ugly having to resort to environment variables to turn it off or on.

With this formatter, SimpleCov will start, and it will load a .coverage file in which you can add ruby code to configure SimpleCov in a non-obtrusive way. Configuration for a typical Rails app will look like this:

SimpleCov.start 'rails'