Skip to content

Instantly share code, notes, and snippets.

@iain
iain / deploy.rb
Created March 10, 2011 22:17
Sunspot helpers
# Tasks for capistrano
def bundler_rake(task_name)
task task_name, :roles => [:app] do
run "cd #{current_path} && bundle exec rake RAILS_ENV=#{rails_env} #{task_name}", :env => {'RAILS_ENV' => rails_env}
end
end
desc "Start Solr"
bundler_rake "solr:start"
Feature: Widgets
Scenario: More than one page of widgets
* there are 25 widgets
* go to the widgets page
* only the latest 20 widgets should be visible
* go to the next page
* only the first 5 widgets should be visible
# vs.
@iain
iain / gist:912682
Created April 10, 2011 20:08
trying to get partial collections with layout working
activesupport (3.0.6) lib/active_support/whiny_nil.rb:48:in `method_missing'
actionpack (3.0.6) lib/action_view/render/rendering.rb:25:in `render'
haml (3.0.25) lib/haml/helpers/action_view_mods.rb:11:in `block in render_with_haml'
haml (3.0.25) lib/haml/helpers.rb:90:in `non_haml'
haml (3.0.25) lib/haml/helpers/action_view_mods.rb:11:in `render_with_haml'
app/views/users/index.html.haml:3:in `_app_views_users_index_html_haml___3430179667211235058_2156490900_627369316816662806'
actionpack (3.0.6) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.6) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.6) lib/action_view/template.rb:127:in `render'
actionpack (3.0.6) lib/action_view/render/rendering.rb:59:in `block in _render_template'
@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}"
@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'
@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
+
# 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 / 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
@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
$ rspec spec -fd -p
0.021032
User
has a name
has a name
Top 2 slowest examples:
User has a name